[FIX] web: avoid crash when deleting a property multiple times

Steps to reproduce the bug:
    - Go to Apps, and install the Knowledge App.
    - Go to Knowledge and create an article, and a child article.
    - Inside the child article, go to Properties tab and add a property.
    - Go to edit the property, and inside the popover,click on the
    delete button, atleast 2 times.
    - Now we got more than 1 popover to confirm the delete of the
    property, click delete on all of them.

Issue:
    Once the first popover is confirmed, we properly delete the property
    but now we are going to get an error because the property is already
    deleted and we won't be able to find the property to delete.

Solution:
    We need to check if we can find the property we want to delete
    before doing any further actions.

opw-3371753

closes odoo/odoo#127584

X-original-commit: 7f5aed12fb143928cc82eeeea712363cb79b1171
Signed-off-by: Maruan Aguerdouh Mohtar (magm) <magm@odoo.com>
This commit is contained in:
Maruan Aguerdouh (magm)
2023-07-08 21:39:43 +02:00
parent e8dbf7a3d1
commit 66d022a4dc
2 changed files with 47 additions and 3 deletions
@@ -294,10 +294,13 @@ export class PropertiesField extends Component {
confirm: () => {
this.popover.close();
const propertiesDefinitions = this.propertiesList;
propertiesDefinitions.find(
const foundPropertyDefinition = propertiesDefinitions.find(
(property) => property.name === propertyName
).definition_deleted = true;
this.props.record.update({ [this.props.name]: propertiesDefinitions });
);
if (foundPropertyDefinition) {
foundPropertyDefinition.definition_deleted = true;
this.props.record.update({ [this.props.name]: propertiesDefinitions });
}
},
cancel: () => {},
};
@@ -1772,4 +1772,45 @@ QUnit.module("Fields", (hooks) => {
assert.ok(target.querySelector(".o_test_properties_not_empty"));
}
);
QUnit.test(
"properties: confirm the delete of an already deleted property does not throw an error",
async function (assert) {
async function mockRPC(route, { method, model, kwargs }) {
if (["check_access_rights", "check_access_rule"].includes(method)) {
return true;
}
}
await makeView({
type: "form",
resModel: "partner",
resId: 3,
serverData,
arch: `
<form>
<sheet>
<group>
<field name="company_id"/>
<field name="display_name"/>
<field name="properties" widget="properties"/>
</group>
</sheet>
</form>`,
mockRPC,
});
// We open the property popover
await click(target, ".o_property_field:first-child .o_field_property_open_popover");
// We click on the delete button 2 times to get 2 confirmation popovers
await click(target, ".o_field_property_definition_delete");
await click(target, ".o_field_property_definition_delete");
// We confirm both confirmation popovers
await click(target.querySelector(".modal-content .btn-primary"));
await click(target.querySelector(".modal-content .btn-primary"));
assert.containsNone(target, ".modal-content");
}
);
});