changeset 406bfa727011 in modules/stock:default
details: https://hg.tryton.org/modules/stock?cmd=changeset;node=406bfa727011
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 | 8 ++------
product.py | 9 ++++-----
2 files changed, 6 insertions(+), 11 deletions(-)
diffs (79 lines):
diff -r 49d7a3c1f368 -r 406bfa727011 move.py
--- a/move.py Mon Apr 13 12:21:55 2020 +0200
+++ b/move.py Thu Apr 23 21:44:00 2020 +0200
@@ -19,7 +19,7 @@
from trytond.transaction import Transaction
from trytond.pool import Pool
-from trytond.modules.product import price_digits
+from trytond.modules.product import price_digits, round_price
from .exceptions import MoveOriginWarning
@@ -477,7 +477,6 @@
"""
pool = Pool()
Uom = pool.get('product.uom')
- Product = pool.get('product.product')
Currency = pool.get('currency.currency')
if direction == 'in':
@@ -505,10 +504,7 @@
new_cost_price = unit_price
elif direction == 'out':
new_cost_price = cost_price
-
- digits = Product.cost_price.digits
- return new_cost_price.quantize(
- Decimal(str(10.0 ** -digits[1])))
+ return round_price(new_cost_price)
@staticmethod
def _get_internal_quantity(quantity, uom, product):
diff -r 49d7a3c1f368 -r 406bfa727011 product.py
--- a/product.py Mon Apr 13 12:21:55 2020 +0200
+++ b/product.py Thu Apr 23 21:44:00 2020 +0200
@@ -23,6 +23,8 @@
from trytond.pool import Pool, PoolMeta
from trytond.tools import grouped_slice
+from trytond.modules.product import round_price
+
from .exceptions import ProductCostPriceError
from .move import StockMixin
@@ -226,7 +228,6 @@
def recompute_cost_price(cls, products, start=None):
pool = Pool()
Move = pool.get('stock.move')
- digits = cls.cost_price.digits
costs = defaultdict(list)
for product in products:
if product.type == 'service':
@@ -234,7 +235,7 @@
cost = getattr(
product, 'recompute_cost_price_%s' %
product.cost_price_method)(start)
- cost = cost.quantize(Decimal(str(10.0 ** -digits[1])))
+ cost = round_price(cost)
costs[cost].append(product)
updated = []
@@ -298,7 +299,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),
@@ -371,8 +371,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)
quantity += qty
Move.write([