summaryrefslogtreecommitdiff
path: root/addons/account/models/mail_thread.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/account/models/mail_thread.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/account/models/mail_thread.py')
-rw-r--r--addons/account/models/mail_thread.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/addons/account/models/mail_thread.py b/addons/account/models/mail_thread.py
new file mode 100644
index 00000000..cf396c93
--- /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