round unit_price of invoice-line by price_digits

This commit is contained in:
Frederik Jaeckel 2025-01-28 12:50:55 +01:00
parent ceb2a72fed
commit 02221601e7
2 changed files with 18 additions and 2 deletions

View file

@ -4,12 +4,13 @@
# full copyright notices and license terms. # full copyright notices and license terms.
from decimal import Decimal from decimal import Decimal, ROUND_HALF_EVEN
import html import html
from trytond.exceptions import UserError from trytond.exceptions import UserError
from trytond.i18n import gettext from trytond.i18n import gettext
from trytond.tools import cached_property from trytond.tools import cached_property
from trytond.pool import Pool from trytond.pool import Pool
from trytond.modules.product import price_digits
class EdocumentMixin(object): class EdocumentMixin(object):
@ -183,6 +184,21 @@ class EdocumentMixin(object):
taxname=tax.rec_name)) taxname=tax.rec_name))
return unece_category_code return unece_category_code
def round_unitprice(self, value):
""" round value by digits in unit_price of account.invoice.line
Args:
value (Decimal): unit-price
Returns:
Decimal: rounded value
"""
if isinstance(value, Decimal):
return value.quantize(
Decimal(str(1/10 ** price_digits[1])),
ROUND_HALF_EVEN)
return value
def quote_text(self, text): def quote_text(self, text):
""" replace critical chars """ replace critical chars
""" """

View file

@ -76,7 +76,7 @@ this repository contains the full copyright notices and license terms. -->
</ram:SpecifiedTradeProduct> </ram:SpecifiedTradeProduct>
<ram:SpecifiedLineTradeAgreement> <ram:SpecifiedLineTradeAgreement>
<ram:NetPriceProductTradePrice> <ram:NetPriceProductTradePrice>
<ram:ChargeAmount py:attrs="{'currencyID': this.invoice.currency.code}">${this.invoice.currency.round(line.unit_price)}</ram:ChargeAmount> <ram:ChargeAmount py:attrs="{'currencyID': this.invoice.currency.code}">${this.round_unitprice(line.unit_price)}</ram:ChargeAmount>
</ram:NetPriceProductTradePrice> </ram:NetPriceProductTradePrice>
</ram:SpecifiedLineTradeAgreement> </ram:SpecifiedLineTradeAgreement>
<ram:SpecifiedLineTradeDelivery> <ram:SpecifiedLineTradeDelivery>