account_invoice_xrechnung/wizard_runreport.py

80 lines
2.4 KiB
Python
Raw Normal View History

2022-10-18 15:33:31 +00:00
# -*- coding: utf-8 -*-
# This file is part of the cashbook-module from m-ds for Tryton.
# The COPYRIGHT file at the top level of this repository contains the
# full copyright notices and license terms.
from trytond.model import ModelView, fields
2022-10-19 15:47:47 +00:00
from trytond.wizard import Wizard, StateView, StateReport
2022-10-18 15:33:31 +00:00
from trytond.pool import Pool
from trytond.transaction import Transaction
2022-10-19 15:47:47 +00:00
sel_edocument = [
('edocument.xrechnung.invoice', 'XRechnung UBL Invoice 2.1.1'),
('edocument.uncefact.invoice', 'CII CrossIndustryInvoice D16B'),
]
class RunXRechnungReportStart(ModelView):
'eDocument Report'
__name__ = 'account_invoice_xrechnung.runrep.start'
invoice = fields.Many2One(string='Invoice', readonly=True,
model_name='account.invoice', required=True)
edocument = fields.Selection(string='eDocument', required=True,
selection=sel_edocument)
@classmethod
def default_edocument(cls):
""" default xrechnung
"""
return 'edocument.xrechnung.invoice'
# end RunXRechnungReportStart
2022-10-18 15:33:31 +00:00
class RunXRechnungReport(Wizard):
2022-10-19 15:47:47 +00:00
'eDocument Report'
2022-10-18 15:33:31 +00:00
__name__ = 'account_invoice_xrechnung.runrep'
start_state = 'open_'
2022-10-19 15:47:47 +00:00
export = StateReport('account_invoice_xrechnung.export')
open_ = StateView(
model_name='account_invoice_xrechnung.runrep.start',
view='account_invoice_xrechnung.wiz_start_form',
buttons=[
Button(string='Cancel', state='cleanup', icon='tryton-cancel'),
Button(string='Export', state='export', icon='tryton-export'),
],
)
def default_open_(self):
""" set defaults
"""
context = Transaction().context
result = {
'edocument': 'edocument.xrechnung.invoice',
'invoice': context.get('active_id', -1),
}
return result
2022-10-18 15:33:31 +00:00
2022-10-19 15:47:47 +00:00
def do_export(self, action):
2022-10-18 15:33:31 +00:00
""" run form
"""
pool = Pool()
Invoice = pool.get('account.invoice')
EDocument = pool.get('edocument.xrechnung.invoice')
context = Transaction().context
invoice, = Invoice.browse([context.get('active_id', -1)])
template = EDocument(invoice)
invoice_string = template.render('XRechnung-2.2')
print('\n## invoice_string:', invoice_string.decode('utf8'))
2022-10-19 15:47:47 +00:00
with open('x-rechnung.xml', 'wt') as fhdl:
fhdl.write(invoice_string.decode('utf8'))
2022-10-18 15:33:31 +00:00
return action, {}
# end RunXRechnungReport