diff --git a/addons/web/static/src/js/fields/special_fields.js b/addons/web/static/src/js/fields/special_fields.js index 7f4c737888216a03c63c7191fe401f5fbdb43b3d..69647902afec40aaf5c5d62b0583e84e306de45d 100644 --- a/addons/web/static/src/js/fields/special_fields.js +++ b/addons/web/static/src/js/fields/special_fields.js @@ -71,6 +71,7 @@ var FieldTimezoneMismatch = FieldSelection.extend({ // we need to clean the warning to have maximum one alert this.$el.last().filter('.o_tz_warning').remove(); this.$el = this.$el.first(); + var value = this.$el.val(); if (this.$option) { this.$option.html(this.$option.html().split(' ')[0]); @@ -78,7 +79,7 @@ var FieldTimezoneMismatch = FieldSelection.extend({ var userOffset = this.recordData.tz_offset; this.mismatch = false; - if (userOffset) { + if (userOffset && value !== "" && value !== "false") { var offset = -(new Date().getTimezoneOffset()); var browserOffset = (offset < 0) ? "-" : "+"; browserOffset += _.str.sprintf("%02d", Math.abs(offset / 60)); @@ -92,7 +93,6 @@ var FieldTimezoneMismatch = FieldSelection.extend({ $span.attr('title', _t("Timezone Mismatch : The timezone of your browser doesn't match the selected one. The time in Odoo is displayed according to your field timezone.")); this.$el = this.$el.add($span); - var value = this.$el.val(); this.$option = this.$('option').filter(function () { return $(this).attr('value') === value; }); diff --git a/addons/web/static/tests/fields/special_fields.js b/addons/web/static/tests/fields/special_fields.js index af725a007f1d2486cf1fc7c2594d416b9ded6598..6786f6783b7999f4463f434ecba5cc6d8e08effd 100644 --- a/addons/web/static/tests/fields/special_fields.js +++ b/addons/web/static/tests/fields/special_fields.js @@ -1,6 +1,7 @@ odoo.define('web.special_fields_tests', function (require) { "use strict"; +var FormView = require('web.FormView'); var ListView = require('web.ListView'); var testUtils = require('web.test_utils'); @@ -143,7 +144,10 @@ QUnit.module('special_fields', { QUnit.test('widget timezone_mismatch in a list view', function (assert) { assert.expect(5); - this.data.partner.fields.tz_offset = {string: "tz_offset", type: "integer"}; + this.data.partner.fields.tz_offset = { + string: "tz_offset", + type: "char" + }; this.data.partner.records.forEach(function (r) { r.color = 'red'; r.tz_offset = 0; @@ -180,6 +184,35 @@ QUnit.module('special_fields', { list.destroy(); }); + QUnit.test('widget timezone_mismatch in a form view', function (assert) { + assert.expect(1); + + this.data.partner.fields.tz_offset = { + string: "tz_offset", + type: "char" + }; + this.data.partner.fields.tz = { + type: "selection", + selection: [['Europe/Brussels', "Europe/Brussels"], ['America/Los_Angeles', "America/Los_Angeles"]], + }; + this.data.partner.records[0].tz = false; + this.data.partner.records[0].tz_offset = '+4800'; + + var form = createView({ + View: FormView, + model: 'partner', + res_id: 1, + data: this.data, + arch: '<form>' + + '<field name="tz_offset" invisible="True"/>' + + '<field name="tz" widget="timezone_mismatch"/>' + + '</form>', + }); + form.$buttons.find('.o_form_button_edit').click(); + assert.strictEqual(form.$('select').length, 1, "should have the select field"); + form.destroy(); + }); + }); }); });