prepare zugferd

This commit is contained in:
Frederik Jaeckel 2024-12-05 17:32:56 +01:00
parent d932e15878
commit 042e1b9a56
2 changed files with 155 additions and 8 deletions

View file

@ -4,6 +4,7 @@
# this repository contains the full copyright notices and license terms.
import zipfile
from facturx import generate_from_binary
from io import BytesIO
from trytond.report import Report
from trytond.pool import Pool
@ -31,27 +32,45 @@ class XReport(Report):
pool = Pool()
IrDate = pool.get('ir.date')
Invoice = pool.get('account.invoice')
EDocument = pool.get(data['edocument'].split('-')[0])
document_para = pool.get(data['edocument'].split('-')[0])
EDocument = document_para[0]
document_var = document_para[1] if len(document_para) > 1 else None
invoice, = Invoice.browse([data['invoice']])
template = EDocument(invoice)
invoice_string = template.render(edoc_versions[data['edocument']])
invoice_xml = 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 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')
if data['as_zip'] is True:
return (
'zip',
cls.compress_as_zip('%(fname)s.%(ext)s' % {
'fname': file_name,
'ext': 'xml',
}, invoice_string),
}, invoice_xml),
False,
file_name)
else:
return ('xml', invoice_string, False, file_name)
return ('xml', invoice_xml, False, file_name)
# end XReport