From 62e6c8090dc209f8448e691aec0cb47cb97a1ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 26 Sep 2021 23:05:02 +0200 Subject: [PATCH] Add grouping attribute to numeric widgets issue10731 review355501002 --- CHANGELOG | 1 + tryton/gui/window/view_form/model/field.py | 16 ++++++++++------ .../window/view_form/view/form_gtk/integer.py | 4 +++- .../gui/window/view_form/view/list_gtk/widget.py | 3 ++- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 59c102ace4..a86248ddb3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Support grouping attribute * Support monetary and symbol field attributes * Support digits from relation field * Allow PYSON Expression as key for PYSON In with dict object diff --git a/tryton/gui/window/view_form/model/field.py b/tryton/gui/window/view_form/model/field.py index 4496503ffa..f6d0798b60 100644 --- a/tryton/gui/window/view_form/model/field.py +++ b/tryton/gui/window/view_form/model/field.py @@ -413,7 +413,7 @@ class FloatField(Field): super(FloatField, self).set_client(record, value, force_change=force_change) - def get_client(self, record, factor=1): + def get_client(self, record, factor=1, grouping=True): value = record.value.get(self.name) if value is not None: digits = self.digits(record, factor=factor) @@ -422,10 +422,13 @@ class FloatField(Field): d = Decimal(repr(d)) if digits: p = int(digits[1]) + elif d == d.to_integral_value(): + p = 0 else: p = -int(d.as_tuple().exponent) monetary = self.attrs.get('monetary', False) - return locale.localize('{0:.{1}f}'.format(d, p), True, monetary) + return locale.localize( + '{0:.{1}f}'.format(d, p), grouping, monetary) else: return '' @@ -443,9 +446,9 @@ class NumericField(FloatField): return super(NumericField, self).set_client(record, value, force_change=force_change, factor=Decimal(str(factor))) - def get_client(self, record, factor=1): + def get_client(self, record, factor=1, grouping=True): return super(NumericField, self).get_client(record, - factor=Decimal(str(factor))) + factor=Decimal(str(factor)), grouping=grouping) class IntegerField(FloatField): @@ -461,8 +464,9 @@ class IntegerField(FloatField): return super(IntegerField, self).set_client(record, value, force_change=force_change, factor=int(factor)) - def get_client(self, record, factor=1): - return super(IntegerField, self).get_client(record, factor=int(factor)) + def get_client(self, record, factor=1, grouping=True): + return super(IntegerField, self).get_client( + record, factor=int(factor), grouping=grouping) class BooleanField(Field): diff --git a/tryton/gui/window/view_form/view/form_gtk/integer.py b/tryton/gui/window/view_form/view/form_gtk/integer.py index 3d1a39846d..b2ee717929 100644 --- a/tryton/gui/window/view_form/view/form_gtk/integer.py +++ b/tryton/gui/window/view_form/view/form_gtk/integer.py @@ -26,6 +26,7 @@ class Integer(Widget): self.symbol_start, expand=False, fill=False, padding=1) self.widget.pack_start(self.entry, expand=False, fill=False, padding=0) self.factor = float(attrs.get('factor', 1)) + self.grouping = bool(int(attrs.get('grouping', 1))) if self.symbol: self.symbol_end = Gtk.Entry(editable=False) self.widget.pack_start( @@ -49,7 +50,8 @@ class Integer(Widget): if not self.field: value = '' else: - value = self.field.get_client(self.record, factor=self.factor) + value = self.field.get_client( + self.record, factor=self.factor, grouping=self.grouping) return value @property diff --git a/tryton/gui/window/view_form/view/list_gtk/widget.py b/tryton/gui/window/view_form/view/list_gtk/widget.py index 2d4a811a4e..49cacdf057 100644 --- a/tryton/gui/window/view_form/view/list_gtk/widget.py +++ b/tryton/gui/window/view_form/view/list_gtk/widget.py @@ -371,6 +371,7 @@ class Int(GenericText): super(Int, self).__init__(view, attrs, renderer=renderer) self.factor = float(attrs.get('factor', 1)) self.symbol = attrs.get('symbol') + self.grouping = bool(int(attrs.get('grouping', 1))) if self.symbol: self.renderer_prefix = Symbol(view, attrs, 0) self.renderer_suffix = Symbol(view, attrs, 1) @@ -391,7 +392,7 @@ class Int(GenericText): if not record: return '' return record[self.attrs['name']].get_client( - record, factor=self.factor) + record, factor=self.factor, grouping=self.grouping) def value_from_text(self, record, text, callback=None): field = record[self.attrs['name']]