From 120e315becb9e9aec624f43917643156463e29dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 8 Oct 2024 16:34:37 +0200 Subject: [PATCH] Set Decimal precision of default context from environment variable This is placed in the trytond __init__.py because the default context must be set prior to any start of thread. And thus it can only be set via environment. Closes #13572 --- trytond/CHANGELOG | 1 + trytond/trytond/__init__.py | 4 ++++ trytond/trytond/commandline.py | 3 +++ 3 files changed, 8 insertions(+) diff --git a/trytond/CHANGELOG b/trytond/CHANGELOG index b4223c0d4c..425ac608e1 100644 --- a/trytond/CHANGELOG +++ b/trytond/CHANGELOG @@ -1,3 +1,4 @@ +* Set Decimal precision of default context from TRYTOND_DECIMAL_PREC * Replace usage of docstring of Model by __string__ attribute * Rename ir.model.field 'field_description' into 'string' * Replace docstring of models by __string__ diff --git a/trytond/trytond/__init__.py b/trytond/trytond/__init__.py index 2153bfeb82..71e2ef3dee 100644 --- a/trytond/trytond/__init__.py +++ b/trytond/trytond/__init__.py @@ -1,5 +1,7 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. + +import decimal import os import time import warnings @@ -40,3 +42,5 @@ def default_user_agent(name="Tryton"): if requests_utils: requests_utils.default_user_agent = default_user_agent + +decimal.DefaultContext.prec = int(os.environ.get('TRYTOND_DECIMAL_PREC', 28)) diff --git a/trytond/trytond/commandline.py b/trytond/trytond/commandline.py index f273b9fbbe..99b4d556a5 100644 --- a/trytond/trytond/commandline.py +++ b/trytond/trytond/commandline.py @@ -65,6 +65,9 @@ def get_parser(): parser.add_argument( "--logconf", dest="logconf", default=logging_config, metavar='FILE', help="set logging configuration file (ConfigParser format)") + parser.epilog = ( + "The default Decimal precision can be specified in the " + "TRYTOND_DECIMAL_PREC environment variable.") return parser