summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorsvs-odoo <svs@odoo.com>2019-06-04 09:30:03 +0000
committersvs-odoo <svs@odoo.com>2019-06-26 12:30:12 +0000
commit0fa9c07eaa2c8d66ccf7a3d19a35efd1bf2698dc (patch)
tree3e51b05d362685a48f48a9529a1f6d1ae478dfd7 /addons
parent88360a95f2065865c120862518805074d20ae570 (diff)
[FIX] stock: can't select undefined record
Before this commit, on editable quant view list, when user tries to create a duplicate line and save it with tab or enter key, the list tries to go to the next line. But sometime, this line was moved cause of the refresh, so it causes a JS error and raises a traceback. This fix avoid to try to select something in case we refresh the list. Task #2006337 closes odoo/odoo#33866 Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/stock/static/src/js/inventory_singleton_list_controller.js7
-rw-r--r--addons/stock/static/tests/singleton_list_tests.js57
2 files changed, 59 insertions, 5 deletions
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."+
"<br/>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: '<tree editable="top" js_class="singleton_list">'+
+ '<field name="name"/>'+
+ '<field name="age"/>'+
+ '</tree>',
+ 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');