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/core/domain.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'addons/web/static/src/js/core') diff --git a/addons/web/static/src/js/core/domain.js b/addons/web/static/src/js/core/domain.js index 7b873926727..75aaf0105ed 100644 --- a/addons/web/static/src/js/core/domain.js +++ b/addons/web/static/src/js/core/domain.js @@ -51,13 +51,30 @@ var Domain = collections.Tree.extend({ } else if (_.isArray(this._data)) { // The domain is a [name, operator, value] entity // First check if we have the field value in the field values set - if (!(this._data[0] in values)) { + // and if the first part of the domain contains 'parent.field' + // get the value from the parent record. + var isParentField = false; + var fieldName = this._data[0]; + // We split the domain first part and check if it's a match + // for the syntax 'parent.field'. + var parentField = this._data[0].split('.'); + if ('parent' in values && parentField.length === 2) { + fieldName = parentField[1]; + isParentField = parentField[0] === 'parent' && + fieldName in values.parent; + } + if (!(this._data[0] in values) && !(isParentField)) { throw new Error(_.str.sprintf( "Unknown field %s in domain", this._data[0] )); } - var fieldValue = values[this._data[0]]; + var fieldValue; + if (!isParentField) { + fieldValue = values[fieldName]; + } else { + fieldValue = values.parent[fieldName]; + } switch (this._data[1]) { case "=": -- cgit v1.2.3