changeset 812cb3f65405 in modules/account:default
details: https://hg.tryton.org/modules/account?cmd=changeset&node=812cb3f65405
description:
Prevent changing the company currency with account moves
issue10259
review361591005
diffstat:
__init__.py | 2 ++
company.py | 30 ++++++++++++++++++++++++++++++
message.xml | 3 +++
3 files changed, 35 insertions(+), 0 deletions(-)
diffs (65 lines):
diff -r ac039369474a -r 812cb3f65405 __init__.py
--- a/__init__.py Mon Apr 12 20:48:57 2021 +0200
+++ b/__init__.py Sun Apr 18 17:43:43 2021 +0200
@@ -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 @@
Pool.register(
fiscalyear.FiscalYear,
fiscalyear.BalanceNonDeferralStart,
+ company.Company,
account.TypeTemplate,
account.Type,
account.AccountTemplate,
diff -r ac039369474a -r 812cb3f65405 company.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/company.py Sun Apr 18 17:43:43 2021 +0200
@@ -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 -r ac039369474a -r 812cb3f65405 message.xml
--- a/message.xml Mon Apr 12 20:48:57 2021 +0200
+++ b/message.xml Sun Apr 18 17:43:43 2021 +0200
@@ -193,5 +193,8 @@
<record model="ir.message" id="msg_cancel_line_delegated">
<field name="text">The moves "%(moves)s" contain grouped lines,
cancelling them will ungroup the lines.</field>
</record>
+ <record model="ir.message" id="msg_company_change_currency">
+ <field name="text">You cannot change the currency of a company
which is associated with account moves.</field>
+ </record>
</data>
</tryton>