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
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
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
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
PrijaviRelated Posts | Odgovori | Prikazi | Aktivnost | |
---|---|---|---|---|
|
2
avg. 25
|
788 | ||
|
2
maj 25
|
1650 | ||
|
1
apr. 25
|
1616 | ||
|
0
mar. 25
|
1641 | ||
|
0
mar. 25
|
1576 |
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)]})