[FIX] web: empty a many2one field
Before this commit, it was impossible to empty a many2one in a list view. How to reproduce: - go into a list view with a many2one - empty a many2one containing a value - click outside the line Before this commit: The record goes into readonly mode and its many2one returns to its original value. After this commit: The record is saved and its many2one is empty. closes odoo/odoo#99140 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -29,7 +29,7 @@ export function m2oTupleFromData(data) {
|
||||
if ("display_name" in data) {
|
||||
name = data.display_name;
|
||||
} else {
|
||||
let _name = data.name;
|
||||
const _name = data.name;
|
||||
name = Array.isArray(_name) ? _name[1] : _name;
|
||||
}
|
||||
return [id, name];
|
||||
@@ -79,9 +79,6 @@ export class Many2OneField extends Component {
|
||||
if (value) {
|
||||
value = m2oTupleFromData(value[0]);
|
||||
}
|
||||
if (!value && !this.updateOnEmpty) {
|
||||
return;
|
||||
}
|
||||
this.state.isFloating = false;
|
||||
return this.props.update(value);
|
||||
};
|
||||
@@ -132,10 +129,6 @@ export class Many2OneField extends Component {
|
||||
get resId() {
|
||||
return this.props.value && this.props.value[0];
|
||||
}
|
||||
get updateOnEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
getDomain() {
|
||||
return this.domain.toList(this.context);
|
||||
}
|
||||
@@ -232,11 +225,4 @@ Many2OneField.extractProps = ({ attrs, field }) => {
|
||||
};
|
||||
|
||||
registry.category("fields").add("many2one", Many2OneField);
|
||||
|
||||
export class ListMany2OneField extends Many2OneField {
|
||||
get updateOnEmpty() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
registry.category("fields").add("list.many2one", ListMany2OneField); // TODO WOWL: link isn't clickable in lists
|
||||
registry.category("fields").add("list.many2one", Many2OneField);
|
||||
|
||||
@@ -753,21 +753,48 @@ QUnit.module("Fields", (hooks) => {
|
||||
// Select two records
|
||||
await click(target.querySelectorAll(".o_data_row")[0], ".o_list_record_selector input");
|
||||
await click(target.querySelectorAll(".o_data_row")[1], ".o_list_record_selector input");
|
||||
|
||||
await click(target.querySelector(".o_data_row .o_data_cell"));
|
||||
|
||||
await editInput(target, ".o_field_widget[name=trululu] input", "");
|
||||
await triggerEvent(target, ".o_field_widget[name=trululu] input", "blur");
|
||||
|
||||
const input = target.querySelector(".o_field_widget[name=trululu] input");
|
||||
input.value = "";
|
||||
await triggerEvent(input, null, "input");
|
||||
assert.containsNone(target, ".modal", "No save should be triggered when removing value");
|
||||
|
||||
await click(target.querySelector(".o_field_widget[name=trululu] input"));
|
||||
await click(target.querySelector(".o_field_widget[name=trululu] .ui-menu-item"));
|
||||
|
||||
assert.containsOnce(target, ".modal", "Saving should be triggered when selecting a value");
|
||||
|
||||
await click(target, ".modal .btn-primary");
|
||||
});
|
||||
|
||||
QUnit.test("empty a many2one field in list view", async function (assert) {
|
||||
await makeView({
|
||||
type: "list",
|
||||
resModel: "partner",
|
||||
serverData,
|
||||
arch: `
|
||||
<tree editable="top">
|
||||
<field name="trululu"/>
|
||||
</tree>`,
|
||||
mockRPC(route, { method, args }) {
|
||||
if (method === "write") {
|
||||
assert.step(method);
|
||||
assert.deepEqual(args[1], { trululu: false });
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
await click(target.querySelector(".o_data_row .o_data_cell"));
|
||||
await editInput(target, ".o_field_widget[name=trululu] input", "");
|
||||
assert.strictEqual(
|
||||
target.querySelector(".o_data_row .o_field_widget[name=trululu] input").textContent,
|
||||
""
|
||||
);
|
||||
|
||||
await click(target, ".o_list_view");
|
||||
assert.strictEqual(target.querySelector(".o_data_row").textContent, "");
|
||||
|
||||
assert.verifySteps(["write"]);
|
||||
});
|
||||
|
||||
QUnit.test("focus tracking on a many2one in a list", async function (assert) {
|
||||
serverData.views = {
|
||||
"partner,false,form": `
|
||||
|
||||
Reference in New Issue
Block a user