changeset 0fbbe4277280 in modules/account:6.0
details: https://hg.tryton.org/modules/account?cmd=changeset&node=0fbbe4277280
description:
Update parent of type, account, tax and tax code from template
issue11037
review387461002
(grafted from ed7b63a4fdea99ee3c0cf470596b43c6413c07dd)
diffstat:
account.py | 27 +++++++++++++++++++++++++++
tax.py | 45 +++++++++++++++++++++++++++++++++++++++++++++
tests/test_account.py | 16 ++++++++++++++++
3 files changed, 88 insertions(+), 0 deletions(-)
diffs (153 lines):
diff -r c73204d8efed -r 0fbbe4277280 account.py
--- a/account.py Thu Dec 16 22:35:46 2021 +0100
+++ b/account.py Thu Dec 16 22:37:53 2021 +0100
@@ -401,6 +401,26 @@
if values:
self.write(*values)
+ # Update parent
+ to_save = []
+ childs = [self]
+ while childs:
+ for child in childs:
+ if child.template:
+ if not child.template_override:
+ if child.template.parent:
+ parent = template2type[
+ child.template.parent.id]
+ else:
+ parent = None
+ old_parent = (
+ child.parent.id if child.parent else None)
+ if parent != old_parent:
+ child.parent = parent
+ to_save.append(child)
+ childs = sum((c.childs for c in childs), ())
+ self.__class__.save(to_save)
+
class OpenType(Wizard):
'Open Type'
@@ -1235,6 +1255,13 @@
for x in child.template.taxes
if x.id in template2tax])]
break
+ if child.template.parent:
+ parent = template2account[child.template.parent.id]
+ else:
+ parent = None
+ old_parent = child.parent.id if child.parent else None
+ if parent != old_parent:
+ values['parent'] = parent
if child.template.replaced_by:
replaced_by = template2account[
child.template.replaced_by.id]
diff -r c73204d8efed -r 0fbbe4277280 tax.py
--- a/tax.py Thu Dec 16 22:35:46 2021 +0100
+++ b/tax.py Thu Dec 16 22:37:53 2021 +0100
@@ -279,6 +279,29 @@
if values:
cls.write(*values)
+ # Update parent
+ to_save = []
+ childs = cls.search([
+ ('company', '=', company_id),
+ ('parent', '=', None),
+ ])
+ while childs:
+ for child in childs:
+ if child.template:
+ if not child.template_override:
+ if child.template.parent:
+ parent = template2tax_code[
+ child.template.parent.id]
+ else:
+ parent = None
+ old_parent = (
+ child.parent.id if child.parent else None)
+ if parent != old_parent:
+ child.parent = parent
+ to_save.append(child)
+ childs = sum((c.childs for c in childs), ())
+ cls.save(to_save)
+
class TaxCodeLineTemplate(ModelSQL, ModelView):
"Tax Code Line Template"
@@ -1094,6 +1117,28 @@
if values:
cls.write(*values)
+ # Update parent
+ to_save = []
+ childs = cls.search([
+ ('company', '=', company_id),
+ ('parent', '=', None),
+ ])
+ while childs:
+ for child in childs:
+ if child.template:
+ if not child.template_override:
+ if child.template.parent:
+ parent = template2tax[child.template.parent.id]
+ else:
+ parent = None
+ old_parent = (
+ child.parent.id if child.parent else None)
+ if parent != old_parent:
+ child.parent = parent
+ to_save.append(child)
+ childs = sum((c.childs for c in childs), ())
+ cls.save(to_save)
+
class _TaxKey(dict):
diff -r c73204d8efed -r 0fbbe4277280 tests/test_account.py
--- a/tests/test_account.py Thu Dec 16 22:35:46 2021 +0100
+++ b/tests/test_account.py Thu Dec 16 22:37:53 2021 +0100
@@ -1414,6 +1414,11 @@
self.assertEqual(type_.name, type_.template.name)
self.assertEqual(
type_.statement, type_.template.statement)
+ if type_.template.parent:
+ self.assertEqual(
+ type_.parent.name, type_.template.parent.name)
+ else:
+ self.assertEqual(type_.parent, None)
for account in Account.search([]):
self.assertEqual(account.name, account.template.name)
@@ -1431,6 +1436,11 @@
self.assertEqual(
set(t.template for t in account.taxes),
set(t for t in account.template.taxes))
+ if account.template.parent:
+ self.assertEqual(
+ account.parent.name, account.template.parent.name)
+ else:
+ self.assertEqual(account.parent, None)
for tax_code in TaxCode.search([]):
self.assertEqual(tax_code.name, tax_code.template.name)
@@ -1481,6 +1491,11 @@
new_type.parent = root_type
new_type.statement = 'balance'
new_type.save()
+ updated_tax_type, = TypeTemplate.search([
+ ('name', '=', "Tax"),
+ ])
+ updated_tax_type.parent = updated_tax_type.parent.parent
+ updated_tax_type.save()
new_account = AccountTemplate()
new_account.name = 'New Account'
new_account.parent = chart
@@ -1494,6 +1509,7 @@
'account', 'account_template_revenue_en'))
updated_account.code = 'REV'
updated_account.name = 'Updated Account'
+ updated_account.parent = new_account
updated_account.reconcile = True
updated_account.end_date = datetime.date.today()
updated_account.taxes = [updated_tax]