[FIX] web: properties, date / datetime default values are never set

Bug
===
Since c5b87e130b , the Date / Datetime
are not formatted the way they suppose to be. So the value is not
correct (it contains the timezone, etc).

Because of that, the string "Invalid Date" is stored in database
instead of "YYY-mm-dd" when we change the default value in the
definition.

Task-3774178

closes odoo/odoo#155749

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
std-odoo
2024-03-04 11:29:45 +00:00
parent 91e7c5313d
commit 5b9cfff00c
2 changed files with 69 additions and 2 deletions
@@ -12,6 +12,8 @@ import {
deserializeDateTime,
formatDate,
formatDateTime,
serializeDate,
serializeDateTime,
} from "@web/core/l10n/dates";
import { _t } from "@web/core/l10n/translation";
import { TagsList } from "@web/core/tags_list/tags_list";
@@ -202,7 +204,11 @@ export class PropertyValue extends Component {
* @param {object} newValue
*/
async onValueChange(newValue) {
if (this.props.type === "integer") {
if (this.props.type === "datetime") {
newValue = newValue && serializeDateTime(newValue);
} else if (this.props.type === "date") {
newValue = newValue && serializeDate(newValue);
} else if (this.props.type === "integer") {
try {
newValue = parseInteger(newValue) || 0;
} catch {
@@ -11,6 +11,7 @@ import {
nextTick,
patchWithCleanup,
triggerEvent,
patchDate,
} from "@web/../tests/helpers/utils";
import { toggleActionMenu } from "@web/../tests/search/helpers";
import { createWebClient, doAction } from "@web/../tests/webclient/helpers";
@@ -39,6 +40,7 @@ async function changeType(target, propertyType) {
char: 1,
integer: 3,
float: 4,
date: 5,
datetime: 6,
selection: 7,
tags: 8,
@@ -513,7 +515,7 @@ QUnit.module("Fields", (hooks) => {
assert.containsOnce(
target,
".o_cp_action_menus span:contains(Add Properties)",
"The add button must be in the cog menu",
"The add button must be in the cog menu"
);
// Create a new property
@@ -1863,6 +1865,65 @@ QUnit.module("Fields", (hooks) => {
}
});
QUnit.test("properties: default value date", async function (assert) {
async function mockRPC(route, { method, model, kwargs }) {
if (["check_access_rights", "check_access_rule"].includes(method)) {
return true;
}
}
patchDate(2022, 0, 3, 8, 0, 0);
await makeView({
type: "form",
resModel: "partner",
resId: 1,
serverData,
arch: `
<form>
<sheet>
<group>
<field name="company_id"/>
<field name="properties"/>
</group>
</sheet>
</form>`,
mockRPC,
actionMenus: {},
});
const field = target.querySelector(".o_field_properties");
assert.ok(field, "The field must be in the view");
// add a new date property
await toggleActionMenu(target);
await click(target, ".o_cp_action_menus span .fa-cogs");
await nextTick();
let popover = target.querySelector(".o_property_field_popover");
assert.ok(popover, "Should have opened the definition popover");
await changeType(target, "date");
const type = popover.querySelector(".o_field_property_definition_type input");
assert.strictEqual(type.value, "Date", "Should have changed the property type");
// choose a default value and check that it is propagated on the property field
await click(target, ".o_field_property_definition_value .o_datetime_input");
assert.containsOnce(target, ".o_date_picker");
await click(getPickerCell("3").at(0));
await closePopover(target);
assert.strictEqual(
target.querySelector(".o_datetime_input").value,
"01/03/2022",
"The default date value should have been propagated"
);
// save the form and check that the default value is not reset
await click(target, ".o_form_button_save");
await click(target, ".o_property_field:nth-last-child(2) .o_field_property_open_popover");
popover = target.querySelector(".o_property_field_popover");
assert.strictEqual(
popover.querySelector(".o_field_property_definition_value input").value,
"01/03/2022"
);
});
/**
* check if property field popover closes when clicking on delete property icon.
*/