Sergi Almacellas Abellana pushed to branch branch/default at Tryton / Tryton


Commits:
46a73ccc by Sergi Almacellas Abellana at 2023-01-09T14:34:21+01:00
Update parent and replaced_by when template has no taxes

Closes #11891
- - - - -


2 changed files:

- modules/account/account.py
- modules/account/tests/test_module.py


Changes:

=====================================
modules/account/account.py
=====================================
@@ -1362,9 +1362,7 @@
             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]
@@ -1367,14 +1365,14 @@
                 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:


=====================================
modules/account/tests/test_module.py
=====================================
@@ -1608,6 +1608,12 @@
                         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 @@
             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'



View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/commit/46a73ccc6b68e222baa5e60218eee5ef3b6f0637

-- 
View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/commit/46a73ccc6b68e222baa5e60218eee5ef3b6f0637
You're receiving this email because of your account on foss.heptapod.net.


Reply via email to