diff options
| author | Adrien Widart <awt@odoo.com> | 2021-05-04 14:51:12 +0000 |
|---|---|---|
| committer | Adrien Widart <awt@odoo.com> | 2021-05-31 07:21:02 +0000 |
| commit | e6c69a8cf00cd858a45ebf321a190666322c0897 (patch) | |
| tree | 1655dcd9a1ffe86dfe6df832cb70280d021afa00 /addons/account/models | |
| parent | 9cdde27e25b13714e24082a50673454693c954ef (diff) | |
[FIX] account, mail: link attachments to invoice
When using the "Send & Print" functionality, if the user adds an
attachment, the latter won't be linked to the record.
To reproduce the error:
1. Open a posted invoice
2. Send & Print
3. Attach a file > Select a file on your device
4. Send the email
Error: The invoice's PDF is added to record's attachments, but not the
other file (from step 3).
When the module selects the attachments that need to be linked to the
invoice, it only keeps the ones currently linked to `mail.compose.message`:
https://github.com/odoo/odoo/blob/6441ab71cb68648aa735057952bf757677a20ee3/addons/mail/models/mail_thread.py#L1719-L1725
This is correct when the user creates a message directly in the chatter.
However, when the mail is created thanks to `Send & Print` functionality,
the attachment is linked to `account.invoice.send`.
Another flow have a similar issue: from invoices list, select few ones,
Action > Send & Print: the generated PDF won't be attached to their
invoice. In such a situation, here is the source of the problem:
https://github.com/odoo/odoo/blob/05ad6c477f7da2a495e5baf5b4629323b9d11fa0/addons/mail/wizard/mail_compose_message.py#L363-L367
There isn't any information about the invoice, therefore it is not
possible to linked the attachment to it.
OPW-2438457
closes odoo/odoo#71425
X-original-commit: e87f599d4eb22250b628d650b9f59b54db8d043c
Signed-off-by: Adrien Widart <adwid@users.noreply.github.com>
Diffstat (limited to 'addons/account/models')
| -rw-r--r-- | addons/account/models/__init__.py | 1 | ||||
| -rw-r--r-- | addons/account/models/mail_thread.py | 27 |
2 files changed, 28 insertions, 0 deletions
diff --git a/addons/account/models/__init__.py b/addons/account/models/__init__.py index d9e2695b020..a8c6e8936a1 100644 --- a/addons/account/models/__init__.py +++ b/addons/account/models/__init__.py @@ -29,3 +29,4 @@ from . import res_users from . import ir_actions_report from . import res_currency from . import res_bank +from . import mail_thread diff --git a/addons/account/models/mail_thread.py b/addons/account/models/mail_thread.py new file mode 100644 index 00000000000..cf396c93e8e --- /dev/null +++ b/addons/account/models/mail_thread.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models + +class MailThread(models.AbstractModel): + _inherit = 'mail.thread' + + def _message_post_process_attachments(self, attachments, attachment_ids, message_values): + """ This method extension ensures that, when using the "Send & Print" feature, if the user + adds an attachment, the latter will be linked to the record. """ + record = self.env.context.get('attached_to') + # link mail.compose.message attachments to attached_to + if record and record._name == 'account.move': + message_values['model'] = record._name + message_values['res_id'] = record.id + res = super()._message_post_process_attachments(attachments, attachment_ids, message_values) + # link account.invoice.send attachments to attached_to + model = message_values['model'] + res_id = message_values['res_id'] + att_ids = [att[1] for att in res.get('attachment_ids') or []] + if att_ids and model == 'account.move': + filtered_attachment_ids = self.env['ir.attachment'].sudo().browse(att_ids).filtered( + lambda a: a.res_model in ('account.invoice.send',) and a.create_uid.id == self._uid) + if filtered_attachment_ids: + filtered_attachment_ids.write({'res_model': model, 'res_id': res_id}) + return res |
