From 427e20129b4719ef8b3d614aaa51936fc6bcb665 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Dufays Date: Thu, 18 Jan 2024 13:54:08 +0100 Subject: [PATCH] [FIX] {test_}mail: set automated flag to False for activity scheduled manually How to reproduce: - Install contacts - Go to any contact - Schedule an activity on the contact by clicking on "Activities" The flag automated of the created activity is set to True which shouldn't be the case (you can check either in the DB or by adding the field with studio). The same happens when scheduling plan, scheduling activities on multiple records in the view list or a plan on multiple records. This fixes the problem by modifying the activity schedule wizard so that it always creates activities with automated flag set to False. Note that that flags is used to distinguish activities created manually from those created automatically. Some flows automatically cancel automated activities (e.g. cancel 'validate my ticket') but those should probably not cancel user defined activities (e.g. 'ask customer to pay'). That's why we must ensure that activity created manually have that flag set to False. Task-3691827 closes odoo/odoo#149965 Signed-off-by: Thibault Delavallee (tde) --- addons/mail/models/mail_activity_mixin.py | 3 +++ addons/mail/tests/test_mail_activity.py | 1 + addons/mail/wizard/mail_activity_schedule.py | 2 ++ addons/test_mail/tests/test_mail_activity_plan.py | 2 ++ 4 files changed, 8 insertions(+) diff --git a/addons/mail/models/mail_activity_mixin.py b/addons/mail/models/mail_activity_mixin.py index 5c599b70ecf..62f444a6c2f 100644 --- a/addons/mail/models/mail_activity_mixin.py +++ b/addons/mail/models/mail_activity_mixin.py @@ -353,6 +353,9 @@ class MailActivityMixin(models.AbstractModel): It is useful to avoid having various "env.ref" in the code and allow to let the mixin handle access rights. + Note that unless specified otherwise in act_values, the activities created + will have their "automated" field set to True. + :param date_deadline: the day the activity must be scheduled on the timezone of the user must be considered to set the correct deadline """ diff --git a/addons/mail/tests/test_mail_activity.py b/addons/mail/tests/test_mail_activity.py index 61169d704fb..f5c0cd42b82 100644 --- a/addons/mail/tests/test_mail_activity.py +++ b/addons/mail/tests/test_mail_activity.py @@ -89,6 +89,7 @@ class ActivityScheduleCase(MailCommon): **{template.activity_type_id.delay_unit: template.activity_type_id.delay_count})) self.assertEqual(activity.note, template.note) self.assertEqual(activity.summary, template.summary) + self.assertFalse(activity.automated) if force_responsible_id: self.assertEqual(activity.user_id, force_responsible_id) else: diff --git a/addons/mail/wizard/mail_activity_schedule.py b/addons/mail/wizard/mail_activity_schedule.py index 30792319a12..8e784e921ac 100644 --- a/addons/mail/wizard/mail_activity_schedule.py +++ b/addons/mail/wizard/mail_activity_schedule.py @@ -215,6 +215,7 @@ class MailActivitySchedule(models.TransientModel): template.activity_type_id, force_base_date=self.plan_date_deadline) record.activity_schedule( activity_type_id=template.activity_type_id.id, + automated=False, summary=template.summary, note=template.note, user_id=responsible.id, @@ -294,6 +295,7 @@ class MailActivitySchedule(models.TransientModel): def _action_schedule_activities(self): return self._get_applied_on_records().activity_schedule( activity_type_id=self.activity_type_id.id, + automated=False, summary=self.summary, note=self.note, user_id=self.activity_user_id.id, diff --git a/addons/test_mail/tests/test_mail_activity_plan.py b/addons/test_mail/tests/test_mail_activity_plan.py index cf97855d70b..561eecfe03a 100644 --- a/addons/test_mail/tests/test_mail_activity_plan.py +++ b/addons/test_mail/tests/test_mail_activity_plan.py @@ -91,6 +91,7 @@ class TestActivitySchedule(ActivityScheduleCase): for record in test_records: self.assertActivityCreatedOnRecord(record, { 'activity_type_id': self.activity_type_todo, + 'automated': False, 'date_deadline': self.reference_now.date() + timedelta(days=4), # activity type delay 'note': '

Useful link ...

', 'summary': 'Write specification', @@ -151,6 +152,7 @@ class TestActivitySchedule(ActivityScheduleCase): for record in test_records: self.assertActivityCreatedOnRecord(record, { 'activity_type_id': self.activity_type_call, + 'automated': False, 'date_deadline': self.reference_now.date() + timedelta(days=5), # both types delays 'note': False, 'summary': False,