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

[FIX][17.0] date_range : error opening conditional on studio #914

Closed
Closed
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
126 changes: 65 additions & 61 deletions date_range/static/src/js/tree_editor.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,77 +46,81 @@ patch(TreeEditor.prototype, {
) {
info.component = Select;
}
let dateRanges = this.env.domain.dateRanges;
if (this.update_operator && this.update_operator.split("daterange_")[1]) {
dateRanges = this.env.domain.dateRanges.filter(
(range) =>
range.type_id[0] ===
Number(this.update_operator.split("daterange_")[1])
);
}
patch(info, {
extractProps({value, update}) {
const props = super.extractProps.apply(this, arguments);
if (
fieldDef &&
(fieldDef.type === "date" || fieldDef.type === "datetime") &&
node.operator.includes("daterange")
) {
let selected = dateRanges.find(
(range) =>
range.date_start ===
fromDateTime(value[1], fieldDef.type) &&
range.date_end === fromDateTime(value[0], fieldDef.type)
);
if (!selected) {
selected = dateRanges[0];
update([
toDateTime(selected.date_end, fieldDef.type),
toDateTime(selected.date_start, fieldDef.type, true),
]);
}

return {
options: dateRanges.map((dt) => [dt.id, dt.name]),
update: (v) => {
const range = dateRanges.find((r) => r.id === v);
if (typeof this.env.domain !== "undefined") {
let dateRanges = this.env.domain.dateRanges;
if (this.update_operator && this.update_operator.split("daterange_")[1]) {
dateRanges = this.env.domain.dateRanges.filter(
(range) =>
range.type_id[0] ===
Number(this.update_operator.split("daterange_")[1])
);
}
patch(info, {
extractProps({value, update}) {
const props = super.extractProps.apply(this, arguments);
if (
fieldDef &&
(fieldDef.type === "date" || fieldDef.type === "datetime") &&
node.operator.includes("daterange")
) {
let selected = dateRanges.find(
(range) =>
range.date_start ===
fromDateTime(value[1], fieldDef.type) &&
range.date_end === fromDateTime(value[0], fieldDef.type)
);
if (!selected) {
selected = dateRanges[0];
update([
toDateTime(range.date_end, fieldDef.type),
toDateTime(range.date_start, fieldDef.type, true),
toDateTime(selected.date_end, fieldDef.type),
toDateTime(selected.date_start, fieldDef.type, true),
]);
},
value: selected.id,
};
}
}

return props;
},
isSupported(value) {
if (node.operator.includes("daterange")) {
return Array.isArray(value) && value.length === 2;
}
return super.isSupported.apply(this, arguments);
},
});
return {
options: dateRanges.map((dt) => [dt.id, dt.name]),
update: (v) => {
const range = dateRanges.find((r) => r.id === v);
update([
toDateTime(range.date_end, fieldDef.type),
toDateTime(range.date_start, fieldDef.type, true),
]);
},
value: selected.id,
};
}

return props;
},
isSupported(value) {
if (node.operator.includes("daterange")) {
return Array.isArray(value) && value.length === 2;
}
return super.isSupported.apply(this, arguments);
},
});
}
return info;
},

updateLeafOperator(node, operator) {
super.updateLeafOperator.apply(this, arguments);
this.update_operator = operator;
const fieldDef = this.getFieldDef(node.path);
let dateRanges = this.env.domain.dateRanges.filter(
(range) => range.type_id[0] === Number(operator.split("daterange_")[1])
);
if (!dateRanges.length) {
dateRanges = this.env.domain.dateRanges;
}
if (operator.includes("daterange") && dateRanges) {
node.value = [
toDateTime(dateRanges[0].date_end, fieldDef.type),
toDateTime(dateRanges[0].date_start, fieldDef.type, true),
];
this.notifyChanges();
if (typeof this.env.domain !== "undefined") {
let dateRanges = this.env.domain.dateRanges.filter(
(range) => range.type_id[0] === Number(operator.split("daterange_")[1])
);
if (!dateRanges.length) {
dateRanges = this.env.domain.dateRanges;
}
if (operator.includes("daterange") && dateRanges) {
node.value = [
toDateTime(dateRanges[0].date_end, fieldDef.type),
toDateTime(dateRanges[0].date_start, fieldDef.type, true),
];
this.notifyChanges();
}
}
},
});
Loading