From 948404178b2949786c30ddecc68075d34158c244 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 --- product.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/product.py b/product.py index b7765162d3..c4d3ca23fe 100644 --- a/product.py +++ b/product.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 sql import Column, Literal, Window from sql.aggregate import Max from sql.conditionals import Coalesce @@ -11,6 +9,8 @@ from trytond.model import ModelView, ModelSQL, fields from trytond.pool import Pool, PoolMeta from trytond.transaction import Transaction +from trytond.modules.product import round_price + def convert_from(table, tables): right, condition = tables[None] @@ -48,8 +48,7 @@ class Product(metaclass=PoolMeta): ], limit=1, order=[('date', 'DESC')]) if records: record, = records - return record.cost_price.quantize( - Decimal(str(10. ** -self.__class__.cost_price.digits[1]))) + return round_price(record.cost_price) class CostPrice(metaclass=PoolMeta):