changeset c792849c589e in tryton:default
details: https://hg.tryton.org/tryton?cmd=changeset&node=c792849c589e
description:
        Support digits from relation field

        issue10596
        review338511002
diffstat:

 CHANGELOG                                  |   1 +
 tryton/gui/window/view_form/model/field.py |  17 +++++++++++++++++
 2 files changed, 18 insertions(+), 0 deletions(-)

diffs (35 lines):

diff -r c25c1b385cb9 -r c792849c589e CHANGELOG
--- a/CHANGELOG Thu Aug 12 18:39:50 2021 +0200
+++ b/CHANGELOG Sat Aug 21 09:08:09 2021 +0200
@@ -1,3 +1,4 @@
+* Support digits from relation field
 * Allow PYSON Expression as key for PYSON In with dict object
 * Support Binary field in CSV import/export
 
diff -r c25c1b385cb9 -r c792849c589e tryton/gui/window/view_form/model/field.py
--- a/tryton/gui/window/view_form/model/field.py        Thu Aug 12 18:39:50 
2021 +0200
+++ b/tryton/gui/window/view_form/model/field.py        Sat Aug 21 09:08:09 
2021 +0200
@@ -350,6 +350,23 @@
 
     def digits(self, record, factor=1):
         digits = record.expr_eval(self.attrs.get('digits'))
+        if isinstance(digits, str):
+            if digits not in record.group.fields:
+                return
+            digits_field = record.group.fields[digits]
+            digits_name = digits_field.attrs.get('relation')
+            digits_id = digits_field.get(record)
+            if digits_name and digits_id is not None and digits_id >= 0:
+                try:
+                    digits = RPCExecute(
+                        'model', digits_name, 'get_digits', digits_id)
+                except RPCException:
+                    logger.warn(
+                        "Fail to fetch digits for %s,%s",
+                        digits_name, digits_id)
+                    return
+            else:
+                return
         if not digits or any(d is None for d in digits):
             return
         shift = int(round(math.log(abs(factor), 10)))

Reply via email to