l10n-switzerland-flectra/l10n_ch_payment_slip/wizard/isr_batch_print.py
Raphael Ritter 14a109dc87 [ADD] l10n_ch_payment_slip
[ADD] l10n_ch_zip
[ADD] l10n_ch_bank_statement_import_postfinance
2021-07-16 16:21:21 +02:00

40 lines
1.2 KiB
Python

# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from flectra import models, fields, api
from flectra.exceptions import UserError
class ISRBatchPrintWizard(models.TransientModel):
_name = 'isr.batch.print.wizard'
invoice_ids = fields.Many2many(comodel_name='account.move',string='Invoices',ondelete ='cascade')
error_message = fields.Text('Errors', readonly=True)
@api.model
def default_get(self, fields):
res = super(ISRBatchPrintWizard, self).default_get(fields)
active_ids = self.env.context.get('active_ids')
if active_ids:
invoices = self.env['account.invoice'].browse(active_ids)
msg = self.check_generatable(invoices)
if msg:
res['error_message'] = msg
res['invoice_ids'] = active_ids
return res
@api.model
def check_generatable(self, invoices):
try:
invoices._check_isr_generatable()
except UserError as e:
return e.name
#@api.multi
def print_payment_slips(self):
if self.invoice_ids:
return self.invoice_ids.print_isr()
else:
return {'type': 'ir.actions.act_window_close'}