[IMP] web: add support for domain and context in DomainSelectorAutocomplete
This commit adds support for domain and context in DomainSelectorAutocomplete. This is a step towards the simplification of the Record component. We would like to remove the case where the Record component is used with fake resModel/resId only to display a Many2ManyTags or a Many2One. Instead, we could simply use the DomainSelectorAutocomplete or DomainSelectorSingleAutocomplete to achieve the same result. Part of task-id 3433922 Part-of: odoo/odoo#137650
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import { Component, onWillStart, onWillUpdateProps } from "@odoo/owl";
|
||||
import { AutoComplete } from "@web/core/autocomplete/autocomplete";
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
import { Domain } from "@web/core/domain";
|
||||
import { formatAST, toPyValue } from "@web/core/py_js/py_utils";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { TagsList } from "@web/core/tags_list/tags_list";
|
||||
@@ -21,6 +22,8 @@ class AutoCompleteWithSources extends Component {
|
||||
multiSelect: Boolean,
|
||||
getIds: Function,
|
||||
value: String,
|
||||
domain: { type: Array, optional: true },
|
||||
context: { type: Object, optional: true },
|
||||
className: { type: String, optional: true },
|
||||
fieldString: { type: String, optional: true },
|
||||
};
|
||||
@@ -101,6 +104,7 @@ class AutoCompleteWithSources extends Component {
|
||||
resModel,
|
||||
noCreate: true,
|
||||
multiSelect,
|
||||
context: this.props.context || {},
|
||||
onSelected: (resId) => {
|
||||
const resIds = Array.isArray(resId) ? resId : [resId];
|
||||
this.props.update([...resIds]);
|
||||
@@ -108,6 +112,14 @@ class AutoCompleteWithSources extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
getDomain() {
|
||||
const domainIds = Domain.not([["id", "in", this.getIds()]]);
|
||||
if (this.props.domain) {
|
||||
return Domain.and([this.props.domain, domainIds]).toList();
|
||||
}
|
||||
return domainIds.toList();
|
||||
}
|
||||
|
||||
onSelect({ value: resId, action }, params) {
|
||||
if (action) {
|
||||
return action(params);
|
||||
@@ -116,12 +128,12 @@ class AutoCompleteWithSources extends Component {
|
||||
}
|
||||
|
||||
search(name, limit) {
|
||||
const ids = this.getIds();
|
||||
const domain = [["id", "not in", ids]];
|
||||
const domain = this.getDomain();
|
||||
return this.orm.call(this.props.resModel, "name_search", [], {
|
||||
name,
|
||||
args: domain,
|
||||
limit,
|
||||
context: this.props.context || {},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -156,6 +168,8 @@ export class DomainSelectorAutocomplete extends Component {
|
||||
resModel: String,
|
||||
update: Function,
|
||||
value: true,
|
||||
domain: { type: Array, optional: true },
|
||||
context: { type: Object, optional: true },
|
||||
fieldString: { type: String, optional: true },
|
||||
};
|
||||
static components = { AutoCompleteWithSources, TagsList };
|
||||
@@ -206,6 +220,8 @@ export class DomainSelectorSingleAutocomplete extends Component {
|
||||
static props = {
|
||||
resModel: String,
|
||||
update: Function,
|
||||
domain: { type: Array, optional: true },
|
||||
context: { type: Object, optional: true },
|
||||
value: true,
|
||||
fieldString: { type: String, optional: true },
|
||||
};
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
<AutoCompleteWithSources
|
||||
resModel="props.resModel"
|
||||
value="''"
|
||||
domain="props.domain"
|
||||
context="props.context"
|
||||
className="'o_input o_domain_leaf_value_input flex-grow-1'"
|
||||
fieldString="props.fieldString"
|
||||
multiSelect="true"
|
||||
@@ -32,6 +34,8 @@
|
||||
<AutoCompleteWithSources
|
||||
resModel="props.resModel"
|
||||
value="displayName"
|
||||
domain="props.domain"
|
||||
context="props.context"
|
||||
className="'o_input o_domain_leaf_value_input h-100'"
|
||||
fieldString="props.fieldString"
|
||||
multiSelect="false"
|
||||
|
||||
Reference in New Issue
Block a user