Hello everyone,
I am currently seeking assistance with setting up a cron job in Odoo v16 on odoo.sh.
Specifically, I want to create a script that adds an activity to all 'opportunities' in the CRM module that are not 'won', provided there is no existing activity.
Here is the script I have written so far:
leads = env['crm.lead'].search([('activity_ids', '=', False), ('probability', '
for i in range(0, len(leads), 10):
batch_leads = leads[i:i+10]
for lead in batch_leads:
activity = env['mail.activity'].create({
'res_id': lead.id,
'res_model_id': env.ref('crm.model_crm_lead').id,
'activity_type_id': 13,
'date_deadline': datetime.datetime.today().strftime('%Y-%m-%d %H:%M'),
'user_id': lead.user_id.id,
})
lead.write({'activity_ids': [(4, activity.id)]})
However, this script does not seem to work as expected. If anyone could provide guidance or suggestions to correct this script, I would greatly appreciate it.
Thank you in advance for your help and support.
Best regards
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Boekhouding
- Voorraad
- PoS
- Project
- MRP
Deze vraag is gerapporteerd
working script - missing was the last line: env.cr.commit()
leads = env['crm.lead'].search([('activity_ids', '=', False), ('probability', '
for i in range(0, len(leads), 10):
batch_leads = leads[i:i+10]
for lead in batch_leads:
activity = env['mail.activity'].create({
'res_id': lead.id,
'res_model_id': env.ref('crm.model_crm_lead').id,
'activity_type_id': 30,
'date_deadline': datetime.datetime.today().strftime('%Y-%m-%d %H:%M'),
'user_id': lead.user_id.id,
})
lead.write({'activity_ids': [(4, activity.id)]})
Hi,
Please update your code like this and try, it was verified working,
leads = env['crm.lead'].search([('activity_ids', '=', False), ('probability', '
for i in range(0, len(leads), 10):
batch_leads = leads[i:i+10]
for lead in batch_leads:
activity = env['mail.activity'].create({
'res_id': lead.id,
'res_model_id': env.ref('crm.model_crm_lead').id,
'activity_type_id': 13,
'date_deadline': datetime.datetime.today().strftime('%Y-%m-%d %H:%M'),
'user_id': lead.user_id.id,
})
lead.write({'activity_ids': [(4, activity.id)]})
Thanks
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!
Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!
AanmeldenGerelateerde posts | Antwoorden | Weergaven | Activiteit | |
---|---|---|---|---|
|
2
aug. 25
|
982 | ||
|
2
mei 25
|
1879 | ||
|
1
apr. 25
|
1805 | ||
|
0
mrt. 25
|
1777 | ||
|
0
mrt. 25
|
1761 |
Full script:
leads = env['crm.lead'].search([('activity_ids', '=', False), ('probability', '<', 100)])
for i in range(0, len(leads), 10):
batch_leads = leads[i:i+10]
for lead in batch_leads:
activity = env['mail.activity'].create({
'res_id': lead.id,
'res_model_id': env.ref('crm.model_crm_lead').id,
'activity_type_id': 13,
'date_deadline': datetime.datetime.today().strftime('%Y-%m-%d %H:%M'),
'user_id': lead.user_id.id,
})
lead.write({'activity_ids': [(4, activity.id)]})