Skip to content
Snippets Groups Projects
Commit f936def6 authored by Mahdi Cheikh Rouhou (macr)'s avatar Mahdi Cheikh Rouhou (macr)
Browse files

[FIX] repair : send email to author when included

When we include the author in the recipients of the quotation email of a repair order he doesn't receive the email.

Steps to reproduce the error :
1- create a repiar order
2- add the author in the list of recipients
3- send the email

The origin of the problem is that mail_notify_author=False , se we need to add it as True when we have the author in the recipients.

Similar old fix : https://github.com/odoo/odoo/commit/f49dbf595c870b682f36c11443c9cf1a9a027474



opw-3295744

closes odoo/odoo#123036

Signed-off-by: default avatarWilliam Henrotin (whe) <whe@odoo.com>
parent 6f491e34
Branches
Tags
No related merge requests found
......@@ -6,3 +6,4 @@ from . import stock_traceability
from . import stock_production_lot
from . import account_move
from . import product
from . import mail_compose_message
# -*- 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 _action_send_mail(self, auto_commit=False):
if self.model == 'repair.order':
self = self.with_context(mail_notify_author=self.env.user.partner_id in self.partner_ids)
return super(MailComposeMessage, self)._action_send_mail(auto_commit=auto_commit)
......@@ -321,3 +321,28 @@ class TestRepair(AccountTestInvoicingCommon):
# tax02 should not be present since it belongs to the second company.
self.assertEqual(repair_order.operations.tax_id, tax01)
self.assertEqual(repair_order.fees_lines.tax_id, tax01)
def test_repair_order_send_to_self(self):
# when sender(logged in user) is also present in recipients of the mail composer,
# user should receive mail.
product_to_repair = self.product_product_5
partner = self.res_partner_address_1
repair_order = self.env['repair.order'].with_user(self.env.user).create({
'product_id': product_to_repair.id,
'product_uom': product_to_repair.uom_id.id,
'address_id': partner.id,
'guarantee_limit': '2019-01-01',
'location_id': self.stock_warehouse.lot_stock_id.id,
'partner_id': self.env.user.partner_id.id
})
email_ctx = repair_order.action_send_mail().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
repair_order.with_context(**email_ctx).with_user(self.env.user).message_post_with_template(mail_template.id)
mail_message = repair_order.message_ids[0]
self.assertEqual(mail_message.author_id, repair_order.partner_id, 'Repair: author should be same as customer')
self.assertEqual(mail_message.author_id, mail_message.partner_ids, 'Repair: 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, 'Repair: author should receive mail due to presence in composer recipients')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment