From f234b4fba40d3c0d7e5b4828dbbd033f6a667ea2 Mon Sep 17 00:00:00 2001 From: "Nasreddin (bon)" Date: Wed, 6 Jan 2021 14:31:09 +0000 Subject: [PATCH] [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 Signed-off-by: bon-odoo --- addons/account/models/account_move.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index db0837ebdc9..fd07c82bb42 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -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.'),