[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) <qdp@openerp.com>
This commit is contained in:
Laurent Smet
2019-09-26 09:41:56 +00:00
parent 6ff9bd5028
commit a9309e931c
2 changed files with 10 additions and 9 deletions
+10 -4
View File
@@ -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):
-5
View File
@@ -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