changeset f2c1a362b15e in modules/currency:default
details: https://hg.tryton.org/modules/currency?cmd=changeset&node=f2c1a362b15e
description:
        Add parameter rate_decimal

        issue10266
        review365071002
diffstat:

 CHANGELOG             |   1 +
 currency.py           |   4 +++-
 doc/configuration.rst |  23 +++++++++++++++++++++++
 doc/index.rst         |   1 +
 ir.py                 |  21 +++++++++++++++++++++
 5 files changed, 49 insertions(+), 1 deletions(-)

diffs (97 lines):

diff -r 95c963bbe219 -r f2c1a362b15e CHANGELOG
--- a/CHANGELOG Sun Mar 21 16:09:13 2021 +0100
+++ b/CHANGELOG Tue Apr 13 01:47:05 2021 +0200
@@ -1,3 +1,4 @@
+* Add parameter rate_decimal
 * Add scheduled task to update rates
 
 Version 5.8.0 - 2020-11-02
diff -r 95c963bbe219 -r f2c1a362b15e currency.py
--- a/currency.py       Sun Mar 21 16:09:13 2021 +0100
+++ b/currency.py       Tue Apr 13 01:47:05 2021 +0200
@@ -25,6 +25,7 @@
 from trytond.pyson import Eval, If
 
 from .exceptions import RateError
+from .ir import rate_decimal
 
 logger = logging.getLogger(__name__)
 
@@ -40,7 +41,8 @@
         help="The 3 chars ISO currency code.")
     numeric_code = fields.Char('Numeric Code', size=3,
         help="The 3 digits ISO currency code.")
-    rate = fields.Function(fields.Numeric('Current rate', digits=(12, 6)),
+    rate = fields.Function(fields.Numeric(
+            "Current rate", digits=(rate_decimal * 2, rate_decimal)),
         'get_rate')
     rates = fields.One2Many('currency.currency.rate', 'currency', 'Rates',
         help="Add floating exchange rates for the currency.")
diff -r 95c963bbe219 -r f2c1a362b15e doc/configuration.rst
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/configuration.rst     Tue Apr 13 01:47:05 2021 +0200
@@ -0,0 +1,23 @@
+*************
+Configuration
+*************
+
+The *Currency Module* uses some settings from the ``[currency]`` section of the
+:doc:`configuration file <trytond:topics/configuration>`.
+
+.. _config-currency.rate_decimal:
+
+``rate_decimal``
+=================
+
+The ``rate_decimal`` setting defines how many decimal places are used when
+storing currencies' `Rates <model-currency.currency.rate>`.
+
+.. warning::
+
+   Once the database has been created you cannot reduce this value, doing so
+   will break your system's data integrity.
+   Also if you want to increase this value you must also manually change it in
+   the database `IR Configuration <trytond:model-ir.configuration>`.
+
+The default value is: ``6``
diff -r 95c963bbe219 -r f2c1a362b15e doc/index.rst
--- a/doc/index.rst     Sun Mar 21 16:09:13 2021 +0100
+++ b/doc/index.rst     Tue Apr 13 01:47:05 2021 +0200
@@ -12,4 +12,5 @@
 
    setup
    usage
+   configuration
    design
diff -r 95c963bbe219 -r f2c1a362b15e ir.py
--- a/ir.py     Sun Mar 21 16:09:13 2021 +0100
+++ b/ir.py     Tue Apr 13 01:47:05 2021 +0200
@@ -1,7 +1,28 @@
 # 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
 
+rate_decimal = config.getint('currency', 'rate_decimal', default=6)
+
+
+class Configuration(metaclass=PoolMeta):
+    __name__ = 'ir.configuration'
+    currency_rate_decimal = fields.Integer("Currency Rate Decimal")
+
+    @classmethod
+    def default_currency_rate_decimal(cls):
+        return rate_decimal
+
+    def check(self):
+        super().check()
+        if self.currency_rate_decimal != rate_decimal:
+            raise ValueError(
+                "The rate_decimal %s in the [currency] configuration section "
+                "is different from the value %s in 'ir.configuration'." % (
+                    rate_decimal, self.currency_rate_decimal))
+
 
 class Cron(metaclass=PoolMeta):
     __name__ = 'ir.cron'

Reply via email to