changeset 9479f2f53ca1 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset&node=9479f2f53ca1
description:
        Support empty digits in format_number of Report

        issue10678
        review365801002
diffstat:

 CHANGELOG                |   1 +
 trytond/report/report.py |  11 +++++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diffs (40 lines):

diff -r 0ea91b3063af -r 9479f2f53ca1 CHANGELOG
--- a/CHANGELOG Fri Aug 27 09:05:23 2021 +0200
+++ b/CHANGELOG Mon Aug 30 00:26:41 2021 +0200
@@ -1,3 +1,4 @@
+* Support empty digits in format_number of Report
 * Add digits mixin
 * Use argon2 or scrypt to hash password by default
 * Allow PYSON Expression as key for PYSON In with dict object
diff -r 0ea91b3063af -r 9479f2f53ca1 trytond/report/report.py
--- a/trytond/report/report.py  Fri Aug 27 09:05:23 2021 +0200
+++ b/trytond/report/report.py  Mon Aug 30 00:26:41 2021 +0200
@@ -12,6 +12,8 @@
 import warnings
 import zipfile
 import operator
+
+from decimal import Decimal
 from email.mime.multipart import MIMEMultipart
 from email.mime.text import MIMEText
 from io import BytesIO
@@ -439,12 +441,17 @@
         return lang.currency(value, currency, symbol, grouping, digits=digits)
 
     @classmethod
-    def format_number(cls, value, lang, digits=2, grouping=True,
-            monetary=None):
+    def format_number(
+            cls, value, lang, digits=None, grouping=True, monetary=None):
         pool = Pool()
         Lang = pool.get('ir.lang')
         if lang is None:
             lang = Lang.get()
+        if digits is None:
+            d = value
+            if not isinstance(d, Decimal):
+                d = Decimal(repr(value))
+            digits = -int(d.as_tuple().exponent)
         return lang.format('%.' + str(digits) + 'f', value,
             grouping=grouping, monetary=monetary)
 

Reply via email to