Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ

Need help: Create a todo activity for subscription. 
Eg: license validity 1year or more than that. I need to create todo activity for the license expire before 90days.

Many thanks.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

From the question; the requirement looks like you have to add a To-Do activity in the Subscription(sale.subscription) 90 days before the expiry date(In subscription, there is no default field for expiry date. But, there is a field End Date(date)).

For example, I am using the Date of Next Invoice(recurring_next_date) for calculation. If you are using any other date field replace it in the python code given below. Also provide the correct id of the To Do activity type to activity_type_id(here, 4 is given). Since the date is not changing I am using a scheduled action instead of an automated action.

Model: sale.subscription
Execute Every: 1 Days
Number of Calls: -1
license_expiry_date = datetime.date.today() + dateutil.relativedelta.relativedelta(days=90)
subscriptions = model.sudo().search([('recurring_next_date', '=', license_expiry_date)])
for subscription in subscriptions:
activity = {
'res_id': subscription.id,
'res_model_id': env['ir.model'].search([('model', '=', 'sale.subscription')]).id,
'user_id': subscription.user_id.id,
'summary': 'Expiry Notification',
'note': 'The subscription will be expired in 90 days!',
'activity_type_id': 4,
'date_deadline': datetime.date.today(),
}
env['mail.activity'].create(activity)

Regards

Ảnh đại diện
Huỷ bỏ
Tác giả

Thank you so much

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 11 22
2021
1
thg 3 23
9463
0
thg 3 22
2731
2
thg 5 24
2340
1
thg 1 23
1777