[FIX] web: avoid multiple displays of the "same" discard warning

Before this commit, editing a record e.g. in a form
view and toggling the home menu would cause the discard
warning to be displayed twice when going to the home
menu (in enterprise) and then once again when going to
an other app. This is now fixed.

Task ID: 2043027

closes odoo/odoo#37301

Signed-off-by: VincentSchippefilt <VincentSchippefilt@users.noreply.github.com>
Co-authored-by: Mohammed Shekha <msh@odoo.com>
Co-authored-by: aab-odoo <aab@odoo.com>
This commit is contained in:
Mathieu Duckerts-Antoine
2019-09-24 08:34:43 +00:00
co-authored by Mohammed Shekha aab-odoo
parent cbea2c5cdb
commit a7a60f7c61
2 changed files with 43 additions and 1 deletions
@@ -382,10 +382,13 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
options = options || {};
return this.canBeDiscarded(recordID)
.then(function (needDiscard) {
if (options.noAbandon || (options.readonlyIfRealDiscard && !needDiscard)) {
if (options.readonlyIfRealDiscard && !needDiscard) {
return;
}
self.model.discardChanges(recordID);
if (options.noAbandon) {
return;
}
if (self.model.canBeAbandoned(recordID)) {
self._abandonRecord(recordID);
return;
@@ -4033,6 +4033,45 @@ QUnit.module('ActionManager', {
actionManager.destroy();
});
QUnit.test('Call twice clearUncommittedChanges in a row does not display twice the discard warning', async function (assert) {
assert.expect(4);
var actionManager = await createActionManager({
actions: this.actions,
archs: this.archs,
data: this.data,
intercepts: {
clear_uncommitted_changes: function () {
actionManager.clearUncommittedChanges();
},
},
});
// execute an action and edit existing record
await actionManager.doAction(3);
await testUtils.dom.click(actionManager.$('.o_list_view .o_data_row:first'));
assert.containsOnce(actionManager, '.o_form_view.o_form_readonly');
await testUtils.dom.click($('.o_control_panel .o_form_button_edit'));
assert.containsOnce(actionManager, '.o_form_view.o_form_editable');
await testUtils.fields.editInput(actionManager.$('input[name=foo]'), 'val');
actionManager.trigger_up('clear_uncommitted_changes');
await testUtils.nextTick();
assert.containsOnce($('body'), '.modal'); // confirm discard dialog
// confirm discard changes
await testUtils.dom.click($('.modal .modal-footer .btn-primary'));
actionManager.trigger_up('clear_uncommitted_changes');
await testUtils.nextTick();
assert.containsNone($('body'), '.modal');
actionManager.destroy();
});
});
});