diff options
| author | Dharmraj Jhala <dja@odoo.com> | 2020-07-15 10:42:44 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2020-08-24 06:57:33 +0000 |
| commit | 08c0dc929da38595e29a9d1db93065547cd98ad1 (patch) | |
| tree | a2fa1dd3435e1136f30d2a17db6b4ab1ca44a41f /addons | |
| parent | 47f5e14eca4e13010cc11f688ea92f65a2695d38 (diff) | |
[IMP] account, purchase, sale: allow sending email to self
Currently, if users try to send invoices / quotations / purchase orders to
themselves in order to look at final result, they can't do so because our
default chatter protection prevents sending mails to authors themselves.
This commit uses 'mail_notify_author' context key and allows users to send
mails from the header buttons available on SO / PO / invoices to themselves
if they are in recipients.
This commit targets only those buttons as this is the main case where we
want to allow people to send emails to themselves. In order to avoid
side effects no other use case is supported.
Task ID-2294130
closes odoo/odoo#55809
X-original-commit: 09918f320ba712b0bd90a6852825fad864655b04
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/account/wizard/account_invoice_send.py | 2 | ||||
| -rw-r--r-- | addons/purchase/models/__init__.py | 1 | ||||
| -rw-r--r-- | addons/purchase/models/mail_compose_message.py | 13 | ||||
| -rw-r--r-- | addons/sale/models/__init__.py | 1 | ||||
| -rw-r--r-- | addons/sale/models/mail_compose_message.py | 13 | ||||
| -rw-r--r-- | addons/sale/tests/test_sale_order.py | 25 |
6 files changed, 54 insertions, 1 deletions
diff --git a/addons/account/wizard/account_invoice_send.py b/addons/account/wizard/account_invoice_send.py index 3529e2a9fe7..daf1ae3cfe0 100644 --- a/addons/account/wizard/account_invoice_send.py +++ b/addons/account/wizard/account_invoice_send.py @@ -86,7 +86,7 @@ class AccountInvoiceSend(models.TransientModel): def _send_email(self): if self.is_email: # with_context : we don't want to reimport the file we just exported. - self.composer_id.with_context(no_new_invoice=True).send_mail() + self.composer_id.with_context(no_new_invoice=True, mail_notify_author=self.env.user.partner_id in self.composer_id.partner_ids).send_mail() if self.env.context.get('mark_invoice_as_sent'): #Salesman send posted invoice, without the right to write #but they should have the right to change this flag diff --git a/addons/purchase/models/__init__.py b/addons/purchase/models/__init__.py index a641ce05a71..f2f1fa553dc 100644 --- a/addons/purchase/models/__init__.py +++ b/addons/purchase/models/__init__.py @@ -7,3 +7,4 @@ from . import product from . import res_company from . import res_config_settings from . import res_partner +from . import mail_compose_message diff --git a/addons/purchase/models/mail_compose_message.py b/addons/purchase/models/mail_compose_message.py new file mode 100644 index 00000000000..a82e59244cf --- /dev/null +++ b/addons/purchase/models/mail_compose_message.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# purches Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models + + +class MailComposeMessage(models.TransientModel): + _inherit = 'mail.compose.message' + + def send_mail(self, auto_commit=False): + if self.env.context.get('mark_rfq_as_sent') and self.model == 'purchase.order': + self = self.with_context(mail_notify_author=self.env.user.partner_id in self.partner_ids) + return super(MailComposeMessage, self).send_mail(auto_commit=auto_commit) diff --git a/addons/sale/models/__init__.py b/addons/sale/models/__init__.py index 00d0b15fad0..92e9953d654 100644 --- a/addons/sale/models/__init__.py +++ b/addons/sale/models/__init__.py @@ -13,3 +13,4 @@ from . import res_config_settings from . import sales_team from . import payment from . import utm +from . import mail_compose_message diff --git a/addons/sale/models/mail_compose_message.py b/addons/sale/models/mail_compose_message.py new file mode 100644 index 00000000000..1b06a23c1fb --- /dev/null +++ b/addons/sale/models/mail_compose_message.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models + + +class MailComposeMessage(models.TransientModel): + _inherit = 'mail.compose.message' + + def send_mail(self, auto_commit=False): + if self.env.context.get('mark_so_as_sent') and self.model == 'sale.order': + self = self.with_context(mail_notify_author=self.env.user.partner_id in self.partner_ids) + return super(MailComposeMessage, self).send_mail(auto_commit=auto_commit) diff --git a/addons/sale/tests/test_sale_order.py b/addons/sale/tests/test_sale_order.py index 59b8553da78..5f8abd34470 100644 --- a/addons/sale/tests/test_sale_order.py +++ b/addons/sale/tests/test_sale_order.py @@ -126,6 +126,31 @@ class TestSaleOrder(TestSaleCommon): self.assertEqual(invoice3.amount_total, 720.0, 'Sale: second invoice total amount is wrong') self.assertTrue(self.sale_order.invoice_status == 'invoiced', 'Sale: SO status after invoicing everything (including the upsel) should be "invoiced"') + def test_sale_order_send_to_self(self): + # when sender(logged in user) is also present in recipients of the mail composer, + # user should receive mail. + sale_order = self.env['sale.order'].with_user(self.company_data['default_user_salesman']).create({ + 'partner_id': self.company_data['default_user_salesman'].partner_id.id, + 'order_line': [[0, 0, { + 'name': self.company_data['product_order_no'].name, + 'product_id': self.company_data['product_order_no'].id, + 'product_uom_qty': 1, + 'price_unit': self.company_data['product_order_no'].list_price, + }]] + }) + email_ctx = sale_order.action_quotation_send().get('context', {}) + # We need to prevent auto mail deletion, and so we copy the template and send the mail with + # added configuration in copied template. It will allow us to check whether mail is being + # sent to to author or not (in case author is present in 'Recipients' of composer). + mail_template = self.env['mail.template'].browse(email_ctx.get('default_template_id')).copy({'auto_delete': False}) + # send the mail with same user as customer + sale_order.with_context(**email_ctx).with_user(self.company_data['default_user_salesman']).message_post_with_template(mail_template.id) + self.assertTrue(sale_order.state == 'sent', 'Sale : state should be changed to sent') + mail_message = sale_order.message_ids[0] + self.assertEqual(mail_message.author_id, sale_order.partner_id, 'Sale: author should be same as customer') + self.assertEqual(mail_message.author_id, mail_message.partner_ids, 'Sale: author should be in composer recipients thanks to "partner_to" field set on template') + self.assertEqual(mail_message.partner_ids, mail_message.sudo().mail_ids.recipient_ids, 'Sale: author should receive mail due to presence in composer recipients') + def test_sale_sequence(self): self.env['ir.sequence'].search([ ('code', '=', 'sale.order'), |
