Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return a compatible type for multi valued fields in unique_value [PREVIEW] #155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2675,18 +2675,19 @@
unique_value: function(domain) {
if ((domain instanceof Array) &&
(domain.length == 1)) {
domain = domain[0];
var name = domain[0];
var value = domain[2];
var count = 0;
if (domain.length == 4 && name.endsWith('.id')) {
count = 1;
var model = domain[3];
value = [model, value];
}
if ((name.split('.').length - 1) == count &&
(domain[1] == '=')) {
return [true, domain[1], value];
let [name, operator, value, ...model] = domain[0];
if (operator == '=' ||
(operator == 'in' && value.length == 1)) {
value = operator == '=' ? value : value[0];
var count = 0;
if (model.length && name.endsWith('.id')) {
count = 1;
model = model[0];
value = [model, value];
}
if ((name.split('.').length - 1) == count) {
return [true, name, value];
}
}
}
return [false, null, null];
Expand Down
27 changes: 22 additions & 5 deletions src/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,10 @@
return true;
}
var invalid = false;
this.get_state_attrs(record).domain_readonly = false;
var state_attrs = this.get_state_attrs(record);
var is_required = Boolean(parseInt(state_attrs.required, 10));
var is_invisible = Boolean(parseInt(state_attrs.invisible, 10));
state_attrs.domain_readonly = false;
var inversion = new Sao.common.DomainInversion();
var domain = inversion.simplify(this.validation_domains(record,
pre_validate));
Expand All @@ -1688,11 +1691,20 @@
} else if (Sao.common.compare(domain, [['id', '=', null]])) {
invalid = 'domain';
} else {
let [screen_domain, _] = this.get_domains(
record, pre_validate);
var uniques = inversion.unique_value(domain);
var unique = uniques[0];
var leftpart = uniques[1];
var value = uniques[2];
if (unique) {
let unique_from_screen = inversion.unique_value(
screen_domain)[0];
if (this._is_empty(record) &&
!is_required &&
!is_invisible &&
!unique_from_screen) {
// Do nothing
} else if (unique) {
// If the inverted domain is so constraint that only one
// value is possible we should use it. But we must also pay
// attention to the fact that the original domain might be
Expand Down Expand Up @@ -1727,16 +1739,15 @@
}
if (setdefault && !pre_validate) {
this.set_client(record, value);
this.get_state_attrs(record).domain_readonly =
domain_readonly;
state_attrs.domain_readonly = domain_readonly;
}
}
if (!inversion.eval_domain(domain,
Sao.common.EvalEnvironment(record))) {
invalid = domain;
}
}
this.get_state_attrs(record).invalid = invalid;
state_attrs.invalid = invalid;
return !invalid;
}
});
Expand Down Expand Up @@ -1779,6 +1790,12 @@
return value;
},
set_client: function(record, value, force_change) {
if (value === null) {
value = [];
}
if (typeof(value) == 'string') {
value = [value];
}
if (value) {
value = value.slice().sort();
}
Expand Down