From ff98211f2c9d76388ae6b537ec6949a24e9adf83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 18 Apr 2021 17:43:43 +0200 Subject: [PATCH] Prevent changing the company currency with account moves issue10259 review361591005 --- __init__.py | 2 ++ company.py | 30 ++++++++++++++++++++++++++++++ message.xml | 3 +++ 3 files changed, 35 insertions(+) create mode 100644 company.py diff --git a/__init__.py b/__init__.py index fe74ff82c5..dbf8cf5bc5 100644 --- a/__init__.py +++ b/__init__.py @@ -4,6 +4,7 @@ from trytond.pool import Pool from . import account from . import configuration +from . import company from . import fiscalyear from . import journal from . import move @@ -17,6 +18,7 @@ def register(): Pool.register( fiscalyear.FiscalYear, fiscalyear.BalanceNonDeferralStart, + company.Company, account.TypeTemplate, account.Type, account.AccountTemplate, diff --git a/company.py b/company.py new file mode 100644 index 0000000000..cd85f1aeef --- /dev/null +++ b/company.py @@ -0,0 +1,30 @@ +# 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.i18n import gettext +from trytond.model.exceptions import AccessError +from trytond.pool import PoolMeta, Pool +from trytond.transaction import Transaction + + +class Company(metaclass=PoolMeta): + __name__ = 'company.company' + + @classmethod + def write(cls, *args): + pool = Pool() + Move = pool.get('account.move') + transaction = Transaction() + if (transaction.user + and transaction.context.get('_check_access')): + actions = iter(args) + for companies, values in zip(actions, actions): + if 'currency' in values: + moves = Move.search([ + ('company', 'in', [c.id for c in companies]), + ], + limit=1, order=[]) + if moves: + raise AccessError(gettext( + 'account.msg_company_change_currency')) + + super().write(*args) diff --git a/message.xml b/message.xml index 43bbe4eafb..bb895304f5 100644 --- a/message.xml +++ b/message.xml @@ -193,5 +193,8 @@ You may need to cancel its move "%(move)s". The moves "%(moves)s" contain grouped lines, cancelling them will ungroup the lines. + + You cannot change the currency of a company which is associated with account moves. +