[FIX] account_edi: exception during import of attachment is handled
When an exception is raised when importing an attachment with an edi.format, we try with the next edi.format (or stop if it was the last) instead of crashing. closes odoo/odoo#56292 Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
This commit is contained in:
@@ -339,11 +339,14 @@ class AccountEdiFormat(models.Model):
|
||||
for file_data in self._decode_attachment(attachment):
|
||||
for edi_format in self:
|
||||
res = False
|
||||
if file_data['type'] == 'xml':
|
||||
res = edi_format._create_invoice_from_xml_tree(file_data['filename'], file_data['xml_tree'])
|
||||
elif file_data['type'] == 'pdf':
|
||||
res = edi_format._create_invoice_from_pdf_reader(file_data['filename'], file_data['pdf_reader'])
|
||||
file_data['pdf_reader'].stream.close()
|
||||
try:
|
||||
if file_data['type'] == 'xml':
|
||||
res = edi_format._create_invoice_from_xml_tree(file_data['filename'], file_data['xml_tree'])
|
||||
elif file_data['type'] == 'pdf':
|
||||
res = edi_format._create_invoice_from_pdf_reader(file_data['filename'], file_data['pdf_reader'])
|
||||
file_data['pdf_reader'].stream.close()
|
||||
except Exception as e:
|
||||
_logger.exception("Error importing attachment \"%s\" as invoice with format \"%s\"", file_data['filename'], edi_format.name, str(e))
|
||||
if res:
|
||||
if 'extract_state' in res:
|
||||
# Bypass the OCR to prevent overwriting data when an EDI was succesfully imported.
|
||||
@@ -361,11 +364,14 @@ class AccountEdiFormat(models.Model):
|
||||
for file_data in self._decode_attachment(attachment):
|
||||
for edi_format in self:
|
||||
res = False
|
||||
if file_data['type'] == 'xml':
|
||||
res = edi_format._update_invoice_from_xml_tree(file_data['filename'], file_data['xml_tree'], invoice)
|
||||
elif file_data['type'] == 'pdf':
|
||||
res = edi_format._update_invoice_from_pdf_reader(file_data['filename'], file_data['pdf_reader'], invoice)
|
||||
file_data['pdf_reader'].stream.close()
|
||||
try:
|
||||
if file_data['type'] == 'xml':
|
||||
res = edi_format._update_invoice_from_xml_tree(file_data['filename'], file_data['xml_tree'], invoice)
|
||||
elif file_data['type'] == 'pdf':
|
||||
res = edi_format._update_invoice_from_pdf_reader(file_data['filename'], file_data['pdf_reader'], invoice)
|
||||
file_data['pdf_reader'].stream.close()
|
||||
except Exception as e:
|
||||
_logger.exception("Error importing attachment \"%s\" as invoice with format \"%s\"", file_data['filename'], edi_format.name, str(e))
|
||||
if res:
|
||||
if 'extract_state' in res:
|
||||
# Bypass the OCR to prevent overwriting data when an EDI was succesfully imported.
|
||||
|
||||
Reference in New Issue
Block a user