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
- 会計
- 在庫
- PoS
- Project
- MRP
この質問にフラグが付けられました
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
関連投稿 | 返信 | ビュー | 活動 | |
---|---|---|---|---|
|
2
8月 25
|
799 | ||
|
2
5月 25
|
1656 | ||
|
1
4月 25
|
1619 | ||
|
0
3月 25
|
1643 | ||
|
0
3月 25
|
1586 |
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)]})