From 45bc7c92f804c0e2329eadf62043742f6986aa47 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Tue, 6 Nov 2018 10:34:43 +0000 Subject: [FIX] web: extend the fieldsInfo of a view with the origin view to evaluate extra fields Suppose you are editing a SO to add a new line. Depending on the configuration, a sale order line wizard may open (e.g. if packages are activated). This wizard is a form view, opened from the tree view of the sale order lines. We have commit 8e5156938a9c87b80512bff9ecd025891406e624 that adds extra fields from the originating view. (However it doesn't work if the other view is inlined, so we modify this part to add the extra field even in this case.) Then we need the field info from the origin view in the target view; we do so by extending the former with the content of the latter. opw 1904337 closes odoo/odoo#28441 --- .../web/static/src/js/views/basic/basic_model.js | 41 +++++++++------------- 1 file changed, 17 insertions(+), 24 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 1e930ccf783..f87106ec0c2 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -3587,27 +3587,21 @@ var BasicModel = AbstractModel.extend({ _makeDefaultRecord: function (modelName, params) { var self = this; - var determineExtraFields = function () { - // Fields that are present in the originating view, that need to be initialized - // Hence preventing their value to crash when getting back to the originating view - var parentRecord = self.localData[params.parentID]; - - var originView = parentRecord && parentRecord.fieldsInfo; - if (!originView || !originView[parentRecord.viewType]) - return []; - - var fieldsFromOrigin = _.filter(Object.keys(originView[parentRecord.viewType]), - function (fieldname) { - return params.fields[fieldname] !== undefined; - }); - - return fieldsFromOrigin; - }; - - var fieldNames = Object.keys(params.fieldsInfo[params.viewType]); + var targetView = params.viewType; + var fields = params.fields; + var fieldsInfo = params.fieldsInfo; + var fieldNames = Object.keys(fieldsInfo[targetView]); var fields_key = _.without(fieldNames, '__last_update'); - var extraFields = determineExtraFields(); + // Fields that are present in the originating view, that need to be initialized + // Hence preventing their value to crash when getting back to the originating view + var parentRecord = self.localData[params.parentID]; + if (parentRecord) { + var originView = parentRecord.viewType; + fieldNames = _.union(fieldNames, Object.keys(parentRecord.fieldsInfo[originView])); + fieldsInfo[targetView] = _.defaults({}, fieldsInfo[targetView], parentRecord.fieldsInfo[originView]); + fields = _.defaults({}, fields, parentRecord.fields); + } return this._rpc({ model: modelName, @@ -3616,15 +3610,14 @@ var BasicModel = AbstractModel.extend({ context: params.context, }) .then(function (result) { - var record = self._makeDataPoint({ modelName: modelName, - fields: params.fields, - fieldsInfo: params.fieldsInfo, + fields: fields, + fieldsInfo: fieldsInfo, context: params.context, parentID: params.parentID, res_ids: params.res_ids, - viewType: params.viewType, + viewType: targetView, }); // We want to overwrite the default value of the handle field (if any), @@ -3641,7 +3634,7 @@ var BasicModel = AbstractModel.extend({ result[overrideDefaultFields.field] = overrideDefaultFields.value; } - return self.applyDefaultValues(record.id, result, {fieldNames: _.union(fieldNames, extraFields)}) + return self.applyDefaultValues(record.id, result, {fieldNames: fieldNames}) .then(function () { var def = $.Deferred(); self._performOnChange(record, fields_key).always(function () { -- cgit v1.2.3