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 04cb77e49a
commit 5c64dc4f14
2 changed files with 5 additions and 5 deletions
+4 -5
View File
@@ -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
+1
View File
@@ -5,6 +5,7 @@ depends:
account_invoice_line_standalone
account_invoice_stock
ir
product
purchase
sale
stock