summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNasreddin (bon) <bon@odoo.com>2021-01-06 14:31:09 +0000
committerBenjamin Frantzen (bfr) <bfr@odoo.com>2021-02-15 14:03:20 +0000
commit0f6ad2a690f76d6bbbe92106fc8360f99eaac6c2 (patch)
tree0814b7ee4ae155e7f8b7358913535167d3d06944
parent04424cddf1e28a52fd7df3ad954d2d484b52972e (diff)
[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#64286 X-original-commit: 9076b1ba0b7279a9da45f4e52d5203ad7b5710a0 Signed-off-by: bon-odoo <nboulif@users.noreply.github.com> Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
-rw-r--r--addons/account/models/account_move.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py
index 6353a8fb7df..0e3b3823aed 100644
--- a/addons/account/models/account_move.py
+++ b/addons/account/models/account_move.py
@@ -2844,17 +2844,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.'),