From c0247e6a8d6057710908be941dec6a846c31cd28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Thu, 24 Aug 2017 09:57:02 +0200 Subject: [FIX] web: correct evaluation for x2many fields in onchanges Before this commit, it could happen that a x2many field was considered invalid, which prevent triggering onchanges, even though each of its required fields are properly set. Here is such a scenario: We have a one2many field something_ids in a form view, with an inline tree view, which contains a field X. The field X is required on the model, but marked required="0" in the inline view. In that case, we incorrectly evaluated the required modifiers: since the attrs did not contain the required attribute, we fell back on the field_get value, which is true in this case. But this is not correct, the fieldviewget already computed the actual modifiers and took into account the fact that it was overridden. We need to only look at the modifiers. --- addons/web/static/src/js/views/basic/basic_model.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'addons/web/static/src/js/views/basic/basic_model.js') diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js index 0d95c292070..d54f609f002 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -2738,8 +2738,7 @@ var BasicModel = AbstractModel.extend({ var fieldInfo = element.fieldsInfo[element.viewType][fieldName]; var rawModifiers = JSON.parse(fieldInfo.modifiers || "{}"); var modifiers = self._evalModifiers(record, rawModifiers); - var required = 'required' in modifiers ? modifiers.required : field.required; - if (required && !self._isFieldSet(recordData[fieldName], field.type)) { + if (modifiers.required && !self._isFieldSet(recordData[fieldName], field.type)) { isValid = false; } }); -- cgit v1.2.3 From d93726f9ac6d64a39cd95f35cf61a898e4cd2009 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Mon, 28 Aug 2017 16:14:31 +0200 Subject: [FIX] web,mail: only send fields in view for onchanges The field 'display_name' is automatically added to the list of fields to fetch when fetching a record. Before this rev., its value was also sent alongside the fields in the view for onchange RPCs. It shouldn't: only the fields in the view should be sent. It produced a weird bug in the res.partner form view: open a contact (company), add a sub-contact, save -> the display_name of the contact was then '' (and 'Contacts' was displayed in the breadcrumbs instead of the display_name of the opened contact). This is because 'display_name' was sent to the onchange, which returned '' as value (because of another bug python side). So as it's value changed, when saving, the new display_name was sent to the server (even if this field was actually readonly). Before this rev., we also always fetched 'display_name' when fetching list of records (read or search_read). This wasn't a bug per se, but it might be a computed field, and it isn't necessary, so we stop fetching it in that case if it isn't in the view (as it was done in saas-15, before the new views). --- addons/web/static/src/js/views/basic/basic_model.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'addons/web/static/src/js/views/basic/basic_model.js') diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js index d54f609f002..aa0aab7aa64 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1629,8 +1629,8 @@ var BasicModel = AbstractModel.extend({ */ _fetchRecord: function (record, options) { var self = this; - var fieldNames = options && options.fieldNames || - _.uniq(record.getFieldNames().concat(['display_name'])); + var fieldNames = options && options.fieldNames || record.getFieldNames(); + fieldNames = _.uniq(fieldNames.concat(['display_name'])); return this._rpc({ model: record.model, method: 'read', @@ -2337,6 +2337,16 @@ var BasicModel = AbstractModel.extend({ _generateOnChangeData: function (record) { var commands = this._generateX2ManyCommands(record, {withReadonly: true}); var data = _.extend(this.get(record.id, {raw: true}).data, commands); + // 'display_name' is automatically added to the list of fields to fetch, + // when fetching a record, even if it doesn't appear in the view. However, + // only the fields in the view must be passed to the onchange RPC, so we + // remove it from the data sent by RPC if it isn't in the view. + var hasDisplayName = _.some(record.fieldsInfo, function (fieldsInfo) { + return 'display_name' in fieldsInfo; + }); + if (!hasDisplayName) { + delete data.display_name; + } // one2many records have a parentID if (record.parentID) { -- cgit v1.2.3 From 4f61e7f0481fa2e2bfd806d92ea77f07b78d42de Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Tue, 29 Aug 2017 13:41:28 +0200 Subject: [FIX] web: WidgetDomain: don't crash on false domain Before this rev., when the value of a field with widget='domain' was false, the search_count RPC made to display the number of records matching the domain crashed, and the widget displayed that the domain was invalid. This rev. adds a fallback on [] when the domain is false. --- addons/web/static/src/js/views/basic/basic_model.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/static/src/js/views/basic/basic_model.js') diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js index aa0aab7aa64..9dc544ba84f 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -2043,7 +2043,7 @@ var BasicModel = AbstractModel.extend({ if (record.data.hasOwnProperty(domainModel)) { domainModel = record._changes && record._changes[domainModel] || record.data[domainModel]; } - var domainValue = record._changes && record._changes[fieldName] || record.data[fieldName]; + var domainValue = record._changes && record._changes[fieldName] || record.data[fieldName] || []; // avoid rpc if not necessary var hasChanged = this._saveSpecialDataCache(record, fieldName, { -- cgit v1.2.3 From f1082f15525ccf42b1fb95fb7da0211eaf64fcb9 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 30 Aug 2017 10:38:53 +0200 Subject: [FIX] web: don't send virtual id on save The problem occurred on form views with an x2many field with a default value containing CREATE commands, i.e. when opening such a form view in create mode, the x2many field is pre-filled with some (non-existing yet) subrecords. If the user then edited those subrecords, and then clicked on 'Save' to create the main record, an 'UPDATE' command was sent alongside the 'CREATE' one for the x2many, and the id of the 'UPDATE' command was a virtual id (as the subrecord didn't exist yet), and it crashed. This could happen in MRP: - Enable lots in Iventory - Choose a product which is a component of another (through mrp bom) - Set this product as tracked by lot - Set this product inventory quantity to 0 - Create a new manufacturing order for the product for which it is a component - Click on "Check Availability" - click on Produce: the many2many already contains a subrecord - edit the lot field of that subrecord - click on 'Record Production' --- addons/web/static/src/js/views/basic/basic_model.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src/js/views/basic/basic_model.js') diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js index 9dc544ba84f..4e3e5823223 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -2407,7 +2407,10 @@ var BasicModel = AbstractModel.extend({ _.each(list._changes, function (change) { if (change.operation === 'ADD') { relRecordAdded.push(self.localData[change.id]); - } else if (change.operation === 'UPDATE') { + } else if (change.operation === 'UPDATE' && !self.isNew(change.id)) { + // ignore new records that would have been updated + // afterwards, as all their changes would already + // be aggregated in the CREATE command relRecordUpdated.push(self.localData[change.id]); } }); -- cgit v1.2.3