تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
1507 أدوات العرض

I am setting a todo in Sales and when todo is overdue I like to trigger a rule. 


Apply on is set to "Activity State=Overdue" which is working because its shoving me number of records.

I have tried to set trigger on Save, and on UI change but haven't been able to trigger the rule.

What am I missing here? Any Ideas?

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

That is great info thanks for your time

الصورة الرمزية
إهمال
أفضل إجابة

Hi,



To trigger a rule when an activity becomes overdue, you should use a Scheduled Action instead of relying on "on-save" or "UI change" triggers. Scheduled actions run periodically. Go to Settings > Technical > Automation > Scheduled Actions and create a new scheduled action. Enter a name, set the model as 'Activity', and set how often you want it to run (e.g., every hour, daily). Specify when it should first run (Next Execution Date). You can also set the number of calls (Set -1 for unlimited calls.). Then add Python Code to Execute Your Desired Rule:


For example:



overdue_activities = env['mail.activity'].search([


    ('date_deadline', '<', datetime.date.today()),  # Check overdue


    ('state', '!=', 'done')


])


for activity in overdue_activities:


    # Your logic here


    # For example if you want to send a message to the assigned user (if applicable)


    if activity.user_id:


        env['mail.message'].create({


            'body': "Activity is overdue!",


            'subject': 'Overdue Activity Notification',


            'message_type': 'notification',


            'subtype_id': env.ref('mail.mt_comment').id,


            'partner_ids': [(4, activity.user_id.partner_id.id)],


            'res_id': activity.id,


            'model': 'mail.activity',


        })



    # Optionally, if you want to add a message to the related record's chatter


    if activity.res_id and activity.res_model:


        related_record = env[activity.res_model].browse(activity.res_id)


        try:


            related_record.message_post(


                body="The activity is overdue.",


                message_type='comment',


            )


        except AttributeError:


            pass


Hope it helps

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
ديسمبر 24
1288
2
يونيو 24
2198
4
يوليو 24
3912
1
مايو 23
3550
2
يناير 21
3422