Skip to Content
Menu
This question has been flagged

Hello,

In res.partner module i create field and in compute i write a code to get the last date for Archived leads.

Code work but i wanna use this in Automated actions, in every update at crm.lead

So i put this code to (Automation->Automated Action --> and in server action i create the item and use Execute Python Code. I put my code from compute field but it don't works.

I search some tutorials how to do this but i can't found nothing.

I would like to ask someone to modify my code how it's need to proper look, after that i will be know how to do this in future.


The code:


tab=[]
fmt = '%Y-%m-%d'
for record in self:
 id = record.id
 data = self.env['crm.lead'].search_read([('partner_id', '=', id), ('active', '=', False)], ['date_closed'])
 data_active = self.env['crm.lead'].search_read([('partner_id', '=', id), ('active', '=', True)], ['id'])
 zakres_active = len(data_active)
 zakres = len(data)
 if data:
     for x in xrange(zakres):
         tab.append(data[x]['date_closed'])
 data_max =max(tab)
 data_none = None
 if zakres_active > 0 :
        record['x_przypomnienie_debug'] = None
        self.env.cr.execute(""" UPDATE res_partner SET x_przypomnienie =Null WHERE id = %s"""     %(id))
 else:
        record['x_przypomnienie_debug'] = data_max
        self.env.cr.execute(""" UPDATE res_partner SET x_przypomnienie = '%s' WHERE id = %s"""     %(data_max,id))




Avatar
Discard
Related Posts Replies Views Activity
2
May 20
4506
0
Feb 17
1798
1
Jan 16
5236
4
Jan 16
5202
2
Feb 23
2905