diff --git a/document.py b/document.py index 470a4ee..8767cd9 100644 --- a/document.py +++ b/document.py @@ -47,8 +47,9 @@ class Incoming(metaclass=PoolMeta): __name__ = 'document.incoming' xsd_type = fields.Char( - string='XML Content', readonly=True, - states={'invisible': Eval('mime_type', '') != 'application/xml'}) + string='Content Data', readonly=True, + states={'invisible': ~Eval('mime_type', '').in_( + ['application/xml', 'application/pdf'])}) @classmethod def default_company(cls): @@ -72,7 +73,7 @@ class Incoming(metaclass=PoolMeta): """ invoice = super()._process_supplier_invoice() - if self.mime_type == 'application/xml': + if self.mime_type in ['application/xml', 'application/pdf']: # detect xml-content xml_info = self._facturx_detect_content() if xml_info: @@ -1037,7 +1038,23 @@ class Incoming(metaclass=PoolMeta): tuple: ('xsd tyle', '', ) defaults to None if not detected """ - xml_data = etree.fromstring(self.data) + if self.mime_type == 'application/xml': + xml_data = etree.fromstring(self.data) + elif self.mime_type == 'application/pdf': + try: + (xml_filename, xml_bytes) = facturx.get_xml_from_pdf( + self.data, check_xsd=True) + xml_data = etree.fromstring(xml_bytes) + except Exception as e1: + raise UserError(gettext( + 'document_incoming_invoice_xml.msg_convert_error', + msg=str(e1))) + else: + raise UserError(gettext( + 'document_incoming_invoice_xml.msg_convert_error', + msg='content-type "%(mime)s" not supported' % { + 'mime': self.mime_type})) + fx_flavour = facturx.get_flavor(xml_data) fx_level = facturx.get_level(xml_data) @@ -1052,7 +1069,9 @@ class Incoming(metaclass=PoolMeta): schema = etree.XMLSchema(etree.parse(fname)) try: schema.assertValid(xml_data) - self.xsd_type = xsdtype + self.xsd_type = ( + xsdtype if self.mime_type == 'application/xml' + else 'PDF + ' + xsdtype) return (xsdtype, funcname, xml_data) except etree.DocumentInvalid as e1: # fire exception for knows xml-content diff --git a/locale/de.po b/locale/de.po index 5f8d1e0..396b479 100644 --- a/locale/de.po +++ b/locale/de.po @@ -91,6 +91,7 @@ msgid "Categories used to determine tax and accounts for a product on an invoice msgstr "Kategorien zur Ermittlung von Steuer und Konten für ein Produkt auf einer Rechnungszeile." + ##################################### # document.incoming.confprodcat_rel # ##################################### @@ -105,3 +106,11 @@ msgstr "konfiguration" msgctxt "field:document.incoming.confprodcat_rel,category:" msgid "Category" msgstr "Kategorie" + + +##################### +# document.incoming # +##################### +msgctxt "field:document.incoming,xsd_type:" +msgid "Content Data" +msgstr "Dateninhalt" diff --git a/locale/en.po b/locale/en.po index aec4cc4..24dbbdf 100644 --- a/locale/en.po +++ b/locale/en.po @@ -94,3 +94,6 @@ msgctxt "field:document.incoming.confprodcat_rel,category:" msgid "Category" msgstr "Category" +msgctxt "field:document.incoming,xsd_type:" +msgid "Content Data" +msgstr "Content Data" diff --git a/tests/invoice-fx-basic.pdf b/tests/invoice-fx-basic.pdf new file mode 100644 index 0000000..20978b4 Binary files /dev/null and b/tests/invoice-fx-basic.pdf differ