[FIX] crm: invite partners on quick creation of meeting

When creating a meeting from a partner/lead, the invitations won't be
created/sent

To reproduce the error:
1. Open a lead
2. Click on Meeting
3. Create a meeting
    - On meeting creation, directly click on "Create", not "Edit"

Error: No invitation has been sent. When editing the created event,
there isn't any invitation on Invitations tab. Same error will happen
when opening the form of a customer instead of a lead (step 1)

For an attendee to be created, the partners associated with the meeting
must be explicitly listed in the creation values:
https://github.com/odoo/odoo/blob/3e20e68f0790a0b0f3b5c4d43f59f235b7d20fef/addons/calendar/models/calendar_event.py#L710-L713
However, in the above use case, the partners identifiers are given
through the context. This explains why the attendees are not created.

OPW-2531496

closes odoo/odoo#75353

X-original-commit: a8b4f8f6c009d8abd7210973005fd755ac3bc573
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Signed-off-by: Arnaud Joset <arj-odoo@users.noreply.github.com>
Signed-off-by: Adrien Widart <adwid@users.noreply.github.com>
This commit is contained in:
Adrien Widart
2021-08-20 07:48:33 +00:00
parent c47be4bb9a
commit 75584fb881
5 changed files with 40 additions and 4 deletions
+8 -4
View File
@@ -85,6 +85,12 @@ class Meeting(models.Model):
partners |= self.env['res.partner'].browse(active_id)
return partners
@api.model
def _default_attendee_ids(self):
""" Automatically add the current partner when creating an event if there is none
(happens when we quickcreate an event)"""
return self._attendees_values([(4, self.env.user.partner_id.id)])
@api.model
def _default_videocall_location(self):
if self.env.context.get('calendar_no_videocall'):
@@ -156,7 +162,7 @@ class Meeting(models.Model):
activity_ids = fields.One2many('mail.activity', 'calendar_event_id', string='Activities')
# attendees
attendee_ids = fields.One2many(
'calendar.attendee', 'event_id', 'Participant')
'calendar.attendee', 'event_id', 'Participant', default=_default_attendee_ids)
attendee_status = fields.Selection(
Attendee.STATE_SELECTION, string='Attendee Status', compute='_compute_attendee')
partner_ids = fields.Many2many(
@@ -382,10 +388,8 @@ class Meeting(models.Model):
activity_vals['user_id'] = user_id
values['activity_ids'] = [(0, 0, activity_vals)]
# Automatically add the current partner when creating an event if there is none (happens when we quickcreate an event)
self_partner_id = [(4, self.env.user.partner_id.id)]
vals_list = [
dict(vals, attendee_ids=self._attendees_values(vals.get('partner_ids', self_partner_id)))
dict(vals, attendee_ids=self._attendees_values(vals['partner_ids'])) if 'partner_ids' in vals else vals
for vals in vals_list
]
recurrence_fields = self._get_recurrent_fields()
+1
View File
@@ -89,6 +89,7 @@ class Partner(models.Model):
action = self.env["ir.actions.actions"]._for_xml_id("calendar.action_calendar_event")
action['context'] = {
'default_partner_ids': partner_ids,
'default_attendee_ids': [(0, 0, {'partner_id': pid}) for pid in partner_ids],
}
action['domain'] = ['|', ('id', 'in', self._compute_meeting()[self.id]), ('partner_ids', 'in', self.ids)]
return action
+13
View File
@@ -346,3 +346,16 @@ class TestCalendar(SavepointCaseWithUserDemo):
'start': fields.Datetime.to_string(now + timedelta(hours=5)),
'stop': fields.Datetime.to_string(now + timedelta(hours=6)),
})
def test_meeting_creation_from_partner_form(self):
""" When going from a partner to the Calendar and adding a meeting, both current user and partner
should be attendees of the event """
calendar_action = self.partner_demo.schedule_meeting()
event = self.env['calendar.event'].with_context(calendar_action['context']).create({
'name': 'Super Meeting',
'start': datetime(2020, 12, 13, 17),
'stop': datetime(2020, 12, 13, 22),
})
self.assertEqual(len(event.attendee_ids), 2)
self.assertEqual(event.attendee_ids[0].partner_id, self.partner_demo)
self.assertEqual(event.attendee_ids[1].partner_id, self.env.user.partner_id)
+1
View File
@@ -1012,6 +1012,7 @@ class Lead(models.Model):
'default_opportunity_id': current_opportunity_id,
'default_partner_id': self.partner_id.id,
'default_partner_ids': partner_ids,
'default_attendee_ids': [(0, 0, {'partner_id': pid}) for pid in partner_ids],
'default_team_id': self.team_id.id,
'default_name': self.name,
}
@@ -116,3 +116,20 @@ class TestCRMLeadSmartCalendar(TestCrmCommon):
mode, initial_date = lead_smart_calendar_2._get_opportunity_meeting_view_parameters()
self.assertEqual(mode, 'week')
self.assertEqual(initial_date, date(2020, 12, 12))
@users('user_sales_leads')
def test_meeting_creation_from_lead_form(self):
""" When going from a lead to the Calendar and adding a meeting, both salesman and customer
should be attendees of the event """
lead = self.env['crm.lead'].create({
'name': 'SuperLead',
'partner_id': self.contact_1.id,
})
calendar_action = lead.action_schedule_meeting()
event = self.env['calendar.event'].with_context(calendar_action['context']).create({
'start': datetime(2020, 12, 13, 17),
'stop': datetime(2020, 12, 13, 22),
})
self.assertEqual(len(event.attendee_ids), 2)
self.assertEqual(event.attendee_ids[0].partner_id, self.user_sales_leads.partner_id)
self.assertEqual(event.attendee_ids[1].partner_id, self.contact_1)