[REV] account: default taxes on default sale/expense accounts
This reverts commit c539311. The default taxes will now be found in the invoice's onchange() which makes more sense and will work on all income/expense accounts without having to set the taxes on all these accounts.
This commit is contained in:
@@ -1640,11 +1640,12 @@ class AccountInvoiceLine(models.Model):
|
|||||||
self.price_unit = self.price_unit * currency.with_context(dict(self._context or {}, date=self.invoice_id.date_invoice)).rate
|
self.price_unit = self.price_unit * currency.with_context(dict(self._context or {}, date=self.invoice_id.date_invoice)).rate
|
||||||
|
|
||||||
def _set_taxes(self):
|
def _set_taxes(self):
|
||||||
""" Used in on_change to set taxes and price."""
|
""" Used in on_change to set taxes and price"""
|
||||||
|
self.ensure_one()
|
||||||
if self.invoice_id.type in ('out_invoice', 'out_refund'):
|
if self.invoice_id.type in ('out_invoice', 'out_refund'):
|
||||||
taxes = self.product_id.taxes_id or self.account_id.tax_ids
|
taxes = self.product_id.taxes_id or self.account_id.tax_ids or self.invoice_id.company_id.account_sale_tax_id
|
||||||
else:
|
else:
|
||||||
taxes = self.product_id.supplier_taxes_id or self.account_id.tax_ids
|
taxes = self.product_id.supplier_taxes_id or self.account_id.tax_ids or self.invoice_id.company_id.account_purchase_tax_id
|
||||||
|
|
||||||
# Keep only taxes of the company
|
# Keep only taxes of the company
|
||||||
company_id = self.company_id or self.env.user.company_id
|
company_id = self.company_id or self.env.user.company_id
|
||||||
@@ -1734,10 +1735,12 @@ class AccountInvoiceLine(models.Model):
|
|||||||
return
|
return
|
||||||
if not self.product_id:
|
if not self.product_id:
|
||||||
fpos = self.invoice_id.fiscal_position_id
|
fpos = self.invoice_id.fiscal_position_id
|
||||||
self.invoice_line_tax_ids = fpos.map_tax(self.account_id.tax_ids, partner=self.partner_id).ids
|
default_tax = self.invoice_id.type in ('out_invoice', 'out_refund') and self.invoice_id.company_id.account_sale_tax_id or self.invoice_id.company_id.account_purchase_tax_id
|
||||||
|
self.invoice_line_tax_ids = fpos.map_tax(self.account_id.tax_ids or default_tax, partner=self.partner_id).ids
|
||||||
elif not self.price_unit:
|
elif not self.price_unit:
|
||||||
self._set_taxes()
|
self._set_taxes()
|
||||||
|
|
||||||
|
|
||||||
@api.onchange('uom_id')
|
@api.onchange('uom_id')
|
||||||
def _onchange_uom_id(self):
|
def _onchange_uom_id(self):
|
||||||
warning = {}
|
warning = {}
|
||||||
|
|||||||
@@ -242,24 +242,9 @@ class AccountChartTemplate(models.Model):
|
|||||||
# Create the current year earning account if it wasn't present in the CoA
|
# Create the current year earning account if it wasn't present in the CoA
|
||||||
company.get_unaffected_earnings_account()
|
company.get_unaffected_earnings_account()
|
||||||
|
|
||||||
# set the default taxes on the company and on the sale/purchase properties
|
# set the default taxes on the company
|
||||||
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_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
|
company.account_purchase_tax_id = self.env['account.tax'].search([('type_tax_use', 'in', ('purchase', 'all')), ('company_id', '=', company.id)], limit=1).id
|
||||||
todo_list = [
|
|
||||||
('property_account_expense_categ_id', 'account_purchase_tax_id'),
|
|
||||||
('property_account_expense_id', 'account_purchase_tax_id'),
|
|
||||||
('property_account_income_categ_id', 'account_sale_tax_id'),
|
|
||||||
('property_account_income_id', 'account_sale_tax_id'),
|
|
||||||
]
|
|
||||||
last_acc = False
|
|
||||||
for record in todo_list:
|
|
||||||
account_template = getattr(self, record[0])
|
|
||||||
if account_template and account_template.id != last_acc:
|
|
||||||
account_id = acc_template_ref[account_template.id]
|
|
||||||
self.env['account.account'].browse(account_id).write({
|
|
||||||
'tax_ids': [(4, getattr(company, record[1]).id)],
|
|
||||||
})
|
|
||||||
last_acc = account_id
|
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
|
|||||||
Reference in New Issue
Block a user