From 993aa8a71a35f06a99bd2049cb3d98a8c9fea133 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 --- purchase.py | 7 ++----- stock.py | 4 ++-- tryton.cfg | 1 + 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/purchase.py b/purchase.py index 83d05f8ca4..470793bea8 100644 --- a/purchase.py +++ b/purchase.py @@ -1,7 +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 trytond import backend from trytond.i18n import gettext from trytond.model import ModelSQL, ValueMixin, fields @@ -11,6 +9,7 @@ from trytond.pool import Pool, PoolMeta from trytond.transaction import Transaction from trytond.tools.multivalue import migrate_property +from trytond.modules.product import round_price from trytond.modules.purchase.purchase import ( get_shipments_returns, search_shipments_returns) @@ -181,11 +180,9 @@ class Line(metaclass=PoolMeta): Currency = pool.get('currency.currency') move = super().get_move(move_type) if move and self.purchase.customer: - digits = move.__class__.cost_price.digits cost_price = Currency.compute( move.currency, move.unit_price, move.company.currency) - move.cost_price = cost_price.quantize( - Decimal(str(10.0 ** -digits[1]))) + move.cost_price = round_price(cost_price) return move diff --git a/stock.py b/stock.py index 53dae3b76a..891753a890 100644 --- a/stock.py +++ b/stock.py @@ -17,6 +17,7 @@ from trytond.transaction import Transaction from trytond.tools import grouped_slice, cursor_dict from trytond.modules.sale.stock import process_sale +from trytond.modules.product import round_price from trytond.modules.purchase.stock import process_purchase @@ -402,7 +403,6 @@ class ShipmentDrop(Workflow, ModelSQL, ModelView): Move = pool.get('stock.move') to_save = [] - cost_exp = Decimal(str(10.0 ** -Move.cost_price.digits[1])) for shipment in shipments: product_qty = defaultdict(int) product_cost = defaultdict(int) @@ -454,7 +454,7 @@ class ShipmentDrop(Workflow, ModelSQL, ModelView): for product, cost in product_cost.items(): qty = Decimal(str(s_product_qty[product])) if qty: - product_cost[product] = (cost / qty).quantize(cost_exp) + product_cost[product] = round_price(cost / qty) for c_move in list(shipment.customer_moves) + to_save: if c_move.id is not None and c_move.state == 'cancel': continue diff --git a/tryton.cfg b/tryton.cfg index 84b3303374..8c9b11afe0 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -3,6 +3,7 @@ version=5.5.0 depends: company ir + product purchase purchase_request sale