Update parent and replaced_by when template has no taxes

Closes #11891
This commit is contained in:
Sergi Almacellas Abellana
2023-01-09 14:34:21 +01:00
parent 9d402b3807
commit 0287507f85
2 changed files with 14 additions and 9 deletions
+7 -9
View File
@@ -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:
+7
View File
@@ -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'