From b6f11ace836e946eeeae110cdb08d16d80546238 Mon Sep 17 00:00:00 2001 From: "Julien (juc) Castiaux" Date: Wed, 16 Jan 2019 15:26:18 +0000 Subject: [FIX] web: datepicker fallbacks to default english locale When using the datepicker with norwegian locales, the dates are correctly formatted using the norwegian locale but the name of the months are shown in english. This cause a date validation error and thus it is not possible to change the date. tempusdominus.js uses moment.js to deal with dates, it sometimes copies/creates some and set their option according to the ones given at instantiation time and fallbacks on default options for that are not set. opw-1922437 closes odoo/odoo#30276 --- .../web/static/tests/fields/basic_fields_tests.js | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'addons/web/static/tests/fields/basic_fields_tests.js') diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index cb49e8b5bba..978e6de226f 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -2969,6 +2969,47 @@ QUnit.module('basic_fields', { form.destroy(); }); + QUnit.test('date field support internalization', function (assert) { + assert.expect(2); + + var originalLocale = moment.locale(); + var originalParameters = _.clone(core._t.database.parameters); + + _.extend(core._t.database.parameters, {date_format: '%d. %b %Y', time_format: '%H:%M:%S'}); + moment.defineLocale('norvegianForTest', { + monthsShort: 'jan._feb._mars_april_mai_juni_juli_aug._sep._okt._nov._des.'.split('_'), + monthsParseExact: true, + dayOfMonthOrdinalParse: /\d{1,2}\./, + ordinal: '%d.', + }); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch:'
', + res_id: 1, + }); + + var dateViewForm = form.$('.o_field_date').text(); + testUtils.dom.click(form.$buttons.find('.o_form_button_edit')); + testUtils.openDatepicker(form.$('.o_datepicker')); + assert.strictEqual(form.$('.o_datepicker_input').val(), dateViewForm, + "input date field should be the same as it was in the view form"); + + testUtils.dom.click($('.day:contains(30)')); + var dateEditForm = form.$('.o_datepicker_input').val() + testUtils.dom.click(form.$buttons.find('.o_form_button_save')); + assert.strictEqual(form.$('.o_field_date').text(), dateEditForm, + "date field should be the same as the one selected in the view form"); + + moment.locale(originalLocale); + moment.updateLocale('norvegianForTest', null); + core._t.database.parameters = originalParameters; + + form.destroy(); + }); + QUnit.module('FieldDatetime'); QUnit.test('datetime field in form view', function (assert) { -- cgit v1.2.3