[FIX] web: tempus dominus date as null in setup

- Open User-defined Filters in debug mode;
- Create a new Filter, name it;
- Use Contact model;
- Add a filter in the domain;
- Choose Last Update On;
- on the domain code editor modify it to be :
 `[("write_date", "=", context_today())]`
- Save the new filter and comeback to the filter lists;
- Open again the filter;
- Click in "Invalid DateTime";
- Choose a new date;
- Discard the changes;
- Click again in "Invalid DateTime".

Before this commit, a traceback is raised. This error occurs because
Bootstrap's Tempus Dominus don't manage correctly when in the setup we
send `null` as date.

Now, we sent a invalid date to Tempus Dominus.

closes odoo/odoo#111593

X-original-commit: b43f9473d1597b71323488f7d11e5f1fbdf0d638
Signed-off-by: Bruno Boi (boi) <boi@odoo.com>
Signed-off-by: Jorge Pinna Puissant (jpp) <jpp@odoo.com>
Co-authored-by: Michael Mattiello (mcm) <mcm@odoo.com>
This commit is contained in:
Jorge Pinna Puissant
2023-02-01 14:38:26 +01:00
co-authored by Michael Mattiello
parent affc184a76
commit b4038c915a
3 changed files with 52 additions and 4 deletions
@@ -189,7 +189,7 @@ export class DatePicker extends Component {
};
for (const prop in params) {
if (params[prop] instanceof DateTime) {
params[prop] = params[prop].isValid ? luxonToMoment(params[prop]) : null;
params[prop] = luxonToMoment(params[prop]);
}
}
commandOrParams = params;
+7 -3
View File
@@ -174,9 +174,13 @@ export const luxonToMomentFormat = memoize(function luxonToMomentFormat(format)
* @returns {moment} a moment.js object in the browser's timezone
*/
export function luxonToMoment(dt) {
const o = dt.toObject();
// Note: the month is 0-based in moment.js, but 1-based in luxon.js
return moment({ ...o, month: o.month - 1 });
if (dt.isValid) {
const o = dt.toObject();
// Note: the month is 0-based in moment.js, but 1-based in luxon.js
return moment({ ...o, month: o.month - 1 });
} else {
return moment.invalid();
}
}
/**
@@ -3,6 +3,7 @@
import { makeView, setupViewRegistries } from "@web/../tests/views/helpers";
import {
click,
clickDiscard,
clickSave,
editInput,
getFixture,
@@ -121,6 +122,49 @@ QUnit.module("Fields", (hooks) => {
}
);
QUnit.test(
"The domain editor should not crash the view when given a dynamic filter ( datetime )",
async function (assert) {
// dynamic filters (containing variables, such as uid, parent or today)
// are not handled by the domain editor, but it shouldn't crash the view
serverData.models.partner.records[0].foo = `[("datetime", "=", context_today())]`;
serverData.models.partner.fields.datetime = { string: "A date", type: "datetime" };
await makeView({
type: "form",
resModel: "partner",
resId: 1,
serverData,
arch: `
<form>
<field name="foo" widget="domain" options="{'model': 'partner'}" />
</form>`,
});
// The input field should display that the date is invalid
assert.equal(target.querySelector(".o_datepicker_input").value, "Invalid DateTime");
// Change the date in the datepicker
await click(target, ".o_datepicker_input");
// Select a date in the datepicker
await click(
document.body.querySelector(
`.bootstrap-datetimepicker-widget :not(.today)[data-action="selectDay"]`
)
);
// Close the datepicker
await click(
document.body.querySelector(
`.bootstrap-datetimepicker-widget a[data-action="close"]`
)
);
await clickDiscard(target);
// Open the datepicker again
await click(target, ".o_datepicker_input");
}
);
QUnit.test("basic domain field usage is ok", async function (assert) {
serverData.models.partner.records[0].foo = "[]";