diff options
| author | Daniel Blanco <daniel@blancomartin.cl> | 2020-09-15 21:18:45 +0000 |
|---|---|---|
| committer | Susana <susana@blancomartin.cl> | 2020-09-29 22:07:35 +0000 |
| commit | faea1fec6b0a8571e5f61c1a891cfa708b0a9075 (patch) | |
| tree | 293e18c088fe85f7ca8371909a2ac90e4d4a1d81 /addons/l10n_cl/models | |
| parent | 654be58894c51d2c5384ead67a5a7c68fdebf0a7 (diff) | |
[ADD] l10n_cl: forward to 14.0
closes odoo/odoo#58441
Related: odoo/enterprise#13477
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 | 30 | ||||
| -rw-r--r-- | addons/l10n_cl/models/account_move.py | 26 | ||||
| -rw-r--r-- | addons/l10n_cl/models/l10n_latam_document_type.py | 23 |
3 files changed, 28 insertions, 51 deletions
diff --git a/addons/l10n_cl/models/account_journal.py b/addons/l10n_cl/models/account_journal.py index 5d3fca43818..5917e688b5a 100644 --- a/addons/l10n_cl/models/account_journal.py +++ b/addons/l10n_cl/models/account_journal.py @@ -8,32 +8,4 @@ class AccountJournal(models.Model): l10n_cl_sequence_ids = fields.Many2many( 'ir.sequence', 'l10n_cl_journal_sequence_rel', 'journal_id', 'sequence_id', string='Sequences (cl)', - domain="[('l10n_latam_document_type_id', '!=', False)]") - - 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)] - 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: - sequences |= self.env['ir.sequence'].create(document._get_document_sequence_vals(self)) - self.write({'l10n_cl_sequence_ids': [(4, s.id) for s in sequences]}) - - def create_document_sequences_cl(self): - self.ensure_one() - if (self.company_id.country_id != self.env.ref('base.cl')) or self.env['ir.sequence'].search( - [('l10n_latam_document_type_id', '!=', False)]) or self.type != 'sale' or not self.l10n_latam_use_documents: - return - self.button_create_new_sequences() - - @api.model - def create(self, values): - """ Create Document sequences after create the journal """ - res = super().create(values) - res.create_document_sequences_cl() - return res + domain="[('l10n_latam_document_type_id', '!=', False)]")
\ No newline at end of file diff --git a/addons/l10n_cl/models/account_move.py b/addons/l10n_cl/models/account_move.py index 2b1f2a0ebce..721c142c0b8 100644 --- a/addons/l10n_cl/models/account_move.py +++ b/addons/l10n_cl/models/account_move.py @@ -4,6 +4,8 @@ from odoo.exceptions import ValidationError from odoo import models, fields, api, _ from odoo.osv import expression +SII_VAT = '60805000-0' + class AccountMove(models.Model): _inherit = "account.move" @@ -19,16 +21,19 @@ class AccountMove(models.Model): 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.type == 'sale': - document_type_ids = self.journal_id.l10n_cl_sequence_ids.mapped('l10n_latam_document_type_id').ids + domain = [('country_id', '=', self.env.ref('base.cl').id), ('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 else: 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': + elif self.partner_id.l10n_cl_sii_taxpayer_type == '1' and self.partner_id_vat != SII_VAT: 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': + elif self.partner_id.l10n_cl_sii_taxpayer_type == '1' and self.partner_id_vat == SII_VAT: 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'])] @@ -61,7 +66,7 @@ class AccountMove(models.Model): 'Document types for foreign customers must be export type (codes 110, 111 or 112) or you \ should define the customer as an end consumer and use receipts (codes 39 or 41)')) if rec.journal_id.type == 'purchase' and rec.journal_id.l10n_latam_use_documents: - if vat != '60805000-0' and latam_document_type_code == '914': + if vat != SII_VAT 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: @@ -96,11 +101,11 @@ class AccountMove(models.Model): super()._post(soft) def _l10n_cl_get_formatted_sequence(self, number=0): - return "%s %06d" % (self.l10n_latam_document_type_id.doc_code_prefix, number) + return '%s %06d' % (self.l10n_latam_document_type_id.doc_code_prefix, number) 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 8 padding number """ + 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.l10n_latam_document_type_id: return self._l10n_cl_get_formatted_sequence() @@ -109,11 +114,10 @@ class AccountMove(models.Model): 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: - journals = self.journal_id.l10n_cl_sequence_ids.filtered(lambda s: s.l10n_latam_document_type_id == self.l10n_latam_document_type_id).l10n_cl_journal_ids.ids - if len(journals) > 1: - where_string.replace("journal_id = %(journal_ids)s", "journal_id in %(journal_ids)s") - param['journal_ids'] = journals - where_string += " AND l10n_latam_document_type_id = %(l10n_latam_document_type_id)s " + 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' + param['company_id'] = self.company_id.id or False param['l10n_latam_document_type_id'] = self.l10n_latam_document_type_id.id or 0 return where_string, param diff --git a/addons/l10n_cl/models/l10n_latam_document_type.py b/addons/l10n_cl/models/l10n_latam_document_type.py index 083de809f42..0487f035d67 100644 --- a/addons/l10n_cl/models/l10n_latam_document_type.py +++ b/addons/l10n_cl/models/l10n_latam_document_type.py @@ -15,15 +15,16 @@ class L10nLatamDocumentType(models.Model): ('credit_note', 'Credit Notes'), ('receipt_invoice', 'Receipt Invoice')]) - def _get_document_sequence_vals(self, journal): - values = {} + def _format_document_number(self, document_number): + """ Make validation of Import Dispatch Number + * making validations on the document_number. If it is wrong it should raise an exception + * format the document_number against a pattern and return it + """ + self.ensure_one() if self.country_id != self.env.ref('base.cl'): - return values - values.update({ - 'name': '%s - %s' % (journal.name, self.name), - 'padding': 6, - 'implementation': 'no_gap', - 'l10n_latam_document_type_id': self.id, - 'prefix': None - }) - return values + return super()._format_document_number(document_number) + + if not document_number: + return False + + return document_number.zfill(6) |
