summaryrefslogtreecommitdiff
path: root/addons/web
diff options
context:
space:
mode:
authorMathieu Duckerts-Antoine <dam@odoo.com>2019-09-23 12:24:47 +0000
committerMathieu Duckerts-Antoine <dam@odoo.com>2019-09-24 08:34:43 +0000
commita7a60f7c61275f26521cbc4ea0da2889095a5cc5 (patch)
tree2d81ab54bdc3b17e3e6470ba4c6bed087ef61855 /addons/web
parentcbea2c5cdb3c5f3a0ffcd5ccf557afdba4eeda72 (diff)
[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>
Diffstat (limited to 'addons/web')
-rw-r--r--addons/web/static/src/js/views/basic/basic_controller.js5
-rw-r--r--addons/web/static/tests/chrome/action_manager_tests.js39
2 files changed, 43 insertions, 1 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_controller.js b/addons/web/static/src/js/views/basic/basic_controller.js
index 9e9e7559ede..c82bf05996b 100644
--- a/addons/web/static/src/js/views/basic/basic_controller.js
+++ b/addons/web/static/src/js/views/basic/basic_controller.js
@@ -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;
diff --git a/addons/web/static/tests/chrome/action_manager_tests.js b/addons/web/static/tests/chrome/action_manager_tests.js
index 4d05d723ccf..f896fc659ef 100644
--- a/addons/web/static/tests/chrome/action_manager_tests.js
+++ b/addons/web/static/tests/chrome/action_manager_tests.js
@@ -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();
+ });
});
});