Files
odoo_source/addons/l10n_ar/models/account_chart_template.py
T
Katherine Zaoral d0f86ec9c3 [FIX] l10n_ar: Do not set default purchase tax in Monotributista and Exempt companies.
This kind of companies (because of the AFIP responsibility type) should not have purchase tax defined by default and before this commit we have a default purchase tax named perception with actually is a optional tax that the user could set if needed but should not be set automatically set as default in all the invoice lines.  This commit remove this default purchase tax when loading the chart of account to avoid this bad behavior.

closes odoo/odoo#43832

X-original-commit: b6df9291555ac79b6f1d64cb27235d8191d710b8
Signed-off-by: Josse Colpaert <jco@openerp.com>
2020-01-23 10:45:05 +00:00

68 lines
3.1 KiB
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, api, _
from odoo.exceptions import UserError
from odoo.http import request
class AccountChartTemplate(models.Model):
_inherit = 'account.chart.template'
def _get_fp_vals(self, company, position):
res = super()._get_fp_vals(company, position)
if company.country_id == self.env.ref('base.ar'):
res['l10n_ar_afip_responsibility_type_ids'] = [
(6, False, position.l10n_ar_afip_responsibility_type_ids.ids)]
return res
def _prepare_all_journals(self, acc_template_ref, company, journals_dict=None):
""" If Argentinian chart, we don't create sales journal as we need more
data to create it properly """
res = super()._prepare_all_journals(acc_template_ref, company, journals_dict=journals_dict)
if company.country_id == self.env.ref('base.ar'):
for vals in res:
if vals['type'] == 'sale':
res.remove(vals)
return res
@api.model
def _get_ar_responsibility_match(self, chart_template_id):
""" return responsibility type that match with the given chart_template_id
"""
match = {
self.env.ref('l10n_ar.l10nar_base_chart_template').id: self.env.ref('l10n_ar.res_RM'),
self.env.ref('l10n_ar.l10nar_ex_chart_template').id: self.env.ref('l10n_ar.res_IVAE'),
self.env.ref('l10n_ar.l10nar_ri_chart_template').id: self.env.ref('l10n_ar.res_IVARI'),
}
return match.get(chart_template_id)
def _load(self, sale_tax_rate, purchase_tax_rate, company):
""" Set companies AFIP Responsibility and Country if AR CoA is installed, also set tax calculation rounding
method required in order to properly validate match AFIP invoices.
Also, raise a warning if the user is trying to install a CoA that does not match with the defined AFIP
Responsibility defined in the company
"""
self.ensure_one()
coa_responsibility = self._get_ar_responsibility_match(self.id)
if coa_responsibility:
company_responsibility = company.l10n_ar_afip_responsibility_type_id
if company_responsibility and company_responsibility != coa_responsibility:
raise UserError(_(
'You are trying to install a chart of account for the %s responsibility but your company is'
' configured as %s type' % (coa_responsibility.name, company_responsibility.name)))
company.write({
'l10n_ar_afip_responsibility_type_id': coa_responsibility.id,
'country_id': self.env.ref('base.ar').id,
'tax_calculation_rounding_method': 'round_globally',
})
res = super()._load(sale_tax_rate, purchase_tax_rate, company)
# If Responsable Monotributista remove the default purchase tax
if self == self.env.ref('l10n_ar.l10nar_base_chart_template') or \
self == self.env.ref('l10n_ar.l10nar_ex_chart_template'):
company.account_purchase_tax_id = self.env['account.tax']
return res