diff --git a/modules/account/account.py b/modules/account/account.py index 484c116034..3f2436a10b 100644 --- a/modules/account/account.py +++ b/modules/account/account.py @@ -1362,19 +1362,17 @@ class Account( for child in childs: if not child.template: continue - if not child.template.taxes: - continue values = {} tax_ids = [template2tax[x.id] for x in child.template.taxes if x.id in template2tax] old_tax_ids = [x.id for x in child.taxes] - for tax_id in tax_ids: - if tax_id not in old_tax_ids: - values['taxes'] = [ - ('add', [template2tax[x.id] - for x in child.template.taxes - if x.id in template2tax])] - break + taxes_to_add = [x for x in tax_ids if x not in old_tax_ids] + taxes_to_remove = [x for x in old_tax_ids if x not in tax_ids] + if taxes_to_add or taxes_to_remove: + values['taxes'] = [ + ('add', taxes_to_add), + ('remove', taxes_to_remove), + ] if child.template.parent: parent = template2account[child.template.parent.id] else: diff --git a/modules/account/tests/test_module.py b/modules/account/tests/test_module.py index ad8a645dd1..2a101b9e85 100644 --- a/modules/account/tests/test_module.py +++ b/modules/account/tests/test_module.py @@ -1608,6 +1608,12 @@ class AccountTestCase( account.parent.name, account.template.parent.name) else: self.assertEqual(account.parent, None) + if account.template.replaced_by: + self.assertEqual( + account.replaced_by.name, + account.template.replaced_by.name) + else: + self.assertEqual(account.replaced_by, None) for tax_code in TaxCode.search([]): self.assertEqual(tax_code.name, tax_code.template.name) @@ -1685,6 +1691,7 @@ class AccountTestCase( inactive_account = AccountTemplate(ModelData.get_id( 'account', 'account_template_expense_en')) inactive_account.end_date = datetime.date.min + inactive_account.replaced_by = new_account inactive_account.save() new_tax = TaxTemplate() new_tax.name = new_tax.description = '10% VAT'