From 704aca129f5f7ba60f9600db07650242ac8fa976 Mon Sep 17 00:00:00 2001 From: "diego.barreto" <diego.barreto@eynes.com.ar> Date: Mon, 8 Jul 2024 12:46:03 -0300 Subject: [PATCH 1/2] [FIX][T4901] add date check before generating voucher report and show which invoice gets error while reporting --- models/ws_caea_code.py | 2 +- wizard/caea_report_wizard.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/models/ws_caea_code.py b/models/ws_caea_code.py index fb87f6e..0f0c98a 100644 --- a/models/ws_caea_code.py +++ b/models/ws_caea_code.py @@ -689,7 +689,7 @@ class WsCaeaCode(models.Model): key_req='informarComprobanteCAEA', **prepare_comprobante) except Exception as e: - raise exceptions.ValidationError(str(e)) + raise exceptions.ValidationError(str(invoice.internal_number) + '\n' +str(e)) if errors: self.config_id.get_errors(errors) if observ: diff --git a/wizard/caea_report_wizard.py b/wizard/caea_report_wizard.py index 92c5d16..c197445 100644 --- a/wizard/caea_report_wizard.py +++ b/wizard/caea_report_wizard.py @@ -1,6 +1,7 @@ # -*- encoding: utf-8 -*- from odoo import models, fields, api import logging +from odoo.exceptions import UserError _logger = logging.getLogger(__name__) @@ -27,6 +28,10 @@ class CaeaReportWizard(models.TransientModel): # Funciones @api.multi def get_invoices(self): + + if self.date_start < self.caea_code_id.date_from or self.date_end > self.caea_code_id.date_to: + raise UserError("El rango de fechas seleccionado esta fuera del rango del periodo del CAEA") + list_invoice = self.caea_code_id.invoice_ids.filtered( lambda record: record.caea and self.date_start <= record.date_invoice <= self.date_end -- GitLab From 2c04629d799096568915639eb94187f4959334a7 Mon Sep 17 00:00:00 2001 From: "diego.barreto" <diego.barreto@eynes.com.ar> Date: Fri, 12 Jul 2024 10:02:28 -0300 Subject: [PATCH 2/2] [T4901] add select invoices to inform function --- models/account_invoice.py | 2 +- models/ws_caea_code.py | 18 ++++++++++++++++++ views/ws_caea_code_view.xml | 9 +++++++++ wizard/caea_report_wizard.xml | 1 - 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/models/account_invoice.py b/models/account_invoice.py index 70f8f2c..d9d4c3f 100644 --- a/models/account_invoice.py +++ b/models/account_invoice.py @@ -46,7 +46,7 @@ class AccountInvoice(models.Model): related='caea_code_id.config_id', readonly=True, ) - + select = fields.Boolean(default=False) # Funciones def open_partner(self): """ diff --git a/models/ws_caea_code.py b/models/ws_caea_code.py index 0f0c98a..c73d459 100644 --- a/models/ws_caea_code.py +++ b/models/ws_caea_code.py @@ -117,6 +117,7 @@ class WsCaeaCode(models.Model): string='Unused CAEA Report', readonly=True, ) + any_selected = fields.Boolean(string='Any Selected', compute='_compute_any_selected') # Funciones def write(self, vals): @@ -195,6 +196,23 @@ class WsCaeaCode(models.Model): 'context': {'default_caea_code_id': self.id}, } + @api.depends('invoice_ids.select') + def _compute_any_selected(self): + for record in self: + record.any_selected = any(invoice.select for invoice in record.invoice_ids) + + def generate_voucher_only_select_invoices(self): + list_invoice = self.invoice_ids.filtered(lambda record: record.select == True).sorted(key=lambda record: record.id) + if list_invoice: + rec = self.env['ws.caea.report'].sudo().create({ + 'caea_code_id': self.id, + 'date_start': list_invoice[0].date_invoice, + 'date_end': list_invoice[-1].date_invoice, + 'invoices_ids': [(4, i.id,) for i in list_invoice], + }) + self.write({'caea_report_ids': [(4, rec.id)]}) + list_invoice.write({'select': False}) + # ************INFORME COMPROBANTE CAEA******************************* def get_cotizacion(self, invoice): company_id = invoice.env.user.company_id diff --git a/views/ws_caea_code_view.xml b/views/ws_caea_code_view.xml index ad50f6b..339c7a7 100644 --- a/views/ws_caea_code_view.xml +++ b/views/ws_caea_code_view.xml @@ -30,6 +30,14 @@ </header> <sheet> <div class="oe_button_box" name="button_box"> + <field name="any_selected" invisible="1"/> + <button name="generate_voucher_only_select_invoices" + string="Generate Voucher Report Only Select" + type="object" + class="oe_stat_button" + icon="fa-list" + attrs="{'invisible': [('any_selected', '=', False)]}" + /> <button name="call_wizard_comprobante" string="Generate Voucher Report" type="object" class="oe_stat_button " icon="fa-list"></button> <button name="call_wizard_prepare_mail" string="Prepare and Send Mail" type="object" @@ -59,6 +67,7 @@ <page string="Associated Invoices"> <field name="invoice_ids"> <tree> + <field name="select" widget="boolean_toggle"/> <field name="partner_id"/> <field name="date_invoice"/> <field name="denomination_id"/> diff --git a/wizard/caea_report_wizard.xml b/wizard/caea_report_wizard.xml index 55a3612..42a5b55 100644 --- a/wizard/caea_report_wizard.xml +++ b/wizard/caea_report_wizard.xml @@ -30,7 +30,6 @@ </group> </div> </div> - </sheet> <footer> <button name="get_invoices" type="object" string="Generate" class="oe_highlight"/> -- GitLab