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
This commit is contained in:
Cédric Krier
2020-04-23 21:44:00 +02:00
parent 220ceb03ed
commit 993aa8a71a
3 changed files with 5 additions and 7 deletions
+2 -5
View File
@@ -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
+2 -2
View File
@@ -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
+1
View File
@@ -3,6 +3,7 @@ version=5.5.0
depends:
company
ir
product
purchase
purchase_request
sale