[FIX] web: send utc date to server from daterange widget
When manually updating the time on a daterange widget, the value sent to the server is not converted to UTC and is sent as it appears on the input. currently daterange widget send datetime value as it is, written in input field if manually entered, so if user set 10:00:00 so while sending data it will be send as it is 10:00:00 so when next time record reloaded after save, it will display 15:30:00 if timezone UTC+5:30. Instead, change the string date to moment object with current user timezone. so that datetime send to server is UTC time and when next time it is loaded it adds user timezone difference, so if timezone is UTC+5:30 and user enters 10:00:00 then while sending data to server it sends 04:30:00 and when displayed again after reload it adds +5:30 timezone difference. LINKS PR #50132 Task 2240378 closes odoo/odoo#59263 X-original-commit: a029fca2d0def06ea3f67270f0e1d654d49a0c57 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -682,6 +682,15 @@ var FieldDateRange = InputField.extend({
|
||||
}
|
||||
this._super.apply(this, arguments);
|
||||
},
|
||||
/**
|
||||
* Return the date written in the input, in UTC.
|
||||
*
|
||||
* @private
|
||||
* @returns {Moment|false}
|
||||
*/
|
||||
_getValue: function () {
|
||||
return field_utils.parse[this.formatType](this.$input.val(), this.field, { timezone: true });
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
|
||||
@@ -3568,6 +3568,54 @@ QUnit.module('basic_fields', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('Datetime field manually input value should send utc value to server', async function (assert) {
|
||||
assert.expect(4);
|
||||
|
||||
this.data.partner.fields.datetime_end = { string: 'Datetime End', type: 'datetime' };
|
||||
this.data.partner.records[0].datetime_end = '2017-03-13 00:00:00';
|
||||
|
||||
const form = await createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: `
|
||||
<form>
|
||||
<field name="datetime" widget="daterange" options="{'related_end_date': 'datetime_end'}"/>
|
||||
<field name="datetime_end" widget="daterange" options="{'related_start_date': 'datetime'}"/>
|
||||
</form>`,
|
||||
res_id: 1,
|
||||
session: {
|
||||
getTZOffset: function () {
|
||||
return 330;
|
||||
},
|
||||
},
|
||||
mockRPC: function (route, args) {
|
||||
if (args.method === 'write') {
|
||||
assert.deepEqual(args.args[1], { datetime: '2017-02-08 06:00:00' });
|
||||
}
|
||||
return this._super(...arguments);
|
||||
},
|
||||
});
|
||||
|
||||
// check date display correctly in readonly
|
||||
assert.strictEqual(form.$('.o_field_date_range:first').text(), '02/08/2017 15:30:00',
|
||||
"the start date should be correctly displayed in readonly");
|
||||
assert.strictEqual(form.$('.o_field_date_range:last').text(), '03/13/2017 05:30:00',
|
||||
"the end date should be correctly displayed in readonly");
|
||||
|
||||
// edit form
|
||||
await testUtils.form.clickEdit(form);
|
||||
// update input for Datetime
|
||||
await testUtils.fields.editInput(form.$('.o_field_date_range:first'), '02/08/2017 11:30:00');
|
||||
// save form
|
||||
await testUtils.form.clickSave(form);
|
||||
|
||||
assert.strictEqual(form.$('.o_field_date_range:first').text(), '02/08/2017 11:30:00',
|
||||
"the start date should be correctly displayed in readonly after manual update");
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.module('FieldDate');
|
||||
|
||||
QUnit.test('date field: toggle datepicker [REQUIRE FOCUS]', async function (assert) {
|
||||
|
||||
Reference in New Issue
Block a user