diff --git a/header_search_panel/static/src/search/header_search/components/fields_filter/fields_filter.js b/header_search_panel/static/src/search/header_search/components/fields_filter/fields_filter.js
index 67096c5cb..b42de2f74 100644
--- a/header_search_panel/static/src/search/header_search/components/fields_filter/fields_filter.js
+++ b/header_search_panel/static/src/search/header_search/components/fields_filter/fields_filter.js
@@ -147,7 +147,6 @@ export class FieldsFilter extends Component {
fieldString: field.fieldString,
searchLimit: field.fieldOptions?.search_limit || 10,
placeholder: field.placeholder,
- isMulti: field.fieldWidget === "multi",
}
this._addFieldBaseProps(field.props, field);
}
diff --git a/header_search_panel/static/src/search/header_search/components/fields_filter/many2one_filter/many2one_filter.js b/header_search_panel/static/src/search/header_search/components/fields_filter/many2one_filter/many2one_filter.js
index 6da90fe4f..071d04832 100644
--- a/header_search_panel/static/src/search/header_search/components/fields_filter/many2one_filter/many2one_filter.js
+++ b/header_search_panel/static/src/search/header_search/components/fields_filter/many2one_filter/many2one_filter.js
@@ -1,6 +1,6 @@
/** @odoo-module **/
-import { Component, useState } from "@odoo/owl";
+import { Component } from "@odoo/owl";
import { Domain } from "@web/core/domain";
import { useService } from "@web/core/utils/hooks";
import { Many2XAutocomplete } from "@web/views/fields/relational_utils";
@@ -12,32 +12,60 @@ export class Many2oneFilter extends Component {
super.setup();
this.rpc = useService("rpc");
this.user = useService("user");
- const saved = this.env.searchModel.headerSearchInfo.FieldsFilter[this.props.id]?.activeValues;
- if (this.props.isMulti) {
- // 多选模式:activeValues 是数组 [{id, name}, ...]
- this.state = useState({ multiValues: Array.isArray(saved) ? saved : [] });
+ this.activeValues = this.env.searchModel.headerSearchInfo.FieldsFilter[this.props.id]?.activeValues || [];
+ }
+
+ /**
+ * 设置筛选字段的值
+ */
+ setActiveValues(ev) {
+ /*
+ * 判断值是否是单选,如果是单选,则替换掉之前的值
+ * 否则,判断是选中还是取消选中,如果是选中,则添加到数组中,否则从数组中删除
+ * */
+ const value = ev.target.value;
+ const isChecked = ev.target.checked;
+
+ if (this.props.isSingle) {
+ this.activeValues = [value];
} else {
- // 单选模式:activeValues 是对象 {id, name} 或 {}
- this.activeValues = (saved && !Array.isArray(saved)) ? saved : {};
+ // 判断是选中还是取消选中,如果是选中,则添加到数组中,否则从数组中删除
+ if (isChecked) {
+ // 如果是选中状态,则添加到数组中
+ this.activeValues.push(value);
+ } else {
+ // 如果是取消选中状态,则从数组中删除
+ const index = this.activeValues.indexOf(value);
+ if (index !== -1) {
+ this.activeValues.splice(index, 1);
+ }
+ }
}
}
- // ===== 单选模式 domain =====
+ /**
+ * 获取筛选字段的domain
+ */
get domain() {
- if (this.props.isMulti) {
- const ids = this.state.multiValues.map(v => v.id);
- return ids.length ? [[this.props.name, "in", ids]] : [];
- }
- return this.activeValues.id ? [[this.props.name, "=", this.activeValues.id]] : [];
+ return this.activeValues.id ? [[this.props.name, "=", this.activeValues.id]]: [];
}
+ /**
+ * 点击筛选字段时触发,将筛选字段
+ */
+ selectionOnchange(ev) {
+ // 设置筛选字段的值
+ this.setActiveValues(ev);
+ this.props.fieldOnchange({fieldDomainList: this.domain, activeValues: this.activeValues});
+ }
+
+ /**
+ * 点击清空筛选时触发
+ */
resetFilter() {
- if (this.props.isMulti) {
- this.state.multiValues = [];
- } else {
- this.activeValues = {};
- }
- this.props.fieldOnchange({ fieldDomainList: this.domain, activeValues: this.props.isMulti ? this.state.multiValues : this.activeValues });
+ // 清空筛选字段的值
+ this.activeValues = [];
+ this.props.fieldOnchange({fieldDomainList: this.domain, activeValues: this.activeValues});
}
getDomain() {
@@ -48,24 +76,19 @@ export class Many2oneFilter extends Component {
return new Domain(this.props.domain).toList(evalContext);
}
- // ===== 单选 update =====
async update(value) {
- if (this.props.isMulti) {
- await this.updateMulti(value);
- return;
- }
if (value) {
- value = value[0];
+ value = value[0]
if (!value.name) {
try {
- await this.rpc("/web/dataset/call_kw", {
+ await this.rpc("/web/dataset/call_kw",{
model: this.props.resModel,
method: "name_get",
args: [[value.id]],
kwargs: {},
}).then((result) => {
- value.name = result[0][1];
- });
+ value.name = result[0][1]
+ })
} catch (error) {
this.activeValues = {};
}
@@ -74,46 +97,16 @@ export class Many2oneFilter extends Component {
} else {
this.activeValues = {};
}
- this.props.fieldOnchange({ fieldDomainList: this.domain, activeValues: this.activeValues });
- }
-
- // ===== 多选 update =====
- async updateMulti(value) {
- if (value && value.length) {
- let item = value[0];
- if (!item.name) {
- try {
- await this.rpc("/web/dataset/call_kw", {
- model: this.props.resModel,
- method: "name_get",
- args: [[item.id]],
- kwargs: {},
- }).then((result) => {
- item.name = result[0][1];
- });
- } catch (e) { return; }
- }
- // 去重
- if (!this.state.multiValues.find(v => v.id === item.id)) {
- this.state.multiValues = [...this.state.multiValues, item];
- }
- }
- this.props.fieldOnchange({ fieldDomainList: this.domain, activeValues: this.state.multiValues });
- }
-
- // ===== 多选:删除某个 tag =====
- removeTag(id) {
- this.state.multiValues = this.state.multiValues.filter(v => v.id !== id);
- this.props.fieldOnchange({ fieldDomainList: this.domain, activeValues: this.state.multiValues });
+ this.props.fieldOnchange({fieldDomainList: this.domain, activeValues: this.activeValues})
}
get Many2XAutocompleteProps() {
return {
- value: this.props.isMulti ? '' : (this.activeValues.name || ''),
+ value: this.activeValues.name || '',
resModel: this.props.resModel,
getDomain: this.getDomain.bind(this),
update: this.update.bind(this),
- activeActions: { create: false, createEdit: false, write: false },
+ activeActions: {create: false, createEdit: false, write: false},
fieldString: this.props.fieldString,
searchLimit: this.props.searchLimit,
placeholder: this.props.placeholder,
@@ -127,9 +120,8 @@ Many2oneFilter.components = {
};
Many2oneFilter.props = {
...standardFieldFilterProps,
- resModel: { type: String, required: true },
- domain: { type: String, optional: true },
- fieldString: { type: String, optional: true },
- searchLimit: { type: Number, optional: true },
- isMulti: { type: Boolean, optional: true },
+ resModel: {type: String, required: true},
+ domain: {type: String, optional: true},
+ fieldString: {type: String, optional: true},
+ searchLimit: {type: Number, optional: true},
};
diff --git a/header_search_panel/static/src/search/header_search/components/fields_filter/many2one_filter/many2one_filter.xml b/header_search_panel/static/src/search/header_search/components/fields_filter/many2one_filter/many2one_filter.xml
index 194375eb2..8acbac67a 100644
--- a/header_search_panel/static/src/search/header_search/components/fields_filter/many2one_filter/many2one_filter.xml
+++ b/header_search_panel/static/src/search/header_search/components/fields_filter/many2one_filter/many2one_filter.xml
@@ -1,24 +1,9 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/yuthon_property_approval/views/inherit_yuthon_property_views.xml b/yuthon_property_approval/views/inherit_yuthon_property_views.xml
index 119362068..dcd117e81 100644
--- a/yuthon_property_approval/views/inherit_yuthon_property_views.xml
+++ b/yuthon_property_approval/views/inherit_yuthon_property_views.xml
@@ -481,9 +481,9 @@
-
+
-
+
diff --git a/yuthon_purchase/views/inherit_purchase_order_views.xml b/yuthon_purchase/views/inherit_purchase_order_views.xml
index 64ea56edc..73ec59264 100644
--- a/yuthon_purchase/views/inherit_purchase_order_views.xml
+++ b/yuthon_purchase/views/inherit_purchase_order_views.xml
@@ -124,7 +124,6 @@
-
购******的事宜