akretion / factur-x

Python lib for Factur-X, the e-invoicing standard for France and Germany
Other
170 stars 56 forks source link

[MIG] Python3 #9

Closed joshuajan closed 5 years ago

joshuajan commented 5 years ago

Dear @alexis-via

Thanks for your job. We want to use the Chorus module in Odoo V12. And we have upgrade some module to V12. Here is the PR for factur-x py3.

Thank you.

alexis-via commented 5 years ago

Thanks for this very interesting contribution ! Do you think that, with your PR, factur-x would work both in python2 and python3 ? Or would it only work in python3 ?

JulienPalard commented 5 years ago

Not sure if it's due to the migration or not, yet, but I tried in Python 3.7.2, with the examples from http://fnfe-mpe.org/factur-x/ and it failed:

$ facturx-pdfextractxml --log-level=debug Facture_DOM_BASIC.pdf  Facture_DOM_BASIC.pdf.xml
2019-01-11 00:02:47,172 [DEBUG] pdf_root={'/AF': IndirectObject(9, 0), '/Type': '/Catalog', '/Names': {'/EmbeddedFiles': {'/Names': ['factur-x.xml', IndirectObject(5, 0)]}}, '/OutputIntents': [IndirectObject(7, 0)], '/Metadata': IndirectObject(8, 0), '/Pages': IndirectObject(1, 0), '/PageMode': '/UseAttachments'}
2019-01-11 00:02:47,172 [DEBUG] embeddedfiles=['factur-x.xml', IndirectObject(5, 0)]
2019-01-11 00:02:47,172 [ERROR] No valid XML file found in the PDF
DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead [facturx-pdfextractxml:80]
2019-01-11 00:02:47,172 [WARNING] File Facture_DOM_BASIC.pdf.xml has not been created
JulienPalard commented 5 years ago

Can confirm, it works with Python 2.7:

$ facturx-pdfextractxml --log-level=debug Facture_DOM_BASIC.pdf  Facture_DOM_BASIC.pdf.xml
PdfReadWarning: PdfFileReader stream/file object is not in binary mode. It may not be read correctly. [pdf.py:1079]
2019-01-11 00:06:21,667 [DEBUG] pdf_root={'/AF': IndirectObject(9, 0), '/Type': '/Catalog', '/Names': {'/EmbeddedFiles': {'/Names': [u'factur-x.xml', IndirectObject(5, 0)]}}, '/OutputIntents': [IndirectObject(7, 0)], '/Pages': IndirectObject(1, 0), '/PageMode': '/UseAttachments', '/Metadata': IndirectObject(8, 0)}
2019-01-11 00:06:21,667 [DEBUG] embeddedfiles=[u'factur-x.xml', IndirectObject(5, 0)]
2019-01-11 00:06:21,667 [DEBUG] embeddedfiles_by_two=[(u'factur-x.xml', IndirectObject(5, 0))]
2019-01-11 00:06:21,667 [DEBUG] found filename=factur-x.xml
2019-01-11 00:06:21,668 [DEBUG] xml_file_dict={'/Type': '/Filespec', '/AFRelationship': '/Data', '/F': u'factur-x.xml', '/Desc': u'Factur-X Invoice', '/UF': u'factur-x.xml', '/EF': {'/F': IndirectObject(4, 0), '/UF': IndirectObject(4, 0)}}
2019-01-11 00:06:21,668 [INFO] A valid XML file factur-x.xml has been found in the PDF file
JulienPalard commented 5 years ago

Oh, this is line 177 of facturx.py, TypeError: 'zip' object is not subscriptable.

joshuajan commented 5 years ago

Hello @JulienPalard I have update the code. and I have test the script both in python2 and python3.