[FIX] web: prevent recreating a deleted record
Before this commit, deleting a record containing changes (dirty) recreated the record when leaving the view. Now, the changes are discarded when deleting the record so it is not marked as dirty and not recreated. task id: 3063834 closes odoo/odoo#115767 X-original-commit: cf8952aaac1ba9b43f0f558cc15e48462defcfe7 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -381,6 +381,8 @@ var BasicModel = AbstractModel.extend({
|
||||
})
|
||||
.then(function () {
|
||||
_.each(records, function (record) {
|
||||
// discard any changes to prevent creating a new record with auto-save
|
||||
self.discardChanges(record.id);
|
||||
var parent = record.parentID && self.localData[record.parentID];
|
||||
if (parent && parent.type === 'list') {
|
||||
parent.data = _.without(parent.data, record.id);
|
||||
|
||||
@@ -13307,4 +13307,50 @@ QUnit.module("Views", (hooks) => {
|
||||
assert.verifySteps(['danger:Please click on the "save" button first']);
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test("prevent recreating a deleted record", async (assert) => {
|
||||
serverData.models.partner.records.length = 1;
|
||||
|
||||
serverData.actions[1] = {
|
||||
id: 1,
|
||||
name: "Partner",
|
||||
res_model: "partner",
|
||||
type: "ir.actions.act_window",
|
||||
views: [
|
||||
[false, "list"],
|
||||
[false, "form"],
|
||||
],
|
||||
};
|
||||
serverData.views = {
|
||||
"partner,false,list": `
|
||||
<tree>
|
||||
<field name="name"/>
|
||||
</tree>`,
|
||||
"partner,false,form": `
|
||||
<form>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
</group>
|
||||
</form>`,
|
||||
"partner,false,search": "<search></search>",
|
||||
};
|
||||
|
||||
const webClient = await createWebClient({ serverData });
|
||||
await doAction(webClient, 1);
|
||||
|
||||
assert.containsOnce(target, ".o_data_row");
|
||||
assert.strictEqual(target.querySelector(".o_data_row").textContent, "name");
|
||||
await click(target, ".o_data_row .o_data_cell");
|
||||
|
||||
await editInput(target, ".o_field_char .o_input", "now dirty");
|
||||
assert.isVisible(target.querySelector(".o_form_status_indicator_buttons"));
|
||||
|
||||
await click(target, ".o_cp_action_menus .dropdown-toggle");
|
||||
await click(target.querySelectorAll(".o_cp_action_menus .dropdown-item")[1]);
|
||||
assert.containsOnce(target, ".modal");
|
||||
|
||||
await click(target, ".modal-footer button.btn-primary");
|
||||
assert.containsOnce(target, ".o_list_view");
|
||||
assert.containsNone(target, ".o_data_row");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user