# -*- 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. import zipfile from io import BytesIO from trytond.report import Report from trytond.pool import Pool from slugify import slugify from .wizard_runreport import edoc_versions class XReport(Report): 'eDocument Export' __name__ = 'account_invoice_xrechnung.export' @classmethod def compress_as_zip(cls, fname, data): """ compress """ content = BytesIO() with zipfile.ZipFile(content, 'w') as content_zip: content_zip.writestr(fname, data) return content.getvalue() @classmethod def execute(cls, ids, data): """ skip export-engine, run edocument-xml-convert """ pool = Pool() IrDate = pool.get('ir.date') Invoice = pool.get('account.invoice') EDocument = pool.get(data['edocument']) invoice, = Invoice.browse([data['invoice']]) template = EDocument(invoice) invoice_string = template.render(edoc_versions[data['edocument']]) file_name = slugify('%(date)s-%(descr)s' % { 'date': IrDate.today().isoformat().replace('-', ''), 'descr': invoice.rec_name, }, max_length=100, word_boundary=True, save_order=True) if data['as_zip'] == True: return ( 'zip', cls.compress_as_zip('%(fname)s.%(ext)s' % { 'fname': file_name, 'ext': 'xml', }, invoice_string), False, file_name) else : return ('xml', invoice_string, False, file_name) # end XReport