From f8dafb20c00678a5149e4e6e0a2d5cd4f35b5635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 30 Aug 2021 00:26:41 +0200 Subject: [PATCH] Support empty digits in format_number of Report issue10678 review365801002 --- CHANGELOG | 1 + trytond/report/report.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 5050f7a18e..88a395c3cf 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 --git a/trytond/report/report.py b/trytond/report/report.py index 621b95a7d5..36c55a871d 100644 --- a/trytond/report/report.py +++ b/trytond/report/report.py @@ -12,6 +12,8 @@ import time 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 @@ class Report(URLMixin, PoolBase): 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)