From da136d83bb4cd952dc0e2417d67679cfc5068f34 Mon Sep 17 00:00:00 2001 From: fwi-odoo Date: Fri, 15 Sep 2017 10:19:16 +0200 Subject: [IMP] web: x2m list: conditionnaly hide a column This commit introduces a new way to hide a column in a x2m list view. The attribute 'tree_invisible' can be add in the field attrs in the x2m view definition. This attribute can use the 'parent' key to make a reference to the parent record (e.g. 'parent.id'). --- addons/web/static/src/js/views/basic/basic_model.js | 7 +++++-- 1 file changed, 5 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 d85f55ddf36..6500fb43b85 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1689,6 +1689,9 @@ var BasicModel = AbstractModel.extend({ if ('invisible' in modifiers) { result.invisible = evalModifier(modifiers.invisible); } + if ('column_invisible' in modifiers) { + result.column_invisible = evalModifier(modifiers.column_invisible); + } if ('readonly' in modifiers) { result.readonly = evalModifier(modifiers.readonly); } @@ -2847,7 +2850,7 @@ var BasicModel = AbstractModel.extend({ _isFieldProtected: function (record, fieldName, viewType) { var fieldInfo = record.fieldsInfo[viewType || record.viewType][fieldName]; if (fieldInfo) { - var rawModifiers = JSON.parse(fieldInfo.modifiers || "{}"); + var rawModifiers = fieldInfo.modifiers || {}; var modifiers = this._evalModifiers(record, rawModifiers); return modifiers.readonly && !fieldInfo.force_save; } else { @@ -2899,7 +2902,7 @@ var BasicModel = AbstractModel.extend({ _.each(element.getFieldNames(), function (fieldName) { var field = element.fields[fieldName]; var fieldInfo = element.fieldsInfo[element.viewType][fieldName]; - var rawModifiers = JSON.parse(fieldInfo.modifiers || "{}"); + var rawModifiers = fieldInfo.modifiers || {}; var modifiers = self._evalModifiers(record, rawModifiers); if (modifiers.required && !self._isFieldSet(recordData[fieldName], field.type)) { isValid = false; -- cgit v1.2.3 From d9ffd5204d7826dcdcb026e828867f6ea3d95755 Mon Sep 17 00:00:00 2001 From: fwi-odoo Date: Sat, 30 Sep 2017 14:28:42 +0200 Subject: [FIX] web: correctly apply onchange on boolean field When an onchange sets a boolean field to 'true', if this boolean was set to 'false' previously, the old value was used instead of '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 6500fb43b85..7810a1195f0 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1235,7 +1235,7 @@ var BasicModel = AbstractModel.extend({ record._rawChanges[name] = val; return; } - var oldValue = record._changes[name] || record.data[name]; + var oldValue = name in record._changes ? record._changes[name] : record.data[name]; var id; if (field.type === 'many2one') { id = false; -- cgit v1.2.3 From 16eb262c60a3b46f89cb706504a8c2d3dc755e08 Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Fri, 29 Sep 2017 14:01:51 +0200 Subject: [FIX] web: fix one2many default get The one2many default get code used to meddle with basic_model's res_ids manually, which ended up desynchronizing the data and res_ids fields of the list representation of the one2many values. This commit solves the issue by using the proper mechanisms of the basic_model, that is creating a proper datapoint for those ids. Steps to reproduce the original issue: - Install sale_mamangement, mrp and purchase - Create a product - In the Inventory tab, in Routes, uncheck Buy - Check and then uncheck back any other route than Buy - Get a traceback because we are looking for a record with a given res_id in the list data but since they are desynchronized, data is empty at that point even though res_ids is not. --- 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 7810a1195f0..9e7fb8b78ef 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -3182,8 +3182,18 @@ var BasicModel = AbstractModel.extend({ } if (value[0] === 6) { // REPLACE_WITH - x2manyList.res_ids = value[2]; - x2manyList.count = x2manyList.res_ids.length; + _.each(value[2], function (res_id) { + r = self._makeDataPoint({ + modelName: x2manyList.model, + context: x2manyList.context, + fieldsInfo: fieldsInfo, + fields: fields, + parentID: x2manyList.id, + res_id: res_id, + viewType: viewType, + }); + x2manyList._changes.push({operation: 'ADD', id: r.id}); + }); var def = self._readUngroupedList(x2manyList).then(function () { return $.when( self._fetchX2ManysBatched(x2manyList), -- cgit v1.2.3 From 776bac6a069fc1ef2d6bea0e85a0737e3cefecef Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Sat, 30 Sep 2017 10:50:41 +0200 Subject: [FIX] web: don't discard x2many rows coming from default_get Problem occured in the MRP Production wizard (with a consumed product tracked by serial number). The opened record is a new record, and its one2many has 2 default rows that are prefilled. If the user edited one of the quantities in those rows, and set an invalid value instead (e.g. a letter), the row was removed without notice when it was focused out. This was because the model wasn't aware that a change has been done on the record, and as the record was flagged as new, it was simply abandonned. --- addons/web/static/src/js/views/basic/basic_model.js | 11 +++++++++++ 1 file changed, 11 insertions(+) (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 9e7fb8b78ef..57c4a1f3743 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -947,6 +947,17 @@ var BasicModel = AbstractModel.extend({ record.fields = _.defaults(record.fields, viewInfo.fields); record.fieldsInfo = _.defaults(record.fieldsInfo, viewInfo.fieldsInfo); }, + /** + * Manually sets a resource as dirty. This is used to notify that a field + * has been modified, but with an invalid value. In that case, the value is + * not sent to the basic model, but the record should still be flagged as + * dirty so that it isn't discarded without any warning. + * + * @param {string} id a resource id + */ + setDirty: function (id) { + this.localData[id]._isDirty = true; + }, /** * For list resources, this changes the orderedBy key. * -- cgit v1.2.3