[FIX] web: allow date to be validated through the ENTER keyboard
When creating a custom datetime field (with date option type) with Studio and that you edit the field manually then validates with the ENTER keyboard, the date is changed (one day is removed - mm/dd-1/yy). Since [1]. Step to reproduce the issue: 1. Put yourself in Europe timezone (e.g. BE) 2. Add a datetime field via studio (e.g. on the product form) 3. Put a date widget (no datetime) 4. Enter a date manually mm/dd/yy 5. Hit ENTER without clicking outside the box You will see that the final date will be mm/dd-1/yy. Solution: The path applied when clicking outside the box and cliking ENTER is not the same. In the ENTER path, we check if the type of the field is a `datetime`, if so, we remove the offset TZ to match 00:00:00 instead of 02:00:00 (if you were in GMT+2 zone). The issue is that we do this offset if the customm field (via Studio) is a `datetime`. This check is incorrect: we can have a `datetime` field but a date widget, in that case, if we are not on GMT time we offset by some hours and we end up the day before (as we offset by 2 hours starting from midnight which results in 22PM the day before and when rendered as a simple date we "loose" one day). [1]: https://github.com/odoo/odoo/commit/08a423577f732b65ad5035e8f4662386a8631c5f opw-2830843 closes odoo/odoo#93293 X-original-commit: 37a58832bc966f28fb2c1d627dfe28cef4fb5de7 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com> Signed-off-by: Desausoi Laurent (lade) <lade@odoo.com>
This commit is contained in:
@@ -1001,7 +1001,7 @@ var FieldDate = InputField.extend({
|
||||
let value = this.$input.val();
|
||||
try {
|
||||
value = this._parseValue(value);
|
||||
if (this.field.type === "datetime") {
|
||||
if (this.datewidget.type_of_date === "datetime") {
|
||||
value.add(-this.getSession().getTZOffset(value), "minutes");
|
||||
}
|
||||
} catch (_err) {}
|
||||
|
||||
@@ -5250,6 +5250,41 @@ QUnit.module('basic_fields', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('datetime field with date widget: hit enter should update value', async function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
const form = await createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch:'<form string="Partners"><field name="datetime" widget="date"/></form>',
|
||||
res_id: 1,
|
||||
translateParameters: { // Avoid issues due to localization formats
|
||||
date_format: '%m/%d/%Y',
|
||||
},
|
||||
viewOptions: {
|
||||
mode: 'edit',
|
||||
},
|
||||
session: {
|
||||
getTZOffset: function () {
|
||||
return 120;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const datetime = form.el.querySelector('input[name="datetime"]');
|
||||
|
||||
await testUtils.fields.editInput(datetime, '01/08/22');
|
||||
await testUtils.fields.triggerKeydown(datetime, 'enter');
|
||||
assert.strictEqual(datetime.value, '01/08/2022');
|
||||
|
||||
// Click outside the field to check that the field is not changed
|
||||
await testUtils.dom.click(form.$el);
|
||||
assert.strictEqual(datetime.value, '01/08/2022');
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.module('RemainingDays');
|
||||
|
||||
QUnit.test('remaining_days widget on a date field in list view', async function (assert) {
|
||||
|
||||
Reference in New Issue
Block a user