The original function I want to modify is:
// @spreadsheet/global_filters/helpers.js
export function getRelativeDateDomain(now, offset, rangeType, fieldName, fieldType) {
// original logic...
}
Since it’s a standalone exported function (not inside a class), I tried to patch it using Odoo’s patch() utility.
Here’s what I’ve done in my custom module:
/** @odoo-module **/
import { patch } from "@web/core/utils/patch";
import * as helpers from "@spreadsheet/global_filters/helpers";
import { RELATIVE_DATE_RANGE_TYPES } from "@spreadsheet/helpers/constants";
import { Domain } from "@web/core/domain";
import { serializeDate, serializeDateTime } from "@web/core/l10n/dates";
console.log("[Custom Patch] relative_date_patch.js loaded ✅");
// Step 1: Add new range types
if (!RELATIVE_DATE_RANGE_TYPES.find((r) => r.type === "today")) {
RELATIVE_DATE_RANGE_TYPES.unshift(
{ type: "today", description: "Today" },
{ type: "yesterday", description: "Yesterday" }
);
console.log("[Custom Patch] Added Today and Yesterday to RELATIVE_DATE_RANGE_TYPES");
}
// Step 2: Patch the helper function
patch(helpers, {
getRelativeDateDomain(now, offset, rangeType, fieldName, fieldType) {
console.log("[Custom Patch] getRelativeDateDomain called", rangeType);
switch (rangeType) {
case "today":
const startToday = now.startOf("day").plus({ days: offset });
const endToday = now.endOf("day").plus({ days: offset });
return new Domain([
"&",
[fieldName, ">=", serializeDate(startToday)],
[fieldName, "<=", serializeDate(endToday)],
]);
case "yesterday":
const yesterday = now.minus({ days: 1 }).plus({ days: offset });
const startYesterday = yesterday.startOf("day");
const endYesterday = yesterday.endOf("day");
return new Domain([
"&",
[fieldName, ">=", serializeDate(startYesterday)],
[fieldName, "<=", serializeDate(endYesterday)],
]);
default:
// fallback to original
return helpers.getRelativeDateDomain(...arguments);
}
},
});
console.log("[Custom Patch] getRelativeDateDomain patch applied successfully ✅");
Current logs show:
[Custom Patch] relative_date_patch.js loaded ✅
[Custom Patch] Added Today and Yesterday to RELATIVE_DATE_RANGE_TYPES
[Custom Patch] getRelativeDateDomain patch applied successfully ✅
But none of the logs inside the patched function appear - it seems Odoo still calls the original function from @spreadsheet/global_filters/helpers instead of my patched version.
How can I override or patch a standalone exported JS function like getRelativeDateDomain() in Odoo 18, so my patched version is actually used?