2022-10-20 12:43:58 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2023-06-30 09:21:48 +00:00
|
|
|
# This file is part of the account-invoice-xrechnung-module
|
|
|
|
# from m-ds for Tryton. The COPYRIGHT file at the top level of
|
|
|
|
# this repository contains the full copyright notices and license terms.
|
2022-10-20 12:43:58 +00:00
|
|
|
|
|
|
|
import zipfile
|
2024-12-05 16:32:56 +00:00
|
|
|
from facturx import generate_from_binary
|
2022-10-20 12:43:58 +00:00
|
|
|
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')
|
2024-12-05 16:32:56 +00:00
|
|
|
document_para = pool.get(data['edocument'].split('-')[0])
|
|
|
|
|
|
|
|
EDocument = document_para[0]
|
|
|
|
document_var = document_para[1] if len(document_para) > 1 else None
|
2022-10-20 12:43:58 +00:00
|
|
|
|
|
|
|
invoice, = Invoice.browse([data['invoice']])
|
|
|
|
template = EDocument(invoice)
|
2024-12-05 16:32:56 +00:00
|
|
|
invoice_xml = template.render(edoc_versions[data['edocument']])
|
2022-10-20 12:43:58 +00:00
|
|
|
|
|
|
|
file_name = slugify('%(date)s-%(descr)s' % {
|
2024-11-21 13:34:17 +00:00
|
|
|
'date': IrDate.today().isoformat().replace('-', ''),
|
|
|
|
'descr': invoice.rec_name},
|
|
|
|
max_length=100, word_boundary=True, save_order=True)
|
2022-10-20 12:43:58 +00:00
|
|
|
|
2024-12-05 16:32:56 +00:00
|
|
|
# if document_var and (
|
|
|
|
# document_var == 'ferd') and (
|
|
|
|
# EDocument.__name__ == 'edocument.facturxext.invoice'):
|
|
|
|
# # convert to zugferd
|
|
|
|
# pdf_data = generate_from_binary(
|
|
|
|
# pdf_file='pdf_content',
|
|
|
|
# xml=invoice_xml,
|
|
|
|
# check_xsd=True,
|
|
|
|
# pdf_metadata={
|
|
|
|
# 'author': invoice.company.rec_name,
|
|
|
|
# 'keywords': 'Factur-X, Invoice',
|
|
|
|
# 'title': invoice.number,
|
|
|
|
# 'subject': invoice.description},
|
|
|
|
# lang='de-DE')
|
|
|
|
|
2023-06-30 09:21:48 +00:00
|
|
|
if data['as_zip'] is True:
|
2022-10-20 12:43:58 +00:00
|
|
|
return (
|
|
|
|
'zip',
|
|
|
|
cls.compress_as_zip('%(fname)s.%(ext)s' % {
|
|
|
|
'fname': file_name,
|
|
|
|
'ext': 'xml',
|
2024-12-05 16:32:56 +00:00
|
|
|
}, invoice_xml),
|
2022-10-20 12:43:58 +00:00
|
|
|
False,
|
|
|
|
file_name)
|
2023-06-30 09:21:48 +00:00
|
|
|
else:
|
2024-12-05 16:32:56 +00:00
|
|
|
return ('xml', invoice_xml, False, file_name)
|
2022-10-20 12:43:58 +00:00
|
|
|
|
|
|
|
# end XReport
|