diff --git a/addons/stock/static/src/js/inventory_singleton_list_controller.js b/addons/stock/static/src/js/inventory_singleton_list_controller.js
index 30bd5c4b22a..b71f2d6ae39 100644
--- a/addons/stock/static/src/js/inventory_singleton_list_controller.js
+++ b/addons/stock/static/src/js/inventory_singleton_list_controller.js
@@ -19,6 +19,8 @@ var _t = core._t;
var SingletonListController = ListController.extend({
/**
* @override
+ * @return {Promise} rejected when update the list because we don't want
+ * anymore to select a cell who maybe doesn't exist anymore.
*/
_confirmSave: function (id) {
var newRecord = this.model.localData[id];
@@ -52,10 +54,11 @@ var SingletonListController = ListController.extend({
var notification = _t("You tried to create a record who already exists."+
"
This last one has been modified instead.");
this.do_notify(_t("This record already exists."), notification);
- return this.reload();
+ this.reload();
+ return Promise.reject();
}
else {
- return this._super(id);
+ return this._super.apply(this, arguments);
}
},
});
diff --git a/addons/stock/static/tests/singleton_list_tests.js b/addons/stock/static/tests/singleton_list_tests.js
index 21886429b42..aad90a29a0c 100644
--- a/addons/stock/static/tests/singleton_list_tests.js
+++ b/addons/stock/static/tests/singleton_list_tests.js
@@ -1,7 +1,6 @@
odoo.define('web.singleton_list_tests', function (require) {
"use strict";
-var core = require('web.core');
var SingletonListView = require('stock.SingletonListView');
var testUtils = require('web.test_utils');
@@ -105,10 +104,62 @@ QUnit.module('Views', {
var age = '72';
await testUtils.fields.editInput($input, age);
await testUtils.fields.triggerKeydown($input, 'enter');
- await testUtils.dom.click($('.o_list_button_save'));
// Checks we have still only 3 records...
- assert.containsN(list, '.o_data_row', 3, "should now have 4 records");
+ assert.containsN(list, '.o_data_row', 3, "should still have 3 records");
+ // ... and verify modification was occured.
+ var nameField = list.$('td[title="' + name + '"]');
+ var ageField = nameField.parent().find('.o_list_number');
+ assert.strictEqual(ageField.text(), age, "The age field must be updated");
+ list.destroy();
+ });
+
+ QUnit.test('Don\'t raise error when trying to create duplicate line', async function (assert) {
+ assert.expect(3);
+ /* In some condition, a list editable with the `singletonlist` js_class
+ can try to select a record at a line who isn't the same place anymore.
+ In this case, the list can try to find the id of an undefined record.
+ This test just insures we don't raise a traceback in this case.
+ */
+ var list = await createView({
+ View: SingletonListView,
+ model: 'person',
+ data: {
+ person: {
+ fields: {
+ name: {string: "Name", type: "char"},
+ age: {string: "Age", type: "integer"},
+ },
+ records: [
+ {id: 1, name: 'Bobby B. Bop', age: 18},
+ ]
+ }
+ },
+ arch: ''+
+ ''+
+ ''+
+ '',
+ mockRPC: this.mockRPC,
+ });
+ // Checks we have initially 1 record
+ assert.containsN(list, '.o_data_row', 1, "should have 1 records");
+
+ // Creates a new line...
+ await testUtils.dom.click($('.o_list_button_add'));
+ // ... and fills fields with already existing value
+ var $input = $('.o_selected_row input[name=name]');
+ var name = 'Bobby B. Bop';
+ await testUtils.fields.editInput($input, name);
+ await testUtils.fields.triggerKeydown($input, 'tab');
+
+ $input = $('.o_selected_row input[name=age]');
+ var age = '22';
+ await testUtils.fields.editInput($input, age);
+ // This operation causes list'll try to select undefined record.
+ await testUtils.fields.triggerKeydown($input, 'enter');
+
+ // Checks we have still only 1 record...
+ assert.containsN(list, '.o_data_row', 1, "should now have 1 records");
// ... and verify modification was occured.
var nameField = list.$('td[title="' + name + '"]');
var ageField = nameField.parent().find('.o_list_number');