diff --git a/CHANGELOG b/CHANGELOG index 81a4ba59f2..abac66d190 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 --git a/account.py b/account.py index fbf7ae7a6b..8b7718b5ab 100644 --- a/account.py +++ b/account.py @@ -544,6 +544,29 @@ def AccountMixin(template=False): depends=['type']), '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 --git a/tests/test_account.py b/tests/test_account.py index 0c49d3db16..b53af1944b 100644 --- a/tests/test_account.py +++ b/tests/test_account.py @@ -1539,6 +1539,7 @@ class AccountTestCase( 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]