changeset c39ad0bef61e in modules/account:default
details: https://hg.tryton.org/modules/account?cmd=changeset&node=c39ad0bef61e
description:
        Enforce same type for children account as their parent

        issue11143
        review384081002
diffstat:

 CHANGELOG             |   1 +
 account.py            |  23 +++++++++++++++++++++++
 tests/test_account.py |   1 +
 3 files changed, 25 insertions(+), 0 deletions(-)

diffs (52 lines):

diff -r 0ab649829988 -r c39ad0bef61e CHANGELOG
--- a/CHANGELOG Thu Feb 10 13:35:19 2022 +0100
+++ b/CHANGELOG Sun Feb 13 01:33:15 2022 +0100
@@ -1,3 +1,4 @@
+* Enforce same type for children account as their parent
 * Show debit / credit columns in ledgers when they contain lines
 * Count number of lines in Account and General Ledger
 * Handle errors in move template expression
diff -r 0ab649829988 -r c39ad0bef61e account.py
--- a/account.py        Thu Feb 10 13:35:19 2022 +0100
+++ b/account.py        Sun Feb 13 01:33:15 2022 +0100
@@ -545,6 +545,29 @@
             'on_change_with_deferral', searcher='search_deferral')
 
         @classmethod
+        def __setup__(cls):
+            super().__setup__()
+
+            if not cls.childs.domain:
+                cls.childs.domain = []
+            for type_ in ['type', 'debit_type']:
+                field = getattr(cls, type_)
+                field.domain = [
+                    If(Eval('parent')
+                        & Eval('_parent_parent.%s' % type_)
+                        & Eval('_parent_parent.parent'),
+                        ('id', '=', Eval('_parent_parent.%s' % type_)),
+                        ()),
+                    ]
+                field.depends.append('parent')
+
+                cls.childs.domain.append(
+                    If(Eval(type_),
+                        (type_, '=', Eval(type_)),
+                        ()))
+                cls.childs.depends.append(type_)
+
+        @classmethod
         def default_closed(cls):
             return False
 
diff -r 0ab649829988 -r c39ad0bef61e tests/test_account.py
--- a/tests/test_account.py     Thu Feb 10 13:35:19 2022 +0100
+++ b/tests/test_account.py     Sun Feb 13 01:33:15 2022 +0100
@@ -1539,6 +1539,7 @@
             updated_account.code = 'REV'
             updated_account.name = 'Updated Account'
             updated_account.parent = new_account
+            updated_account.type = new_account.type
             updated_account.reconcile = True
             updated_account.end_date = datetime.date.today()
             updated_account.taxes = [updated_tax]

Reply via email to