Skip to Content
Menu
This question has been flagged

Hi Community,

Please read attentionally and give me valid suggetion

I have one dropdown field and when i add the user in dropdown list that same user added in Followers and sanding the mail to the Added user. so my problem is that for example i added two records rec1 and rec2  in dropdown and save then when i update the same records i remove the rec1 from dropdown and save the record that time system send the mail to the rec2. i don't sand the email to the already added user so how to solve this. if you know please suggest me.

see my code and tell me where i'm wrong.

@api.model
def create(self, vals):
    lead_res = super(CrmLead, self).create(vals)
    for rec in lead_res:
    if rec.estimation_id:
        partner_ids = []
        for est_rec in rec.estimation_id:
            if est_rec.partner_id and est_rec.partner_id.email:
                partner_ids.append(est_rec.partner_id.id)
                template_obj = self.env['mail.mail']
                template_data = {
                                                'subject': 'New Estimation Asign : ',
                                                'body_html': "message_body",
                                                'email_from': self.env['mail.message']._get_default_from(),
                                                'email_to': est_rec.partner_id.email
                                            }
                template_id = template_obj.create(template_data)
                template_obj.send(template_id)
                if partner_ids:
                    rec.message_subscribe(partner_ids, None)
    return lead_res

    @api.multi
    def write(self, vals):
        res = super(CrmLead, self).write(vals)
        for rec in self:
            if rec.estimation_id:
                partner_ids = []
                for est_rec in rec.estimation_id:
                    if est_rec.partner_id and est_rec.partner_id.email:
                        partner_ids.append(est_rec.partner_id.id)
                        template_obj = self.env['mail.mail']
                        template_data = {
                                                         'subject': 'New Estimation Asign : ',
                                                        'body_html': "message_body",
                                                        'email_from': self.env['mail.message']._get_default_from(),
                                                        'email_to': est_rec.partner_id.email
                                                }
                        template_id = template_obj.create(template_data)
                        template_obj.send(template_id)
                        rec.message_subscribe(partner_ids, None)
                        #message_unsubscribe
                        message_partner_ids = rec.message_partner_ids.ids
                         est_ids = [est_rec.partner_id.id for est_rec in rec.estimation_id] + [self.env.ref('base.partner_root').id]
                        unsub_partners = set(message_partner_ids) - set(est_ids)

                        if list(unsub_partners):
                            rec.message_unsubscribe(list(unsub_partners))
            else:
                print("+++++============= Else Part =============+++++")
        return res

Avatar
Discard
Related Posts Replies Views Activity
3
Nov 19
4149
1
Mar 20
7335
3
Nov 19
6437
3
Dec 19
4701
0
Oct 19
92