changeset d48a794599b1 in modules/account:5.0
details: https://hg.tryton.org/modules/account?cmd=changeset;node=d48a794599b1
description:
        Do not recreate models that have template override is True

        The dictionary template2*** must always be filled even if template 
override is
        True because create_*** calls will use this dictionary to not recreate 
the
        records.

        issue7938
        review54551002
        (grafted from 10df9d79188c3ae7010ae8bd0be6b9bc4d15aa09)
diffstat:

 account.py |  38 ++++++++++++++-------------
 tax.py     |  83 ++++++++++++++++++++++++++++++++-----------------------------
 2 files changed, 63 insertions(+), 58 deletions(-)

diffs (162 lines):

diff -r 0ea9922235b0 -r d48a794599b1 account.py
--- a/account.py        Tue Feb 19 21:51:57 2019 +0100
+++ b/account.py        Fri Mar 08 18:48:09 2019 +0100
@@ -276,11 +276,12 @@
         childs = [self]
         while childs:
             for child in childs:
-                if child.template and not child.template_override:
-                    vals = child.template._get_type_value(type=child)
-                    if vals:
-                        values.append([child])
-                        values.append(vals)
+                if child.template:
+                    if not child.template_override:
+                        vals = child.template._get_type_value(type=child)
+                        if vals:
+                            values.append([child])
+                            values.append(vals)
                     template2type[child.template.id] = child.id
             childs = sum((c.childs for c in childs), ())
         if values:
@@ -1032,19 +1033,20 @@
         childs = [self]
         while childs:
             for child in childs:
-                if child.template and not child.template_override:
-                    vals = child.template._get_account_value(account=child)
-                    current_type = child.type.id if child.type else None
-                    if child.template.type:
-                        template_type = template2type.get(
-                            child.template.type.id)
-                    else:
-                        template_type = None
-                    if current_type != template_type:
-                        vals['type'] = template_type
-                    if vals:
-                        values.append([child])
-                        values.append(vals)
+                if child.template:
+                    if not child.template_override:
+                        vals = child.template._get_account_value(account=child)
+                        current_type = child.type.id if child.type else None
+                        if child.template.type:
+                            template_type = template2type.get(
+                                child.template.type.id)
+                        else:
+                            template_type = None
+                        if current_type != template_type:
+                            vals['type'] = template_type
+                        if vals:
+                            values.append([child])
+                            values.append(vals)
                     template2account[child.template.id] = child.id
             childs = sum((c.childs for c in childs), ())
         if values:
diff -r 0ea9922235b0 -r d48a794599b1 tax.py
--- a/tax.py    Tue Feb 19 21:51:57 2019 +0100
+++ b/tax.py    Fri Mar 08 18:48:09 2019 +0100
@@ -264,11 +264,12 @@
                 ])
         while childs:
             for child in childs:
-                if child.template and not child.template_override:
-                    vals = child.template._get_tax_code_value(code=child)
-                    if vals:
-                        values.append([child])
-                        values.append(vals)
+                if child.template:
+                    if not child.template_override:
+                        vals = child.template._get_tax_code_value(code=child)
+                        if vals:
+                            values.append([child])
+                            values.append(vals)
                     template2tax_code[child.template.id] = child.id
             childs = sum((c.childs for c in childs), ())
         if values:
@@ -399,16 +400,17 @@
 
         values = []
         for line in cls.search([('tax.company', '=', company_id)]):
-            if line.template and not line.template_override:
-                template = line.template
-                value = template._get_tax_code_line_value(line=line)
-                if line.code.id != template2tax_code.get(template.code.id):
-                    value['code'] = template2tax_code.get(template.code.id)
-                if line.tax.id != template2tax.get(template.tax.id):
-                    value['tax'] = template2tax.get(template.tax.id)
-                if value:
-                    values.append([line])
-                    values.append(value)
+            if line.template:
+                if not line.template_override:
+                    template = line.template
+                    value = template._get_tax_code_line_value(line=line)
+                    if line.code.id != template2tax_code.get(template.code.id):
+                        value['code'] = template2tax_code.get(template.code.id)
+                    if line.tax.id != template2tax.get(template.tax.id):
+                        value['tax'] = template2tax.get(template.tax.id)
+                    if value:
+                        values.append([line])
+                        values.append(value)
                 template2tax_code_line[line.template.id] = line.id
         if values:
             cls.write(*values)
@@ -1002,31 +1004,32 @@
                 ])
         while childs:
             for child in childs:
-                if child.template and not child.template_override:
-                    vals = child.template._get_tax_value(tax=child)
-                    invoice_account_id = (child.invoice_account.id
-                        if child.invoice_account else None)
-                    if (child.template.invoice_account and
-                            invoice_account_id != template2account.get(
-                                    child.template.invoice_account.id)):
-                        vals['invoice_account'] = template2account.get(
-                            child.template.invoice_account.id)
-                    elif (not child.template.invoice_account
-                            and child.invoice_account):
-                        vals['invoice_account'] = None
-                    credit_note_account_id = (child.credit_note_account.id
-                        if child.credit_note_account else None)
-                    if (child.template.credit_note_account and
-                            credit_note_account_id != template2account.get(
-                                child.template.credit_note_account.id)):
-                        vals['credit_note_account'] = template2account.get(
-                            child.template.credit_note_account.id)
-                    elif (not child.template.credit_note_account
-                            and child.credit_note_account):
-                        vals['credit_note_account'] = None
-                    if vals:
-                        values.append([child])
-                        values.append(vals)
+                if child.template:
+                    if not child.template_override:
+                        vals = child.template._get_tax_value(tax=child)
+                        invoice_account_id = (child.invoice_account.id
+                            if child.invoice_account else None)
+                        if (child.template.invoice_account and
+                                invoice_account_id != template2account.get(
+                                        child.template.invoice_account.id)):
+                            vals['invoice_account'] = template2account.get(
+                                child.template.invoice_account.id)
+                        elif (not child.template.invoice_account
+                                and child.invoice_account):
+                            vals['invoice_account'] = None
+                        credit_note_account_id = (child.credit_note_account.id
+                            if child.credit_note_account else None)
+                        if (child.template.credit_note_account and
+                                credit_note_account_id != template2account.get(
+                                    child.template.credit_note_account.id)):
+                            vals['credit_note_account'] = template2account.get(
+                                child.template.credit_note_account.id)
+                        elif (not child.template.credit_note_account
+                                and child.credit_note_account):
+                            vals['credit_note_account'] = None
+                        if vals:
+                            values.append([child])
+                            values.append(vals)
                     template2tax[child.template.id] = child.id
             childs = sum((c.childs for c in childs), ())
         if values:

Reply via email to