summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--addons/account/models/__init__.py1
-rw-r--r--addons/account/models/mail_thread.py27
-rw-r--r--addons/mail/wizard/mail_compose_message.py2
-rw-r--r--addons/web/static/src/js/views/graph/graph_renderer.js2
4 files changed, 30 insertions, 2 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
diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py
index 3384b32f94e..327cad2bc8b 100644
--- a/addons/mail/wizard/mail_compose_message.py
+++ b/addons/mail/wizard/mail_compose_message.py
@@ -336,7 +336,7 @@ class MailComposer(models.TransientModel):
new_attach_id = self.env['ir.attachment'].browse(attach_id).copy({'res_model': self._name, 'res_id': self.id})
attachment_ids.append(new_attach_id.id)
attachment_ids.reverse()
- mail_values['attachment_ids'] = self.env['mail.thread']._message_post_process_attachments(
+ mail_values['attachment_ids'] = self.env['mail.thread'].with_context(attached_to=record)._message_post_process_attachments(
mail_values.pop('attachments', []),
attachment_ids,
{'model': 'mail.message', 'res_id': 0}
diff --git a/addons/web/static/src/js/views/graph/graph_renderer.js b/addons/web/static/src/js/views/graph/graph_renderer.js
index 118245f997b..f6fb1ede893 100644
--- a/addons/web/static/src/js/views/graph/graph_renderer.js
+++ b/addons/web/static/src/js/views/graph/graph_renderer.js
@@ -222,7 +222,7 @@ return AbstractRenderer.extend({
counts += dataPt.count;
});
// data points with zero count might have been created on purpose
- // we only remove them if there are no data point with positive count
+ // we only remove them if there are no data point with positive countaddons/account/models/__init__.py
if (counts === 0) {
dataPoints = [];
}