export ok

This commit is contained in:
Frederik Jaeckel 2022-10-20 14:43:58 +02:00
parent 00dd70e877
commit 73e30e1a88
12 changed files with 461 additions and 25 deletions

View file

@ -4,7 +4,7 @@
# full copyright notices and license terms.
from trytond.model import ModelView, fields
from trytond.wizard import Wizard, StateView, StateReport
from trytond.wizard import Wizard, StateView, StateReport, Button
from trytond.pool import Pool
from trytond.transaction import Transaction
@ -14,15 +14,28 @@ sel_edocument = [
('edocument.uncefact.invoice', 'CII CrossIndustryInvoice D16B'),
]
edoc_versions = {
'edocument.xrechnung.invoice': 'XRechnung-2.2',
'edocument.uncefact.invoice': '16B-CII',
}
class RunXRechnungReportStart(ModelView):
'eDocument Report'
'eDocument Export'
__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,
edocument = fields.Selection(string='Type', required=True,
selection=sel_edocument)
as_zip = fields.Boolean(string='ZIP-File')
@classmethod
def default_as_zip(cls):
""" default: True
"""
return True
@classmethod
def default_edocument(cls):
@ -34,21 +47,21 @@ class RunXRechnungReportStart(ModelView):
class RunXRechnungReport(Wizard):
'eDocument Report'
'eDocument Export'
__name__ = 'account_invoice_xrechnung.runrep'
start_state = 'open_'
start_state = 'start'
export = StateReport('account_invoice_xrechnung.export')
open_ = StateView(
start = 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='Cancel', state='end', icon='tryton-cancel'),
Button(string='Export', state='export', icon='tryton-export'),
],
)
def default_open_(self):
def default_start(self, fields):
""" set defaults
"""
context = Transaction().context
@ -60,20 +73,12 @@ class RunXRechnungReport(Wizard):
return result
def do_export(self, action):
""" run form
""" run export
"""
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'))
with open('x-rechnung.xml', 'wt') as fhdl:
fhdl.write(invoice_string.decode('utf8'))
return action, {}
return action, {
'invoice': self.start.invoice.id,
'edocument': self.start.edocument,
'as_zip': self.start.as_zip,
}
# end RunXRechnungReport