43 lines
1.8 KiB
Python
43 lines
1.8 KiB
Python
# Copyright 2018-Today datenpol gmbh (<http://www.datenpol.at>)
|
|
# License OPL-1 or later (https://www.odoo.com/documentation/user/11.0/legal/licenses/licenses.html#licenses).
|
|
|
|
from odoo import api, fields, models, _
|
|
from odoo.exceptions import ValidationError
|
|
|
|
|
|
class WizardTzIc(models.TransientModel):
|
|
_name = 'wizard.tz.ic'
|
|
_description = 'Generiere IC-Rechnung'
|
|
|
|
new_pg_ic_num = fields.Char()
|
|
|
|
@api.multi
|
|
def button_tz_ic(self):
|
|
if not self.new_pg_ic_num:
|
|
raise ValidationError(_("Keine IC-Nummer angegeben"))
|
|
inv = self.env['account.invoice']
|
|
ck_ivc = inv.search([('pg_ic_num', '=', self.new_pg_ic_num), ('pg_ic_flag', '=', True)], order='id ASC',
|
|
limit=1)
|
|
if ck_ivc:
|
|
info = 'IC-Nummer bereits bei folgenden Rechnungen vergegeben!'
|
|
for ivc in ck_ivc:
|
|
info += '\n %s' % ivc.number
|
|
raise ValidationError(_(info))
|
|
for wizard in self:
|
|
error_at_ivc = False
|
|
info = 'Bitte prüfen Sie den Status folgender Rechnungen:'
|
|
active_ids = self.env.context.get('active_ids', [])
|
|
ivcs = self.env['account.invoice'].browse(active_ids)
|
|
if ivcs.exists():
|
|
for ivc in ivcs:
|
|
if not ivc.charge_further or ivc.pg_ic_flag or (ivc.state in ['draft','cancel']):
|
|
info += '\n %s, WV=%s / IC_Flag=%s / Status=%s' % (ivc.number,ivc.charge_further,ivc.pg_ic_flag,ivc.state)
|
|
error_at_ivc = True
|
|
else:
|
|
ivc.pg_ic_num = self.new_pg_ic_num
|
|
if error_at_ivc:
|
|
raise ValidationError(_(info))
|
|
action = self.env.ref('account.action_invoice_tree').read()[0]
|
|
action['domain'] = [('id', 'in', active_ids)]
|
|
return action
|