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
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
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
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
2
thg 8 25
|
982 | ||
|
2
thg 5 25
|
1877 | ||
|
1
thg 4 25
|
1805 | ||
|
0
thg 3 25
|
1777 | ||
|
0
thg 3 25
|
1752 |
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)]})