add pdf-import

This commit is contained in:
Frederik Jaeckel 2025-01-22 18:31:40 +01:00
parent 037ff9636a
commit c25ad51d75
4 changed files with 36 additions and 5 deletions

View file

@ -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', '<function to read xml>', <xml etree>)
defaults to None if not detected
"""
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

View file

@ -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"

View file

@ -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"

BIN
tests/invoice-fx-basic.pdf Normal file

Binary file not shown.