diff --git a/models/account_invoice.py b/models/account_invoice.py index 70f8f2c4100a0c294dee1b954fe72a0286661c47..d9d4c3f7a534ff6dc461490714886f4610f5ef3f 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 fb87f6e19d1d588a31395fb7767191a5048e72dd..c73d459f2a8ada0de0bc5f9351ac7a9bd8f0caef 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 @@ -689,7 +707,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/views/ws_caea_code_view.xml b/views/ws_caea_code_view.xml index ad50f6bf995c324a1a25e190ce3c559453da6aa0..339c7a7cf588877653efbb326b86b6b7219a0b3b 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.py b/wizard/caea_report_wizard.py index 92c5d16b7360c255c6e2eba0eb84878e79fc5ee1..c19744538cf1c7540aa737cb4543e7823a5a6371 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 diff --git a/wizard/caea_report_wizard.xml b/wizard/caea_report_wizard.xml index 55a3612e7bc1536a792c45dffc7333b443ad8520..42a5b551f2f785b51030e87c13e63cbdbab0728d 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"/>