From 8a386b9a08d1dcd8eac66623f2743291bf677c00 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Mon, 7 Aug 2017 10:32:54 +0200 Subject: [FIX] web: BasicModel: domain returned by onchanges Onchange RPCs return an object that may contain a 'domain' key. When it does, its value is an object whose keys are field names and values are the new domain for the corresponding field. Commit 8473bde8 added the support of the 'domain' key, but stored it directly in the fieldsInfo (an object gathering information of the fields in the view, and which is shared between all records). This was wrong as the domain isn't necessarily the same for all records. To reproduce, with the UOMs activated, go to Sales > Quotation, in the form view, add an order line, set a product (e.g. Graphic Card), the onchange sets the domain for the uom field (matching uoms like 'unit', 'dozens'). Add a second line with a service product, the onchange returns another domain for the uom field (matching uoms like 'hours', days'). Click again on the uom field of the first line, the domain is the one of the second record, which is wrong. This rev. directly stores the domains returned by the onchange on the object representing the record, so that this information isn't shared between records anymore. --- addons/web/static/src/js/views/basic/basic_model.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'addons/web/static/src/js/views/basic') 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 04fe384afdc..966a6ef3a78 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -2435,6 +2435,12 @@ var BasicModel = AbstractModel.extend({ */ _getDomain: function (element, options) { if (options && options.fieldName) { + if (element._domains[options.fieldName]) { + return Domain.prototype.stringToArray( + element._domains[options.fieldName], + this._getEvalContext(element, true) + ); + } var viewType = options.viewType || element.viewType; var fieldInfo = element.fieldsInfo[viewType][options.fieldName]; if (fieldInfo && fieldInfo.domain) { @@ -2697,6 +2703,7 @@ var BasicModel = AbstractModel.extend({ var dataPoint = { _cache: type === 'list' ? {} : undefined, _changes: null, + _domains: {}, aggregateValues: params.aggregateValues || {}, context: params.context || {}, count: params.count || res_ids.length, @@ -3021,12 +3028,7 @@ var BasicModel = AbstractModel.extend({ record._warning = true; } if (result.domain) { - var fieldsInfo = record.fieldsInfo[viewType || record.viewType]; - for (var fieldName in result.domain) { - if (fieldsInfo[fieldName]) { - fieldsInfo[fieldName].domain = result.domain[fieldName]; - } - } + record._domains = _.extend(record._domains, result.domain); } return self._applyOnChange(result.value, record).then(function () { return result; -- cgit v1.2.3 From 587751aa0dbd095db99e93398cf98d705c35679c Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Fri, 4 Aug 2017 15:36:31 +0200 Subject: [FIX] web: prevent virtual datapoint creation when no default value Previously, it used to create a virtual datapoint even though there was no change on this field. If the field was a many2one, this datapoint triggered a name_get call afterwards, but giving the virtual id of the datapoint since there is no real record. The solution is to avoid creating a virtual datapoint when it is not needed at all, thus fixing the wrong name_get call. Steps to reproduce the bug: - 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 - You'll get an error as the web client tries to fetch the name_get of this datapoint even though the record does not exist. --- addons/web/static/src/js/views/basic/basic_model.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'addons/web/static/src/js/views/basic') 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 966a6ef3a78..fc3b68eeab7 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -2877,6 +2877,9 @@ var BasicModel = AbstractModel.extend({ r._changes = _.defaults(value[2], r.data); for (var name in r._changes) { + if (r._changes[name] === null) { + continue; + } var isFieldInView = name in r.fields; if (isFieldInView && r.fields[name].type === 'many2one') { var rec = self._makeDataPoint({ -- cgit v1.2.3 From e2252c35c15df9ccf9132c72348723790d76a676 Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Fri, 4 Aug 2017 15:31:51 +0200 Subject: [FIX] web: handle create in many2many default_get Previously, we did not handle the case where the result of the m2m default get was a new record. In this case, we can't just send a replace all command giving the ids since the new record has no id. We decided to keep the replace all command even when it is empty to stay consistent with the o2m implementation, even though saas-15 did not behave like that. Steps to reproduce the bug: - 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 - You'll get an error as the id given to the onchange is a virtual one, rather than a create which would not include an id. --- addons/web/static/src/js/views/basic/basic_model.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src/js/views/basic') 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 fc3b68eeab7..acb0dddbcb6 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -2310,12 +2310,20 @@ var BasicModel = AbstractModel.extend({ }); list = this._applyX2ManyOperations(list); if (type === 'many2many' || list._forceM2MLink) { + var relRecordCreated = _.filter(relRecordAdded, function (rec) { + return typeof rec.res_id === 'string'; + }); + var realIDs = _.difference(list.res_ids, _.pluck(relRecordCreated, 'res_id')); // deliberately generate a single 'replace' command instead // of a 'delete' and a 'link' commands with the exact diff // because 1) performance-wise it doesn't change anything // and 2) to guard against concurrent updates (policy: force // a complete override of the actual value of the m2m) - commands[fieldName].push(x2ManyCommands.replace_with(list.res_ids)); + commands[fieldName].push(x2ManyCommands.replace_with(realIDs)); + _.each(relRecordCreated, function (relRecord) { + var changes = self._generateChanges(relRecord, options); + commands[fieldName].push(x2ManyCommands.create(changes)); + }); // generate update commands for records that have been // updated (it may happen with editable lists) _.each(relRecordUpdated, function (relRecord) { -- cgit v1.2.3 From 50957038b9ebe5e249da28a9745f957ad02a0760 Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Wed, 9 Aug 2017 11:22:56 +0200 Subject: [FIX] web: fix magic grouping on date fields Date fields have magic grouping methods to specify how to group on them like date:month, date:weeks, date:days for example. It needs to be handled properly since date:month is not a valid field name but date is. Steps to reproduce the issue: - Go to Sales/Dashboard - Click on My Pipeline - Group by "Creation Month" Basically, this can be triggred from any view which has a search view which defines a group using the magic date grouping methods. --- addons/web/static/src/js/views/basic/basic_model.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'addons/web/static/src/js/views/basic') 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 acb0dddbcb6..288186e4d5a 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -3096,7 +3096,9 @@ var BasicModel = AbstractModel.extend({ */ _readGroup: function (list) { var self = this; - var fields = _.uniq(list.getFieldNames().concat(list.groupedBy)); + var groupByField = list.groupedBy[0]; + var rawGroupBy = groupByField.split(':')[0]; + var fields = _.uniq(list.getFieldNames().concat(rawGroupBy)); return this._rpc({ model: list.model, method: 'read_group', @@ -3107,8 +3109,6 @@ var BasicModel = AbstractModel.extend({ lazy: true, }) .then(function (groups) { - var groupByField = list.groupedBy[0]; - var rawGroupBy = groupByField.split(':')[0]; var previousGroups = _.map(list.data, function (groupID) { return self.localData[groupID]; }); -- cgit v1.2.3 From 1e8f6d01ffe324348ce5d75f8643f170f6478657 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 9 Aug 2017 09:21:13 +0200 Subject: [FIX] web,*: send correct context on button clicked *account_asset When a button of type 'action' is clicked (execute a given action), special keys must be set in the context (active_id, active_ids and active_model). They must be computed regarding the record containing the clicked button, i.e. if we are in a modal, it must be the id and model of the record displayed in the modal. Before this rev., we always sent the id and model of the record displayed in the background (i.e. the id and model of the url). This caused a bug in MRP that could be reproduced as follows: - open a manufacturing order in form view - click on edit - click on one of the line of the one2many, and click on the green icon to edit a product - click on the update product quantity button on top of it - the product field must be correctly filled, which was not the case before this rev. --- addons/web/static/src/js/views/basic/basic_controller.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'addons/web/static/src/js/views/basic') 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 3a47f65ab03..6ba9dbea477 100644 --- a/addons/web/static/src/js/views/basic/basic_controller.js +++ b/addons/web/static/src/js/views/basic/basic_controller.js @@ -232,13 +232,17 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { return self.isDestroyed() ? $.when() : self.reload(); }; record = record || this.model.get(this.handle); - var recordID = record.data.id; + this.trigger_up('execute_action', { action_data: _.extend({}, attrs, { - context: record.getContext({additionalContext: attrs.context || {}}), + context: record.getContext({additionalContext: attrs.context || {}}), }), - model: record.model, - res_ids: [recordID], + env: { + context: record.getContext(), + currentID: record.data.id, + model: record.model, + resIDs: record.res_ids, + }, on_closed: function (reason) { if (!_.isObject(reason)) { reload(reason); -- cgit v1.2.3 From 87133a8235aa71db49566e9a1179ab66b68e87ec Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 10 Aug 2017 11:49:15 +0200 Subject: [FIX] web: BasicModel: correctly reload new records Commit 7cd2f6370 (in 10.0) recently added attribute special='cancel' on the 'Cancel' buttons of the Settings views in Odoo. The attribute wasn't really supported in this case by the old web framework, so this commit also slightly adapted it, and made it reload the whole webclient when such a button is clicked. This commit now needs to be forwardported in saas-16, so we have to handle the case in the new views as well. Before this rev., it crashed, because the BasicModel tried to reload a new record (the one of the Settings form view), so basically it performed a 'read' RPC on a virtual ID like 'virtual_123', and the server didn't really appreciate. This rev. handles the case where a new record is reloaded, and simply performs a 'default_get' instead of a read. Bonus point: with the new views, we don't have to reload the whole webclient. --- 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') 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 288186e4d5a..8755805f993 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -649,7 +649,7 @@ var BasicModel = AbstractModel.extend({ var element = this.localData[id]; if (element.type === 'record') { - if ('currentId' in options && !options.currentId) { + if (!options.currentId && (('currentId' in options) || this.isNew(id))) { var params = { context: element.context, fieldsInfo: element.fieldsInfo, -- cgit v1.2.3