From a9309e931c38d6b669000ffef183a333519e19e4 Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Wed, 25 Sep 2019 08:38:12 +0000 Subject: [PATCH] [FIX] account: Fix fallback on company taxes Revert the new behavior introduced by https://github.com/odoo/odoo/commit/9bc4a19d74185a066b7ac870b02fd1836c4392b6 We finally decide to restore the previous behavior allowing to fallback on the company default taxes. In addition, the taxes will be overrided only if specific taxes are set on the account. closes odoo/odoo#37406 Signed-off-by: Quentin De Paoli (qdp) --- addons/account/models/account_move.py | 14 ++++++++++---- addons/account/models/chart_template.py | 5 ----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index a21b99b1a21..605cbf6ea76 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -2503,7 +2503,9 @@ class AccountMoveLine(models.Model): elif self.account_id.tax_ids: tax_ids = self.account_id.tax_ids else: - tax_ids = None + tax_ids = self.env['account.tax'] + if not tax_ids and not self.exclude_from_invoice_tab: + tax_ids = self.move_id.company_id.account_sale_tax_id elif self.move_id.is_purchase_document(include_receipts=True): # In invoice. if self.product_id.supplier_taxes_id: @@ -2511,7 +2513,9 @@ class AccountMoveLine(models.Model): elif self.account_id.tax_ids: tax_ids = self.account_id.tax_ids else: - tax_ids = None + tax_ids = self.env['account.tax'] + if not tax_ids and not self.exclude_from_invoice_tab: + tax_ids = self.move_id.company_id.account_purchase_tax_id else: # Miscellaneous operation. tax_ids = self.account_id.tax_ids @@ -2732,8 +2736,10 @@ class AccountMoveLine(models.Model): @api.onchange('account_id') def _onchange_account_id(self): - ''' Recompute 'tax_ids' based on 'account_id'. ''' - if not self.display_type in ('line_section', 'line_note'): + ''' Recompute 'tax_ids' based on 'account_id'. + /!\ Don't remove existing taxes if there is no explicit taxes set on the account. + ''' + if not self.display_type and (self.account_id.tax_ids or not self.tax_ids): self.tax_ids = self._get_computed_taxes() def _onchange_balance(self): diff --git a/addons/account/models/chart_template.py b/addons/account/models/chart_template.py index dfa524f5cf6..abe030637f2 100644 --- a/addons/account/models/chart_template.py +++ b/addons/account/models/chart_template.py @@ -250,11 +250,6 @@ class AccountChartTemplate(models.Model): company.account_sale_tax_id = self.env['account.tax'].search([('type_tax_use', 'in', ('sale', 'all')), ('company_id', '=', company.id)], limit=1).id company.account_purchase_tax_id = self.env['account.tax'].search([('type_tax_use', 'in', ('purchase', 'all')), ('company_id', '=', company.id)], limit=1).id - # set default taxes to income/expense accounts - if company.account_sale_tax_id: - self.env['account.account'].browse(acc_template_ref.values()).filtered(lambda x: x.user_type_id.internal_group == 'income' and x != company.income_currency_exchange_account_id).tax_ids = company.account_sale_tax_id - if company.account_purchase_tax_id: - self.env['account.account'].browse(acc_template_ref.values()).filtered(lambda x: x.user_type_id.internal_group == 'expense' and x != company.expense_currency_exchange_account_id).tax_ids = company.account_purchase_tax_id return {} @api.model