[FIX] account_facturx: Parse pdf attachment

Solution is different in the case of the foward-port, see bellow.

Issue

	- Init an instances of Odoo v13.0 'A' and v14.0 'B'.
	- Install "Accounting" app on instance A & B.
	- Set your email server on instance A & B.
	- Activate 'External email server' in settings of instance A.
	- Set an email alias for "Vendor Bills" on instance A.
	- Send a "Customer Invoice" from instance B to alias of instance A.
	- Fetch for new mail (in case new vendor bill don't appear) on instance A.
	- Open the new Vendor bill on instance A.

	Data are not parsed from pdf attachment.

Cause

	No managing all attachements types:
	- list(tuple(str,str), tuple(str,str, dict) or int) attachments : list of attachment tuples in the form
          ``(name,content)`` or ``(name,content, info)``, where content is NOT base64 encoded
	- list id attachment_ids: list of existing attachement to link to this message
          - Should only be setted by chatter
          - Attachement object attached to mail.compose.message(0) will be attached
            to the related document.

Solution

	In this fw-port, we override `_message_post_after_hook` instead of
	`_message_post_process_attachments` because the later is also called
	from portal and with sudo rights. We don't want to update invoices with
	files coming from portal, since it could cause a security issue.
	Also, because of the way attachments are parsed for invoice, this could
	cause the OCR not to work any longer because at the time
	`_message_post_process_attachments` is called,`move.message_main_attachment_id`
	is not set yet, and OCR relies on it.
	The solution is rather to override `_message_post_after_hook` because
	it ensures that all the attachments have been properly treated and are
	present in `new_message.attachment_ids`, and `message_main_attachment_id`
	is properly set.

opw-2411002

closes odoo/odoo#66458

X-original-commit: 0f6ad2a690f76d6bbbe92106fc8360f99eaac6c2
Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
Signed-off-by: bon-odoo <nboulif@users.noreply.github.com>
This commit is contained in:
Nasreddin (bon)
2021-02-18 12:48:34 +00:00
committed by Benjamin Frantzen (bfr)
parent d4b6ee53f9
commit f234b4fba4
+4 -6
View File
@@ -2892,17 +2892,15 @@ class AccountMove(models.Model):
return rslt
@api.returns('mail.message', lambda value: value.id)
def message_post(self, **kwargs):
def _message_post_after_hook(self, new_message, message_values):
# OVERRIDE
# When posting a message, check the attachment to see if it's an invoice and update with the imported data.
res = super().message_post(**kwargs)
res = super()._message_post_after_hook(new_message, message_values)
attachment_ids = kwargs.get('attachment_ids', [])
if len(self) != 1 or not attachment_ids or self.env.context.get('no_new_invoice') or not self.is_invoice(include_receipts=True):
attachments = new_message.attachment_ids
if len(self) != 1 or not attachments or self.env.context.get('no_new_invoice') or not self.is_invoice(include_receipts=True):
return res
attachments = self.env['ir.attachment'].browse(attachment_ids)
odoobot = self.env.ref('base.partner_root')
if attachments and self.state != 'draft':
self.message_post(body=_('The invoice is not a draft, it was not updated from the attachment.'),