[IMP] calendar: do not switch assignation on activities

Currently, if we create an activity for user other than logged in one and
create a calendar event from the activity, it automatically changes the
attendee on the event and re-assigns the activity to the logged in user
instead of the one originally assigned to the activity during creation.
It happens because default attendees are not passed while creating the
event from activity. ALso, when editing the calendar event, the sync
mechanism changes the activity user to the organizer of the event, which
by default is logged in user.

This commit improves the behavior by passing the appropriate default
values so that the calendar attendees and organizer matches with the
user to whom the activity is assigned initially.

task-2920631

closes odoo/odoo#96943

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
Mahamadasif Ansari
2022-09-23 13:34:19 +02:00
parent 78b5e4836c
commit 89a1de5232
3 changed files with 30 additions and 3 deletions
+2 -3
View File
@@ -407,13 +407,12 @@ class Meeting(models.Model):
def create(self, vals_list):
# Prevent sending update notification when _inverse_dates is called
self = self.with_context(is_calendar_event_new=True)
defaults = self.default_get(['activity_ids', 'res_model_id', 'res_id', 'user_id', 'res_model', 'partner_ids'])
vals_list = [ # Else bug with quick_create when we are filter on an other user
dict(vals, user_id=self.env.user.id) if not 'user_id' in vals else vals
dict(vals, user_id=defaults.get('user_id', self.env.user.id)) if not 'user_id' in vals else vals
for vals in vals_list
]
defaults = self.default_get(['activity_ids', 'res_model_id', 'res_id', 'user_id', 'res_model', 'partner_ids'])
meeting_activity_type = self.env['mail.activity.type'].search([('category', '=', 'meeting')], limit=1)
# get list of models ids and filter out None values directly
model_ids = list(filter(None, {values.get('res_model_id', defaults.get('res_model_id')) for values in vals_list}))
+2
View File
@@ -20,6 +20,8 @@ class MailActivity(models.Model):
'default_name': self.summary or self.res_name,
'default_description': self.note if not is_html_empty(self.note) else '',
'default_activity_ids': [(6, 0, self.ids)],
'default_partner_ids': self.user_id.partner_id.ids,
'default_user_id': self.user_id.id,
}
return action
+26
View File
@@ -151,6 +151,32 @@ class TestCalendar(SavepointCaseWithUserDemo):
self.assertEqual(test_event.res_id, test_record.id)
self.assertEqual(len(test_record.activity_ids), 1)
def test_event_activity_user_sync(self):
# ensure phonecall activity type exists
activty_type = self.env['mail.activity.type'].create({
'name': 'Call',
'category': 'phonecall'
})
activity = self.env['mail.activity'].create({
'summary': 'Call with Demo',
'activity_type_id': activty_type.id,
'note': 'Schedule call with Admin',
'res_model_id': self.env['ir.model']._get_id('res.partner'),
'res_id': self.env['res.partner'].create({'name': 'Test Partner'}).id,
'user_id': self.user_demo.id,
})
action_context = activity.action_create_calendar_event().get('context', {})
event_from_activity = self.env['calendar.event'].with_context(action_context).create({
'start': '2022-07-27 14:30:00',
'stop': '2022-07-27 16:30:00',
})
# Check that assignation of the activity hasn't changed, and event is having
# correct values set in attendee and organizer related fields
self.assertEqual(activity.user_id, self.user_demo)
self.assertEqual(event_from_activity.partner_ids, activity.user_id.partner_id)
self.assertEqual(event_from_activity.attendee_ids.partner_id, activity.user_id.partner_id)
self.assertEqual(event_from_activity.user_id, activity.user_id)
def test_event_allday(self):
self.env.user.tz = 'Pacific/Honolulu'