changeset 3d7294bedb52 in modules/product:default details: https://hg.tryton.org/modules/product?cmd=changeset;node=3d7294bedb52 description: Check price_decimal configuration
The price_decimal stored in ir.configuration is checked against the current configuration value. We do not allow to start serving a database for which the values are different as it may be due to a misconfiguration which can lead to data corruption. issue9324 review317381002 diffstat: CHANGELOG | 2 ++ __init__.py | 2 ++ ir.py | 24 ++++++++++++++++++++++++ product.py | 4 ++-- 4 files changed, 30 insertions(+), 2 deletions(-) diffs (82 lines): diff -r 047ca03127ba -r 3d7294bedb52 CHANGELOG --- a/CHANGELOG Tue May 19 19:23:37 2020 +0200 +++ b/CHANGELOG Thu May 28 18:22:45 2020 +0200 @@ -1,3 +1,5 @@ +* Check price_decimal configuration + Version 5.6.0 - 2020-05-04 * Bug fixes (see mercurial logs for details) * Add round_price diff -r 047ca03127ba -r 3d7294bedb52 __init__.py --- a/__init__.py Tue May 19 19:23:37 2020 +0200 +++ b/__init__.py Thu May 28 18:22:45 2020 +0200 @@ -2,6 +2,7 @@ # this repository contains the full copyright notices and license terms. from trytond.pool import Pool +from . import ir from . import uom from . import category from . import product @@ -14,6 +15,7 @@ def register(): Pool.register( + ir.Configuration, uom.UomCategory, uom.Uom, category.Category, diff -r 047ca03127ba -r 3d7294bedb52 ir.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ir.py Thu May 28 18:22:45 2020 +0200 @@ -0,0 +1,24 @@ +# 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 trytond.config import config +from trytond.model import fields +from trytond.pool import PoolMeta + +price_decimal = config.getint('product', 'price_decimal', default=4) + + +class Configuration(metaclass=PoolMeta): + __name__ = 'ir.configuration' + product_price_decimal = fields.Integer("Product Price Decimal") + + @classmethod + def default_product_price_decimal(cls): + return price_decimal + + def check(self): + super().check() + if self.product_price_decimal != price_decimal: + raise ValueError( + "The price_decimal %s in [product] configuration section " + "is different from the value %s in 'ir.configuration'." % ( + self.product_price_decimal, price_decimal)) diff -r 047ca03127ba -r 3d7294bedb52 product.py --- a/product.py Tue May 19 19:23:37 2020 +0200 +++ b/product.py Thu May 28 18:22:45 2020 +0200 @@ -18,12 +18,12 @@ from trytond.transaction import Transaction from trytond.pool import Pool from trytond import backend -from trytond.config import config from trytond.tools import lstrip_wildcard from trytond.tools.multivalue import migrate_property from trytond.modules.company.model import ( CompanyMultiValueMixin, CompanyValueMixin) from .exceptions import InvalidIdentifierCode +from .ir import price_decimal __all__ = ['price_digits', 'round_price', 'TemplateFunction'] @@ -39,7 +39,7 @@ ('average', 'Average'), ] -price_digits = (16, config.getint('product', 'price_decimal', default=4)) +price_digits = (16, price_decimal) def round_price(value, rounding=None):