From 5c64dc4f149ea599ea570e8ed9d0d887bda67ba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 23 Apr 2020 21:44:00 +0200 Subject: [PATCH] Add round_price We add a common method to round prices that are stored using the price digits. It is useless to use the digits from the field because it can not be changed in any other way than by configuration. issue9146 review299521002 --- stock.py | 9 ++++----- tryton.cfg | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/stock.py b/stock.py index adf9223666..b3006c25b6 100644 --- a/stock.py +++ b/stock.py @@ -1,6 +1,5 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from decimal import Decimal from functools import wraps from trytond.model import ModelView, Workflow, fields @@ -8,6 +7,8 @@ from trytond.transaction import Transaction from trytond.pool import PoolMeta, Pool from trytond.pyson import Eval +from trytond.modules.product import round_price + class Location(metaclass=PoolMeta): __name__ = 'stock.location' @@ -211,8 +212,7 @@ class Move(metaclass=PoolMeta): taxes=[t.id for t in line.taxes]): line.unit_price = Product.get_purchase_price( [line.product], line.quantity)[line.product.id] - line.unit_price = line.unit_price.quantize( - Decimal(1) / 10 ** line.__class__.unit_price.digits[1]) + line.unit_price = round_price(line.unit_price) return line def _get_customer_invoice_line_consignment(self): @@ -256,8 +256,7 @@ class Move(metaclass=PoolMeta): taxes=[t.id for t in line.taxes]): line.unit_price = Product.get_sale_price( [line.product], line.quantity)[line.product.id] - line.unit_price = line.unit_price.quantize( - Decimal(1) / 10 ** line.__class__.unit_price.digits[1]) + line.unit_price = round_price(line.unit_price) return line @classmethod diff --git a/tryton.cfg b/tryton.cfg index 0a80316d03..d11217837c 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -5,6 +5,7 @@ depends: account_invoice_line_standalone account_invoice_stock ir + product purchase sale stock