Skip to content
Snippets Groups Projects
Commit 9ba0767f authored by Christophe Matthieu's avatar Christophe Matthieu
Browse files

[FIX] web: unable to open User FormView from Settings

Uncaught TypeError: Cannot read property 'split' of undefined.
Crash when the value of widget 'timezone_mismatch' is false in form view.
parent 5dd23f7d
No related branches found
No related tags found
No related merge requests found
......@@ -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;
});
......
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();
});
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment