diff options
| author | Priyanka Kakadiya <pka@odoo.com> | 2020-10-06 09:56:39 +0000 |
|---|---|---|
| committer | Priyanka Kakadiya <pka@odoo.com> | 2020-10-06 09:56:47 +0000 |
| commit | a029fca2d0def06ea3f67270f0e1d654d49a0c57 (patch) | |
| tree | ad43c602870fc39828df61c37f9e478b23b32ef5 /addons/web | |
| parent | 5d3310cea75014ce3c43ee89235cd42b87e0cf99 (diff) | |
[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#59208
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Diffstat (limited to 'addons/web')
| -rw-r--r-- | addons/web/static/src/js/fields/basic_fields.js | 9 | ||||
| -rw-r--r-- | addons/web/static/tests/fields/basic_fields_tests.js | 48 |
2 files changed, 57 insertions, 0 deletions
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index efa9f522c98..e194ee6b522 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -638,6 +638,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 diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index 8586b9cb82e..5819bd22ffe 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -3483,6 +3483,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) { |
