From 3aecfc96584896f8b8369cd4e1e836d87975274b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 23 Oct 2024 13:56:53 +0200 Subject: [PATCH] Do not fail to set value of the wrong type to Dict Entry widget Closes #13621 --- sao/src/view/form.js | 13 ++++++++++--- .../window/view_form/view/form_gtk/dictionary.py | 12 +++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/sao/src/view/form.js b/sao/src/view/form.js index df94f44809..7c113038b0 100644 --- a/sao/src/view/form.js +++ b/sao/src/view/form.js @@ -5406,7 +5406,7 @@ function eval_pyson(value){ this.input.prop('disabled', readonly); }, set_value: function(value) { - this.input.prop('checked', value); + this.input.prop('checked', Boolean(value)); } }); @@ -5522,7 +5522,8 @@ function eval_pyson(value){ return value; }, set_value: function(value, options) { - if (value !== null) { + if ((typeof(value) == 'number') || + (value instanceof Sao.Decimal)) { this.input.val(value); this.input_text.val(value.toLocaleString( Sao.i18n.BC47(Sao.i18n.getlang()), options)); @@ -5658,7 +5659,13 @@ function eval_pyson(value){ return this._parse(this.format, this.input.val()); }, set_value: function(value) { - this.input.val(this._format(this.format, value)); + if ((value instanceof Sao.DateTime) || + (value instanceof Sao.Date)) { + value = this._format(this.format, value); + } else { + value = ''; + } + this.input.val(value); }, }); diff --git a/tryton/tryton/gui/window/view_form/view/form_gtk/dictionary.py b/tryton/tryton/gui/window/view_form/view/form_gtk/dictionary.py index 82ae7ec67d..ad5bcc9e88 100644 --- a/tryton/tryton/gui/window/view_form/view/form_gtk/dictionary.py +++ b/tryton/tryton/gui/window/view_form/view/form_gtk/dictionary.py @@ -1,6 +1,7 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of this # repository contains the full copyright notices and license terms. +import datetime as dt import decimal import gettext import locale @@ -64,7 +65,7 @@ class DictEntry(object): return self.widget.get_text() def set_value(self, value): - self.widget.set_text(value or '') + self.widget.set_text(str(value or '')) reset_position(self.widget) def set_readonly(self, readonly): @@ -286,7 +287,7 @@ class DictIntegerEntry(DictEntry): return None def set_value(self, value): - if value is not None: + if isinstance(value, (int, float, Decimal)): txt_val = locale.format_string('%d', value, True) else: txt_val = '' @@ -323,7 +324,7 @@ class DictFloatEntry(DictIntegerEntry): else: self.widget.digits = None self.widget.set_width_chars(self.width) - if value is not None: + if isinstance(value, (int, float, Decimal)): txt_val = locale.localize( '{0:.{1}f}'.format(value, digits[1]), True) else: @@ -369,7 +370,8 @@ class DictDateTimeEntry(DictEntry): return untimezoned_date(self.widget.props.value) def set_value(self, value): - self.widget.props.value = timezoned_date(value) + self.widget.props.value = ( + timezoned_date(value) if isinstance(value, dt.datetime) else None) def set_readonly(self, readonly): for child in self.widget.get_children(): @@ -404,7 +406,7 @@ class DictDateEntry(DictEntry): return self.widget.props.value def set_value(self, value): - self.widget.props.value = value + self.widget.props.value = value if isinstance(value, dt.date) else None def set_readonly(self, readonly): super().set_readonly(readonly)