From 15d6e0f47bb3645602841e3eb0e97eb684fbb55e Mon Sep 17 00:00:00 2001 From: Daniel Blanco Date: Tue, 15 Sep 2020 21:18:45 +0000 Subject: [PATCH] [ADD] l10n_cl: forward to 14.0 closes odoo/odoo#58889 X-original-commit: faea1fec6b0a8571e5f61c1a891cfa708b0a9075 Related: odoo/enterprise#13721 Signed-off-by: Josse Colpaert --- addons/l10n_cl/__manifest__.py | 1 - addons/l10n_cl/i18n/es.po | 5 - addons/l10n_cl/i18n/l10n_cl.pot | 5 - addons/l10n_cl/models/account_journal.py | 30 +-- addons/l10n_cl/models/account_move.py | 26 ++- .../models/l10n_latam_document_type.py | 23 ++- addons/l10n_cl/views/account_journal_view.xml | 25 --- .../views/l10n_latam_document_type_view.xml | 13 ++ addons/l10n_cl/views/report_invoice.xml | 191 ++++++++++++++++-- 9 files changed, 219 insertions(+), 100 deletions(-) delete mode 100644 addons/l10n_cl/views/account_journal_view.xml create mode 100644 addons/l10n_cl/views/l10n_latam_document_type_view.xml diff --git a/addons/l10n_cl/__manifest__.py b/addons/l10n_cl/__manifest__.py index f1941906f24..a23a5fb837c 100644 --- a/addons/l10n_cl/__manifest__.py +++ b/addons/l10n_cl/__manifest__.py @@ -19,7 +19,6 @@ Plan contable chileno e impuestos de acuerdo a disposiciones vigentes 'uom', ], 'data': [ - 'views/account_journal_view.xml', 'views/account_move_view.xml', 'views/account_tax_view.xml', 'views/ir_sequence_view.xml', diff --git a/addons/l10n_cl/i18n/es.po b/addons/l10n_cl/i18n/es.po index 80c15bba2b4..67f2d33e3ef 100644 --- a/addons/l10n_cl/i18n/es.po +++ b/addons/l10n_cl/i18n/es.po @@ -445,11 +445,6 @@ msgstr "Comercial" msgid "Sequence" msgstr "Secuencia" -#. module: l10n_cl -#: model:ir.model.fields,field_description:l10n_cl.field_account_journal__l10n_cl_sequence_ids -msgid "Sequences (cl)" -msgstr "Secuencias (CL)" - #. module: l10n_cl #: model:ir.model.fields,field_description:l10n_cl.field_res_currency__l10n_cl_short_name msgid "Short Name" diff --git a/addons/l10n_cl/i18n/l10n_cl.pot b/addons/l10n_cl/i18n/l10n_cl.pot index 43c90c6079a..7db8d03ab2a 100644 --- a/addons/l10n_cl/i18n/l10n_cl.pot +++ b/addons/l10n_cl/i18n/l10n_cl.pot @@ -429,11 +429,6 @@ msgstr "" msgid "Sequence" msgstr "" -#. module: l10n_cl -#: model:ir.model.fields,field_description:l10n_cl.field_account_journal__l10n_cl_sequence_ids -msgid "Sequences (cl)" -msgstr "" - #. module: l10n_cl #: model:ir.model.fields,field_description:l10n_cl.field_res_currency__l10n_cl_short_name msgid "Short Name" 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) diff --git a/addons/l10n_cl/views/account_journal_view.xml b/addons/l10n_cl/views/account_journal_view.xml deleted file mode 100644 index 8068da6f45e..00000000000 --- a/addons/l10n_cl/views/account_journal_view.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - account.journal - account.journal.form.inherit.cl - - - -