diff --git a/addons/l10n_ar/__manifest__.py b/addons/l10n_ar/__manifest__.py index c1bb058709d..3c7aa692f0e 100644 --- a/addons/l10n_ar/__manifest__.py +++ b/addons/l10n_ar/__manifest__.py @@ -101,6 +101,7 @@ Master Data: 'views/l10n_latam_document_type_view.xml', 'views/report_invoice.xml', 'report/invoice_report_view.xml', + 'data/account_chart_template_configure_data.xml', ], 'demo': [ # we create demo data on different companies (not main_company) to diff --git a/addons/l10n_ar/data/account_chart_template_configure_data.xml b/addons/l10n_ar/data/account_chart_template_configure_data.xml new file mode 100644 index 00000000000..73bc1ca40b6 --- /dev/null +++ b/addons/l10n_ar/data/account_chart_template_configure_data.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/addons/l10n_ar/demo/exento_demo.xml b/addons/l10n_ar/demo/exento_demo.xml index d60c819bcb1..eaa5afff955 100644 --- a/addons/l10n_ar/demo/exento_demo.xml +++ b/addons/l10n_ar/demo/exento_demo.xml @@ -37,18 +37,6 @@ - - Sales Journal - - sale - S0001 - - 1 - - II_IM - - - Expo Sales Journal diff --git a/addons/l10n_ar/demo/mono_demo.xml b/addons/l10n_ar/demo/mono_demo.xml index 32a50e9f1ff..0303743114e 100644 --- a/addons/l10n_ar/demo/mono_demo.xml +++ b/addons/l10n_ar/demo/mono_demo.xml @@ -37,18 +37,6 @@ - - Sales Journal - - sale - S0001 - - 1 - - II_IM - - - Expo Sales Journal diff --git a/addons/l10n_ar/demo/respinsc_demo.xml b/addons/l10n_ar/demo/respinsc_demo.xml index 57b75f1dbfe..eaf13fa6f05 100644 --- a/addons/l10n_ar/demo/respinsc_demo.xml +++ b/addons/l10n_ar/demo/respinsc_demo.xml @@ -45,19 +45,6 @@ - - Sales Journal - - sale - S0001 - - 1 - - II_IM - - - - Expo Sales Journal diff --git a/addons/l10n_ar/models/account_chart_template.py b/addons/l10n_ar/models/account_chart_template.py index aace31e5203..a322e5c5e7d 100644 --- a/addons/l10n_ar/models/account_chart_template.py +++ b/addons/l10n_ar/models/account_chart_template.py @@ -17,13 +17,20 @@ class AccountChartTemplate(models.Model): return res def _prepare_all_journals(self, acc_template_ref, company, journals_dict=None): - """ If Argentinean chart, we don't create sales journal as we need more - data to create it properly """ + """ In case of an Argentinean CoA, we modify the default values of the sales journal to be a preprinted journal""" 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) + vals.update({ + "name": "Ventas Preimpreso", + "code": "0001", + "l10n_ar_afip_pos_number": 1, + "l10n_ar_afip_pos_partner_id": company.partner_id.id, + "l10n_ar_afip_pos_system": 'II_IM', + "l10n_ar_share_sequences": True, + "refund_sequence": False + }) return res @api.model @@ -48,10 +55,6 @@ class AccountChartTemplate(models.Model): 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, diff --git a/addons/l10n_ar/models/account_journal.py b/addons/l10n_ar/models/account_journal.py index 8a537f57b4d..1f30df58cbc 100644 --- a/addons/l10n_ar/models/account_journal.py +++ b/addons/l10n_ar/models/account_journal.py @@ -106,13 +106,12 @@ class AccountJournal(models.Model): @api.constrains('type', 'l10n_ar_afip_pos_system', 'l10n_ar_afip_pos_number', 'l10n_ar_share_sequences', 'l10n_latam_use_documents') def _check_afip_configurations(self): - """ Do not let to update journal if already have confirmed invoices """ - arg_sale_journals = self.filtered(lambda x: x.company_id.country_id == self.env.ref('base.ar') and - x.type == 'sale' and x._origin.type == 'sale') - invoices = self.env['account.move'].search([('journal_id', 'in', arg_sale_journals.ids), ('state', '!=', 'draft')]) + """ Do not let the user update the journal if it already contains confirmed invoices """ + journals = self.filtered(lambda x: x.company_id.country_id == self.env.ref('base.ar') and x.type in ['sale', 'purchase']) + invoices = self.env['account.move'].search([('journal_id', 'in', journals.ids), ('posted_before', '=', True)], limit=1) if invoices: raise ValidationError( - _("You can not change the journal's configuration if journal already have validated invoices") + ' (' + _("You can not change the journal's configuration if it already has validated invoices") + ' (' + ', '.join(invoices.mapped('journal_id').mapped('name')) + ')') @api.constrains('l10n_ar_afip_pos_number') diff --git a/addons/l10n_ar/models/account_move.py b/addons/l10n_ar/models/account_move.py index 68a099389f8..bd41ec37401 100644 --- a/addons/l10n_ar/models/account_move.py +++ b/addons/l10n_ar/models/account_move.py @@ -177,8 +177,6 @@ class AccountMove(models.Model): def _inverse_l10n_latam_document_number(self): super()._inverse_l10n_latam_document_number() - # Avoid that user change the POS number (x.l10n_latam_document_number), Rhe POS number configure in journal it - # will always be used to_review = self.filtered( lambda x: x.journal_id.type == 'sale' and x.l10n_latam_document_type_id and x.l10n_latam_document_number and (x.l10n_latam_manual_document_number or not x.highest_name)) @@ -186,8 +184,15 @@ class AccountMove(models.Model): number = rec.l10n_latam_document_type_id._format_document_number(rec.l10n_latam_document_number) current_pos = int(number.split("-")[0]) if current_pos != rec.journal_id.l10n_ar_afip_pos_number: - raise UserError(_('Can not change the POS number, you can only change the first number for document' - ' type that you are creating in odoo')) + invoices = self.search([('journal_id', '=', rec.journal_id.id), ('posted_before', '=', True)], limit=1) + # If there is no posted before invoices the user can change the POS number (x.l10n_latam_document_number) + if (not invoices): + rec.journal_id.l10n_ar_afip_pos_number = current_pos + rec.journal_id._onchange_set_short_name() + # If not, avoid that the user change the POS number + else: + raise UserError(_('The document number can not be changed for this journal, you can only modify' + ' the POS number if there is not posted (or posted before) invoices')) def _get_formatted_sequence(self, number=0): return "%s %05d-%08d" % (self.l10n_latam_document_type_id.doc_code_prefix, diff --git a/addons/l10n_latam_invoice_document/models/account_journal.py b/addons/l10n_latam_invoice_document/models/account_journal.py index 015119d0a17..9ed4e43bb5f 100644 --- a/addons/l10n_latam_invoice_document/models/account_journal.py +++ b/addons/l10n_latam_invoice_document/models/account_journal.py @@ -26,7 +26,7 @@ class AccountJournal(models.Model): @api.constrains('l10n_latam_use_documents') def check_use_document(self): for rec in self: - if rec.env['account.move'].search([('journal_id', '=', rec.id), ('state', '!=', 'draft')], limit=1): + if rec.env['account.move'].search([('journal_id', '=', rec.id), ('posted_before', '=', True)], limit=1): raise ValidationError(_( 'You can not modify the field "Use Documents?" if there are validated invoices in this journal!'))