Skip to Content
Menu
This question has been flagged
1 Reply
2803 Views

Once done schedule activity then I will click " Mark as done" button to trigger email to who created schedule activity Please help me ?

Avatar
Discard
Best Answer

from odoo import api, fields, models, _

class MailActivity(models.Model):

    _inherit = "mail.activity"

    def action_feedback(self, feedback=False):

        message = self.env['mail.message']

        for rec in self.filtered(lambda m: m.res_model in ['sale.order', 'account.invoice', 'purchase.order', 'tac.purchase.shipment', 'sale.agreement','helpdesk.ticket']):

            # Check Activity Create and Assigned User

            if self.create_user_id != self.user_id and self.create_user_id.id not in (1, 2) and self.user_id.id not in (1, 2):

                # Send Email For Sale Order

                if self.res_model == 'sale.order':

                    server_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url', default='http://yourdomain.com')

                    form_view = self.env.ref('sale.view_order_form')

                    server_url = server_url + "/web?#id=%s&action_id=%s&model=%s" % (

                        self.res_id, form_view.id, self.res_model)

                    obj = self.env['sale.order'].browse(self.res_id)

                    if self.create_user_id.login:

                        mail_template = self.env.ref('tac_activity_notification.tac_email_template_mail_activity_done')

                        if mail_template:

                            mail_template.with_context(feedback=feedback, server_url=server_url, obj=obj.name).send_mail(self.id, force_send=True, email_values={'email_to': self.create_user_id.login})

        if feedback:

            self.write(dict(feedback=feedback))

        for activity in self:

            record = self.env[activity.res_model].browse(activity.res_id)

            record.message_post_with_view(

                'mail.message_activity_done',

                values={'activity': activity},

                subtype_id=self.env['ir.model.data'].xmlid_to_res_id('mail.mt_activities'),

                mail_activity_type_id=activity.activity_type_id.id,

            )

            message |= record.message_ids[0]

        self.unlink()

        return message.ids and message.ids[0] or False

Avatar
Discard