summaryrefslogtreecommitdiff
path: root/addons/l10n_cl/models
diff options
context:
space:
mode:
Diffstat (limited to 'addons/l10n_cl/models')
-rw-r--r--addons/l10n_cl/models/account_move.py22
-rw-r--r--addons/l10n_cl/models/l10n_latam_document_type.py2
-rw-r--r--addons/l10n_cl/models/res_company.py2
-rw-r--r--addons/l10n_cl/models/res_partner.py9
4 files changed, 17 insertions, 18 deletions
diff --git a/addons/l10n_cl/models/account_move.py b/addons/l10n_cl/models/account_move.py
index 721c142c0b8..1380871ec56 100644
--- a/addons/l10n_cl/models/account_move.py
+++ b/addons/l10n_cl/models/account_move.py
@@ -18,10 +18,9 @@ class AccountMove(models.Model):
def _get_l10n_latam_documents_domain(self):
self.ensure_one()
domain = super()._get_l10n_latam_documents_domain()
- if (self.journal_id.l10n_latam_use_documents and
- self.journal_id.company_id.country_id == self.env.ref('base.cl')):
+ if self.journal_id.l10n_latam_use_documents and self.journal_id.company_id.country_id.code == "CL":
if self.journal_id.type == 'sale':
- domain = [('country_id', '=', self.env.ref('base.cl').id), ('internal_type', '!=', 'invoice_in')]
+ domain = [('country_id.code', '=', "CL"), ('internal_type', '!=', 'invoice_in')]
if self.company_id.partner_id.l10n_cl_sii_taxpayer_type == '1':
domain += [('code', '!=', '71')] # Companies with VAT Affected doesn't have "Boleta de honorarios Electrónica"
document_type_ids = self.env['l10n_latam.document.type'].search(domain).ids
@@ -39,8 +38,7 @@ class AccountMove(models.Model):
partner_domain += [('code', 'in', ['70', '71', '56', '61'])]
elif self.partner_id.l10n_cl_sii_taxpayer_type == '3':
partner_domain += [('code', 'in', ['35', '38', '39', '41', '56', '61'])]
- elif not self.partner_id.l10n_cl_sii_taxpayer_type or self.partner_id.country_id != self.env.ref(
- 'base.cl') or self.partner_id.l10n_cl_sii_taxpayer_type == '4':
+ elif not self.partner_id.l10n_cl_sii_taxpayer_type or self.partner_id.country_id.code != "CL" or self.partner_id.l10n_cl_sii_taxpayer_type == '4':
partner_domain += [('code', 'in', [])]
document_type_ids = self.env['l10n_latam.document.type'].search(partner_domain).ids
domain = expression.AND([domain, [('id', 'in', document_type_ids)]])
@@ -48,18 +46,18 @@ class AccountMove(models.Model):
def _check_document_types_post(self):
for rec in self.filtered(
- lambda r: r.company_id.country_id == self.env.ref('base.cl') and
+ lambda r: r.company_id.country_id.code == "CL" and
r.journal_id.type in ['sale', 'purchase']):
tax_payer_type = rec.partner_id.l10n_cl_sii_taxpayer_type
vat = rec.partner_id.vat
country_id = rec.partner_id.country_id
latam_document_type_code = rec.l10n_latam_document_type_id.code
- if (not tax_payer_type or not vat) and (country_id == self.env.ref('base.cl') and latam_document_type_code
+ if (not tax_payer_type or not vat) and (country_id.code == "CL" and latam_document_type_code
and latam_document_type_code not in ['35', '38', '39', '41']):
raise ValidationError(_('Tax payer type and vat number are mandatory for this type of '
'document. Please set the current tax payer type of this customer'))
if rec.journal_id.type == 'sale' and rec.journal_id.l10n_latam_use_documents:
- if country_id != self.env.ref('base.cl'):
+ if country_id.code != "CL":
if not ((tax_payer_type == '4' and latam_document_type_code in ['110', '111', '112']) or (
tax_payer_type == '3' and latam_document_type_code in ['39', '41', '61', '56'])):
raise ValidationError(_(
@@ -70,7 +68,7 @@ class AccountMove(models.Model):
raise ValidationError(_('The DIN document is intended to be used only with RUT 60805000-0'
' (Tesorería General de La República)'))
if not tax_payer_type or not vat:
- if country_id == self.env.ref('base.cl') and latam_document_type_code not in [
+ if country_id.code == "CL" and latam_document_type_code not in [
'35', '38', '39', '41']:
raise ValidationError(_('Tax payer type and vat number are mandatory for this type of '
'document. Please set the current tax payer type of this supplier'))
@@ -84,7 +82,7 @@ class AccountMove(models.Model):
if latam_document_type_code in ['110', '111', '112']:
raise ValidationError(_('The tax payer type of this supplier is not entitled to deliver '
'imports documents'))
- if tax_payer_type == '4' or country_id != self.env.ref('base.cl'):
+ if tax_payer_type == '4' or country_id.code != "CL":
raise ValidationError(_('You need a journal without the use of documents for foreign '
'suppliers'))
if rec.journal_id.type == 'purchase' and not rec.journal_id.l10n_latam_use_documents:
@@ -106,14 +104,14 @@ class AccountMove(models.Model):
def _get_starting_sequence(self):
""" If use documents then will create a new starting sequence using the document type code prefix and the
journal document number with a 6 padding number """
- if self.journal_id.l10n_latam_use_documents and self.env.company.country_id == self.env.ref('base.cl'):
+ if self.journal_id.l10n_latam_use_documents and self.env.company.country_id.code == "CL":
if self.l10n_latam_document_type_id:
return self._l10n_cl_get_formatted_sequence()
return super()._get_starting_sequence()
def _get_last_sequence_domain(self, relaxed=False):
where_string, param = super(AccountMove, self)._get_last_sequence_domain(relaxed)
- if self.company_id.country_id == self.env.ref('base.cl') and self.l10n_latam_use_documents:
+ if self.company_id.country_id.code == "CL" and self.l10n_latam_use_documents:
where_string = where_string.replace('journal_id = %(journal_id)s AND', '')
where_string += ' AND l10n_latam_document_type_id = %(l10n_latam_document_type_id)s AND ' \
'company_id = %(company_id)s'
diff --git a/addons/l10n_cl/models/l10n_latam_document_type.py b/addons/l10n_cl/models/l10n_latam_document_type.py
index 0487f035d67..6e5916b9527 100644
--- a/addons/l10n_cl/models/l10n_latam_document_type.py
+++ b/addons/l10n_cl/models/l10n_latam_document_type.py
@@ -21,7 +21,7 @@ class L10nLatamDocumentType(models.Model):
* format the document_number against a pattern and return it
"""
self.ensure_one()
- if self.country_id != self.env.ref('base.cl'):
+ if self.country_id.code != "CL":
return super()._format_document_number(document_number)
if not document_number:
diff --git a/addons/l10n_cl/models/res_company.py b/addons/l10n_cl/models/res_company.py
index 382f24c059f..8821be52e20 100644
--- a/addons/l10n_cl/models/res_company.py
+++ b/addons/l10n_cl/models/res_company.py
@@ -9,4 +9,4 @@ class ResCompany(models.Model):
def _localization_use_documents(self):
""" Chilean localization use documents """
self.ensure_one()
- return self.country_id == self.env.ref('base.cl') or super()._localization_use_documents()
+ return self.country_id.code == "CL" or super()._localization_use_documents()
diff --git a/addons/l10n_cl/models/res_partner.py b/addons/l10n_cl/models/res_partner.py
index 463051628f9..ecef783641e 100644
--- a/addons/l10n_cl/models/res_partner.py
+++ b/addons/l10n_cl/models/res_partner.py
@@ -26,10 +26,11 @@ class ResPartner(models.Model):
def _format_vat_cl(self, values):
identification_types = [self.env.ref('l10n_latam_base.it_vat').id, self.env.ref('l10n_cl.it_RUT').id,
self.env.ref('l10n_cl.it_RUN').id]
- partner_country_is_chile = (values.get('country_id') == self.env.ref('base.cl').id) or (
- values.get('l10n_latam_identification_type_id') and
- self.env['l10n_latam.identification.type'].browse(
- values.get('l10n_latam_identification_type_id')).country_id == self.env.ref('base.cl'))
+ country = self.env["res.country"].browse(values.get('country_id'))
+ identification_type = self.env['l10n_latam.identification.type'].browse(
+ values.get('l10n_latam_identification_type_id')
+ )
+ partner_country_is_chile = country.code == "CL" or identification_type.country_id.code == "CL"
if partner_country_is_chile and \
values.get('l10n_latam_identification_type_id') in identification_types and values.get('vat'):
return stdnum.util.get_cc_module('cl', 'vat').format(values['vat']).replace('.', '').replace(