[FIX] web: disable timezone convert for Date field custom filters
Reproduction: 1. Install Timesheet, and load demo data 2. Mimic a timezone in browser (Chrome): Right click->Inspect->Sensors, in the Location-> choose Other…, type “America/Puerto_Rico” in Timezone ID, refresh the page 3. Go to Timesheets->Timesheets->All timesheets, choose pivot view 4. Add custom filter, Date is between 1st/Aug/2022 and 5th/Aug/2022, apply 5. The filter result is correct but the tag in the search bar is “Date is between 31/07/2022 and 04/08/2022” This also happens to other fields with type Date, but not Datetime. For example, in Accounting->Reporting->Invoices Analysis->Pivot view, the same issue happens with Due Date filter. For Datetime field, it doesn’t have the issue, for example in CRM->Sales->My pipeline, change to pivot view, the custom filter for Assignment Date doesn’t have the time zone issue. Note: reproduction usually works during the daytime in Brussels. Reason: miswriting when rewrote custom_filter_item from V14 to V15. The value pushed to descriptionArray should not be changed on time zone. Fix: in parseField and formatField, use default formatters/parsers options. Add test for the Date filters. Related PR: odoo-dev@aeb8e49?diff=unified#diff-6d9230cfcd007b087b2851cbf0b4a33b26dc3c91087853da6fe7ce8c2b60e42f Reference code in V14: https://github.com/odoo/odoo/blob/14.0/addons/web/static/src/js/control_panel/custom_filter_item.js#L170-L173 opw-2941231 Part-of: odoo/odoo#98980 Co-authored-by: Liu Jinjiu <jili@odoo.com>
This commit is contained in:
@@ -86,22 +86,22 @@ const FIELD_OPERATORS = {
|
||||
],
|
||||
};
|
||||
|
||||
function parseField(field, value, opts = {}) {
|
||||
function parseField(field, value) {
|
||||
if (FIELD_TYPES[field.type] === "char") {
|
||||
return value;
|
||||
}
|
||||
const type = field.type === "id" ? "integer" : field.type;
|
||||
const parse = parsers.contains(type) ? parsers.get(type) : (v) => v;
|
||||
return parse(value, { field, ...opts });
|
||||
return parse(value);
|
||||
}
|
||||
|
||||
function formatField(field, value, opts = {}) {
|
||||
function formatField(field, value) {
|
||||
if (FIELD_TYPES[field.type] === "char") {
|
||||
return value;
|
||||
}
|
||||
const type = field.type === "id" ? "integer" : field.type;
|
||||
const format = formatters.contains(type) ? formatters.get(type) : (v) => v;
|
||||
return format(value, { digits: field.digits, ...opts });
|
||||
return format(value, { digits: field.digits });
|
||||
}
|
||||
|
||||
export class CustomFilterItem extends Component {
|
||||
@@ -224,7 +224,7 @@ export class CustomFilterItem extends Component {
|
||||
domainValue = condition.value.map(serialize);
|
||||
descriptionArray.push(
|
||||
`"${condition.value
|
||||
.map((val) => formatField(field, val, { timezone: true }))
|
||||
.map((val) => formatField(field, val))
|
||||
.join(" " + this.env._t("and") + " ")}"`
|
||||
);
|
||||
} else {
|
||||
|
||||
@@ -446,6 +446,30 @@ QUnit.module("Search", (hooks) => {
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test("custom filter date with equal operator", async function (assert) {
|
||||
patchTimeZone(-240);
|
||||
patchDate(2017, 1, 22, 12, 30, 0);
|
||||
|
||||
const controlPanel = await makeWithSearch({
|
||||
serverData,
|
||||
resModel: "foo",
|
||||
Component: ControlPanel,
|
||||
searchViewId: false,
|
||||
searchMenuTypes: ["filter"],
|
||||
});
|
||||
|
||||
await toggleFilterMenu(target);
|
||||
await toggleAddCustomFilter(target);
|
||||
|
||||
await editConditionField(target, 0, "date_field");
|
||||
await editConditionOperator(target, 0, "=");
|
||||
await editConditionValue(target, 0, "01/01/2017");
|
||||
await applyFilter(target);
|
||||
|
||||
assert.deepEqual(getFacetTexts(target), ['A date is equal to "01/01/2017"']);
|
||||
assert.deepEqual(getDomain(controlPanel), [["date_field", "=", "2017-01-01"]]);
|
||||
});
|
||||
|
||||
QUnit.test("custom filter datetime with equal operator", async function (assert) {
|
||||
assert.expect(5);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user