From 1567a68edda09f40307226cd314f15da0d384806 Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Sat, 24 Mar 2018 12:07:26 +0100 Subject: [PATCH] Apply party tax rules on on_change_account without invoice Also call tax rule with empty tax to apply aditional taxes issue7203 review36001003 --- invoice.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/invoice.py b/invoice.py index 3626557536..a0a85b7d0f 100644 --- a/invoice.py +++ b/invoice.py @@ -1857,15 +1857,23 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin): return self.product.default_uom_category.id @fields.depends('account', 'product', '_parent_invoice.party', - '_parent_invoice.type') + '_parent_invoice.type', 'party', 'invoice', 'invoice_type') def on_change_account(self): if self.product: return taxes = [] - if (self.invoice and self.invoice.party - and self.invoice.type): + party = None + if self.invoice and self.invoice.party: party = self.invoice.party - if self.invoice.type == 'in': + elif self.party: + party = self.party + + if self.invoice and self.invoice.type: + type_ = self.invoice.type + else: + type_ = self.invoice_type + if party and type_: + if type_ == 'in': tax_rule = party.supplier_tax_rule else: tax_rule = party.customer_tax_rule @@ -1881,6 +1889,10 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin): taxes.extend(tax_ids) continue taxes.append(tax) + if tax_rule: + tax_ids = tax_rule.apply(None, pattern) + if tax_ids: + taxes.extend(tax_ids) self.taxes = taxes @classmethod