changeset f9284f46a6f0 in modules/product_cost_fifo:default
details:
https://hg.tryton.org/modules/product_cost_fifo?cmd=changeset;node=f9284f46a6f0
description:
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
diffstat:
move.py | 6 +++---
product.py | 12 +++++-------
2 files changed, 8 insertions(+), 10 deletions(-)
diffs (73 lines):
diff -r 1c4d3aaa3742 -r f9284f46a6f0 move.py
--- a/move.py Thu Mar 19 19:06:32 2020 +0100
+++ b/move.py Thu Apr 23 21:44:00 2020 +0200
@@ -10,6 +10,8 @@
from trytond.pool import Pool, PoolMeta
from trytond.transaction import Transaction
+from trytond.modules.product import round_price
+
class Move(metaclass=PoolMeta):
__name__ = 'stock.move'
@@ -110,9 +112,7 @@
self.unit_price = unit_price
if cost_price:
- digits = self.__class__.cost_price.digits
- cost_price = cost_price.quantize(
- Decimal(str(10.0 ** -digits[1])))
+ cost_price = round_price(cost_price)
else:
cost_price = average_cost_price
return cost_price, average_cost_price
diff -r 1c4d3aaa3742 -r f9284f46a6f0 product.py
--- a/product.py Thu Mar 19 19:06:32 2020 +0100
+++ b/product.py Thu Apr 23 21:44:00 2020 +0200
@@ -7,6 +7,8 @@
from trytond.transaction import Transaction
from trytond.pool import Pool, PoolMeta
+from trytond.modules.product import round_price
+
class Template(metaclass=PoolMeta):
__name__ = 'product.template'
@@ -94,7 +96,6 @@
Currency = pool.get('currency.currency')
Uom = pool.get('product.uom')
Revision = pool.get('product.cost_price.revision')
- digits = self.__class__.cost_price.digits
domain = [
('product', '=', self.id),
@@ -159,8 +160,7 @@
move.uom, unit_price, move.product.default_uom)
cost_price += unit_price * Decimal(str(move_qty))
if consumed_qty:
- return (cost_price / Decimal(str(consumed_qty))).quantize(
- Decimal(str(10.0 ** -digits[1])))
+ return round_price(cost_price / Decimal(str(consumed_qty)))
current_moves = []
current_out_qty = 0
@@ -192,8 +192,7 @@
/ quantity)
else:
cost_price = Decimal(0)
- current_cost_price = cost_price.quantize(
- Decimal(str(10.0 ** -digits[1])))
+ current_cost_price = round_price(cost_price)
current_moves.clear()
current_out_qty = 0
current_moves.append(move)
@@ -217,8 +216,7 @@
) / (quantity + qty)
elif qty > 0:
cost_price = unit_price
- current_cost_price = cost_price.quantize(
- Decimal(str(10.0 ** -digits[1])))
+ current_cost_price = round_price(cost_price)
else:
current_out_qty += -qty
quantity += qty