From 7a13c3f3d0cc556dda6aa1fb7ff5ff9da3f8227c Mon Sep 17 00:00:00 2001 From: Mathieu Duckerts-Antoine Date: Tue, 30 May 2023 14:00:25 +0000 Subject: [PATCH] [IMP] web: domain selector: getDefaultFieldValue should know operator The computation of the default value used by an editor used to assume that the (default) operator is equal. We now pass the operator info to getDefaultFieldValue in order to be able to have a different default operator ("in" will become the default operator for relational fields). Part-of: odoo/odoo#126350 --- .../src/core/domain_selector/domain_selector.js | 17 +++++++++++++---- .../domain_selector/domain_selector_fields.js | 6 +++--- .../static/src/core/domain_selector/utils.js | 4 ++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/addons/web/static/src/core/domain_selector/domain_selector.js b/addons/web/static/src/core/domain_selector/domain_selector.js index f45d43f8f3a..a7e496f5ae6 100644 --- a/addons/web/static/src/core/domain_selector/domain_selector.js +++ b/addons/web/static/src/core/domain_selector/domain_selector.js @@ -192,7 +192,7 @@ export class DomainSelector extends Component { const pathInfo = { path, fieldDef }; node.pathInfo = pathInfo; node.operatorInfo = getOperatorsInfo(pathInfo.fieldDef)[0]; - node.value = getDefaultFieldValue(pathInfo.fieldDef); + node.value = getDefaultFieldValue(pathInfo.fieldDef, node.operatorInfo.key); this.notifyChanges(); } @@ -213,12 +213,18 @@ export class DomainSelector extends Component { } // binary operator with a non array value case 1: { - node.value = getDefaultFieldValue(node.pathInfo.fieldDef); + node.value = getDefaultFieldValue( + node.pathInfo.fieldDef, + node.operatorInfo.key + ); break; } // binary operator with a fixed sized array value default: { - const defaultValue = getDefaultFieldValue(node.pathInfo.fieldDef); + const defaultValue = getDefaultFieldValue( + node.pathInfo.fieldDef, + node.operatorInfo.key + ); node.value = Array(node.operatorInfo.valueCount).fill(defaultValue); break; } @@ -237,7 +243,10 @@ export class DomainSelector extends Component { } removeExprValue(node) { - this.updateLeafValue(node, getDefaultFieldValue(node.pathInfo.fieldDef)); + this.updateLeafValue( + node, + getDefaultFieldValue(node.pathInfo.fieldDef, node.operatorInfo.key) + ); } onDebugValueChange(value) { diff --git a/addons/web/static/src/core/domain_selector/domain_selector_fields.js b/addons/web/static/src/core/domain_selector/domain_selector_fields.js index 723d3e8deb1..9447f36189d 100644 --- a/addons/web/static/src/core/domain_selector/domain_selector_fields.js +++ b/addons/web/static/src/core/domain_selector/domain_selector_fields.js @@ -388,12 +388,12 @@ export function getOperatorsInfo(fieldDef) { return selectOperators(descr.operators); } -export function getDefaultFieldValue(fieldDef) { +export function getDefaultFieldValue(fieldDef, operatorKey) { const descr = getFieldInfo(fieldDef); - return descr.defaultValue(fieldDef); + return descr.defaultValue(fieldDef, operatorKey); } export function getDefaultOperator(fieldDef) { const [firstOperator] = getOperatorsInfo(fieldDef); - return firstOperator.symbol; + return firstOperator; } diff --git a/addons/web/static/src/core/domain_selector/utils.js b/addons/web/static/src/core/domain_selector/utils.js index cf3cfa17847..8c726a22920 100644 --- a/addons/web/static/src/core/domain_selector/utils.js +++ b/addons/web/static/src/core/domain_selector/utils.js @@ -49,8 +49,8 @@ function getDefaultDomain(fieldDefs) { fieldDef = fieldDefs[name]; if (fieldDef) { const operator = getDefaultOperator(fieldDef); - const defaultValue = getDefaultFieldValue(fieldDef); - return new Domain([[fieldDef.name, operator, defaultValue]]).toString(); + const defaultValue = getDefaultFieldValue(fieldDef, operator.key); + return new Domain([[fieldDef.name, operator.symbol, defaultValue]]).toString(); } } return new Domain([["id", "=", 1]]).toString();