diff options
| author | Daniel Blanco <daniel@blancomartin.cl> | 2019-12-02 12:34:52 +0000 |
|---|---|---|
| committer | Ravi Gohil <rgo@odoo.com> | 2020-06-16 13:28:00 +0000 |
| commit | f3a66dd65d041ffc7367d85d5603e9627efb9f2b (patch) | |
| tree | dc11f51312c633dd4896ce0be4691170e9774bf0 /addons/l10n_cl/models | |
| parent | d85ed5151436be8e17fd7999db5f180c33d3b99b (diff) | |
[FIX] l10n_cl: Several fixes and improvements for l10n_cl
[FIX] l10n_cl: format RUT/VAT as used in Chile (99999999-X)
[FIX] l10n_cl: prevent errors with domain of available documents in invoice view.
[FIX] l10n_cl: allow to select document types when partner is empty
[ADD] l10n_cl: add ILA taxes (purchase and sale) and assign account to taxes
[ADD] l10n_cl: add fiscal position exempt for purchases and sales
[IMP] l10n_cl: configure accounts used in inventory valuation
[FIX] l10n_cl prevent to put unneeded sales documents in sales journal
[FIX] l10n_cl limit revision of document types and partner constrains only for sale and purchase journals
[FIX] l10n_cl: add extra validation to know wether there is a latam_document_type_code selected
[ADD] l10n_cl: add document type '801' Orden de compra
[WIP] add tag to costo de ventas account
[FIX] l10n_cl: fiscal position templates: fix supermarket tax
[FIX] l10n_cl: change order for boletas
[WIP] l10n_cl: fix the compute document types method
[FIX] l10n_cl: prevent expected singleton error (checked in tests) in post
[I18N] l10n_cl: add new translations
[I18N] l10n_cl: reduce size of taxes names and abbreviation for invoices (probably more work to add here)
[FIX] l10n_cl: remove countries from accounts
[FIX] l10n_cl: remove recalc of domain when journal changes
[FIX] l10n_cl: remove sale constraint
closes odoo/odoo#53068
X-original-commit: 060f083879f6094941f746928832fec253a23bb0
Signed-off-by: Josse Colpaert <jco@openerp.com>
Diffstat (limited to 'addons/l10n_cl/models')
| -rw-r--r-- | addons/l10n_cl/models/account_journal.py | 6 | ||||
| -rw-r--r-- | addons/l10n_cl/models/account_move.py | 87 | ||||
| -rw-r--r-- | addons/l10n_cl/models/account_tax.py | 2 | ||||
| -rw-r--r-- | addons/l10n_cl/models/res_partner.py | 32 |
4 files changed, 108 insertions, 19 deletions
diff --git a/addons/l10n_cl/models/account_journal.py b/addons/l10n_cl/models/account_journal.py index ce218d0a827..5d3fca43818 100644 --- a/addons/l10n_cl/models/account_journal.py +++ b/addons/l10n_cl/models/account_journal.py @@ -13,7 +13,11 @@ class AccountJournal(models.Model): def button_create_new_sequences(self): self.ensure_one() internal_types = ['invoice', 'debit_note', 'credit_note'] - domain = [('country_id.code', '=', 'CL'), ('internal_type', 'in', internal_types), ('active', '=', True)] + domain = [('country_id.code', '=', 'CL'), ('internal_type', 'in', internal_types)] + if self.company_id.partner_id.l10n_cl_sii_taxpayer_type in ['1', False]: + domain += [('code', 'not in', ['70', '71'])] + elif self.company_id.partner_id.l10n_cl_sii_taxpayer_type == '2': + domain += [('code', 'not in', ['33', '34'])] documents = self.env['l10n_latam.document.type'].search(domain) sequences = self.env['ir.sequence'] for document in documents: diff --git a/addons/l10n_cl/models/account_move.py b/addons/l10n_cl/models/account_move.py index 7adb1a73d26..249e155fca7 100644 --- a/addons/l10n_cl/models/account_move.py +++ b/addons/l10n_cl/models/account_move.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo.exceptions import ValidationError - from odoo import models, fields, api, _ @@ -18,26 +17,80 @@ class AccountMove(models.Model): 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.move_type in ['in_invoice', 'in_refund']: - if self.partner_id.l10n_cl_sii_taxpayer_type == '2': - domain += [('code', '=', '71')] - return domain - document_type_ids = self.journal_id.l10n_cl_sequence_ids.mapped('l10n_latam_document_type_id').ids - domain += [('id', 'in', document_type_ids)] - if self.partner_id.l10n_cl_sii_taxpayer_type == '3': - domain += [('code', 'in', ['35', '38', '39', '41', '56', '61'])] + if self.journal_id.type == 'sale': + document_type_ids = self.journal_id.l10n_cl_sequence_ids.mapped('l10n_latam_document_type_id').ids + else: # self.journal_id.type == 'purchase': + partner_domain = [ + ('country_id.code', '=', 'CL'), + ('internal_type', 'in', ['invoice', 'debit_note', 'credit_note', 'invoice_in'])] + if not self.partner_id: + pass + elif self.partner_id.l10n_cl_sii_taxpayer_type == '1' and self.partner_id_vat != '60805000-0': + partner_domain += [('code', 'not in', ['39', '70', '71', '914', '911'])] + elif self.partner_id.l10n_cl_sii_taxpayer_type == '1' and self.partner_id_vat == '60805000-0': + partner_domain += [('code', 'not in', ['39', '70', '71'])] + elif self.partner_id.l10n_cl_sii_taxpayer_type == '2': + 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': + partner_domain += [('code', 'in', [])] + document_type_ids = self.env['l10n_latam.document.type'].search(partner_domain).ids + domain = [('id', 'in', document_type_ids)] return domain - @api.constrains('move_type', 'l10n_latam_document_type_id') - def _check_invoice_type_document_type(self): - super()._check_invoice_type_document_type() - for rec in self.filtered(lambda r: r.company_id.country_id == self.env.ref( - 'base.cl') and r.l10n_latam_document_type_id): + def _check_document_types_post(self): + for rec in self.filtered( + lambda r: r.company_id.country_id == self.env.ref('base.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 and latam_document_type_code not in ['35', '38', '39', '41']: - raise ValidationError(_('Tax payer type is mandatory for this type of document. ' - 'Please set the current tax payer type of this client')) + if (not tax_payer_type or not vat) and (country_id == self.env.ref('base.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 (tax_payer_type == '4' or country_id != self.env.ref('base.cl')) and \ + latam_document_type_code not in ['110', '111', '112']: + raise ValidationError(_( + 'Document types for foreign customers must be export type (codes 110, 111 or 112)')) + if rec.journal_id.type == 'purchase' and rec.journal_id.l10n_latam_use_documents: + if vat != '60805000-0' and latam_document_type_code == '914': + 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 [ + '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')) + if tax_payer_type == '2' and latam_document_type_code not in ['70', '71', '56', '61']: + raise ValidationError(_('The tax payer type of this supplier is incorrect for the selected type' + ' of document.')) + if tax_payer_type in ['1', '3']: + if latam_document_type_code in ['70', '71']: + raise ValidationError(_('The tax payer type of this supplier is not entitled to deliver ' + 'fees documents')) + 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'): + 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: + if tax_payer_type != '4': + raise ValidationError(_('This supplier should be defined as foreigner tax payer type and ' + 'the country should be different from Chile to register purchases.')) + + @api.onchange('journal_id') + def _onchange_journal(self): + self.l10n_latam_document_type_id = False + + def post(self): + self._check_document_types_post() + super().post() def _l10n_cl_get_formatted_sequence(self, number=0): return "%s %06d" % (self.l10n_latam_document_type_id.doc_code_prefix, number) diff --git a/addons/l10n_cl/models/account_tax.py b/addons/l10n_cl/models/account_tax.py index c1edd934a50..0f102863763 100644 --- a/addons/l10n_cl/models/account_tax.py +++ b/addons/l10n_cl/models/account_tax.py @@ -7,7 +7,7 @@ class AccountTax(models.Model): _name = 'account.tax' _inherit = 'account.tax' - l10n_cl_sii_code = fields.Integer('SII Code') + l10n_cl_sii_code = fields.Integer('SII Code', group_operator=False) class AccountTaxTemplate(models.Model): diff --git a/addons/l10n_cl/models/res_partner.py b/addons/l10n_cl/models/res_partner.py index 608f031ae6c..463051628f9 100644 --- a/addons/l10n_cl/models/res_partner.py +++ b/addons/l10n_cl/models/res_partner.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +import stdnum from odoo import _, api, fields, models from odoo.exceptions import UserError, ValidationError @@ -21,3 +22,34 @@ class ResPartner(models.Model): '2 - Fees Receipt Issuer (Applies to suppliers who issue fees receipt)\n' '3 - End consumer (only receipts)\n' '4 - Foreigner') + + 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')) + 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( + 'CL', '').upper() + else: + return values['vat'] + + @api.model + def create(self, values): + if values.get('vat'): + values['vat'] = self._format_vat_cl(values) + return super().create(values) + + def write(self, values): + for record in self: + vat_values = { + 'vat': values.get('vat', record.vat), + 'l10n_latam_identification_type_id': values.get( + 'l10n_latam_identification_type_id', record.l10n_latam_identification_type_id.id), + 'country_id': values.get('country_id', record.country_id.id) + } + values['vat'] = self._format_vat_cl(vat_values) + return super().write(values) |
