From 680344c92b2adbce43fb12e9110e91ab398cfac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 20 Jan 2026 09:19:12 +0100 Subject: [PATCH] Format float and computed Decimal using fixed-point notation This avoid the usage of scientific notation. For float we must convert them to Decimal to get a precision large enough to show all coefficient digits. For computed Decimal (which are thus not rounded) we must normalized them first to avoid trailing 0. Closes #14522 --- modules/edocument_ubl/edocument.py | 5 ++++- modules/edocument_ubl/template/2/CreditNote.xml | 8 ++++---- modules/edocument_ubl/template/2/Invoice.xml | 8 ++++---- modules/edocument_uncefact/edocument.py | 5 ++++- .../template/16B-CII/CrossIndustryInvoice.xml | 4 ++-- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/modules/edocument_ubl/edocument.py b/modules/edocument_ubl/edocument.py index a5c073b8d1..b39003c1a7 100644 --- a/modules/edocument_ubl/edocument.py +++ b/modules/edocument_ubl/edocument.py @@ -86,7 +86,10 @@ class Invoice(Model): tmpl = self._get_template(template) if not tmpl: raise NotImplementedError - return (tmpl.generate(this=self, specification=specification) + return (tmpl.generate( + this=self, + specification=specification, + Decimal=Decimal) .filter(remove_comment) .render() .encode('utf-8')) diff --git a/modules/edocument_ubl/template/2/CreditNote.xml b/modules/edocument_ubl/template/2/CreditNote.xml index 39aebfa02f..e26639b73a 100644 --- a/modules/edocument_ubl/template/2/CreditNote.xml +++ b/modules/edocument_ubl/template/2/CreditNote.xml @@ -70,10 +70,10 @@ this repository contains the full copyright notices and license terms. --> ${-line.base} ${-line.amount} - ${line.tax.rate * 100} + ${format((line.tax.rate * 100).normalize(), 'f')} ${line.tax.unece_category_code} - ${line.tax.rate * 100} + ${format((line.tax.rate * 100).normalize(), 'f')} ${line.tax.unece_code} @@ -91,7 +91,7 @@ this repository contains the full copyright notices and license terms. --> ${line_id} - ${-line.quantity} + ${format(-Decimal(str(line.quantity)), 'f')} ${-line.amount} ${line.description} @@ -111,7 +111,7 @@ this repository contains the full copyright notices and license terms. --> ${tax.unece_category_code} - ${tax.rate * 100} + ${format((tax.rate * 100).normalize(), 'f')} ${tax.unece_code} diff --git a/modules/edocument_ubl/template/2/Invoice.xml b/modules/edocument_ubl/template/2/Invoice.xml index e3bd1834b9..260328241e 100644 --- a/modules/edocument_ubl/template/2/Invoice.xml +++ b/modules/edocument_ubl/template/2/Invoice.xml @@ -70,10 +70,10 @@ this repository contains the full copyright notices and license terms. --> ${line.base} ${line.amount} - ${line.tax.rate * 100} + ${format((line.tax.rate * 100).normalize(), 'f')} ${line.tax.unece_category_code} - ${line.tax.rate * 100} + ${format((line.tax.rate * 100).normalize(), 'f')} ${line.tax.unece_code} @@ -91,7 +91,7 @@ this repository contains the full copyright notices and license terms. --> ${line_id} - ${line.quantity} + ${format(Decimal(str(line.quantity)), 'f')} ${line.amount} ${line.description} @@ -111,7 +111,7 @@ this repository contains the full copyright notices and license terms. --> ${tax.unece_category_code} - ${tax.rate * 100} + ${format((tax.rate * 100).normalize(), 'f')} ${tax.unece_code} diff --git a/modules/edocument_uncefact/edocument.py b/modules/edocument_uncefact/edocument.py index c756071a76..6bd27bf427 100644 --- a/modules/edocument_uncefact/edocument.py +++ b/modules/edocument_uncefact/edocument.py @@ -2,6 +2,7 @@ # this repository contains the full copyright notices and license terms. import functools import os +from decimal import Decimal import genshi import genshi.template @@ -78,7 +79,9 @@ class Invoice(Model): tmpl = self._get_template(template) if not tmpl: raise NotImplementedError - return (tmpl.generate(this=self) + return (tmpl.generate( + this=self, + Decimal=Decimal) .filter(remove_comment) .render() .encode('utf-8')) diff --git a/modules/edocument_uncefact/template/16B-CII/CrossIndustryInvoice.xml b/modules/edocument_uncefact/template/16B-CII/CrossIndustryInvoice.xml index 5ca38b5433..ead5453aa4 100644 --- a/modules/edocument_uncefact/template/16B-CII/CrossIndustryInvoice.xml +++ b/modules/edocument_uncefact/template/16B-CII/CrossIndustryInvoice.xml @@ -48,7 +48,7 @@ this repository contains the full copyright notices and license terms. --> ${tax.legal_notice} ${base * this.type_sign} ${tax.unece_category_code} - ${tax.rate * 100} + ${format((tax.rate * 100).normalize(), 'f')} @@ -76,7 +76,7 @@ this repository contains the full copyright notices and license terms. --> - ${line.quantity * this.type_sign} + ${format(Decimal(str(line.quantity * this.type_sign)), 'f')}