Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] resource_booking: Add support for mail_note subtype by default #129

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions resource_booking/models/calendar_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,25 @@ def _notify_thread(self, message, msg_vals=False, **kwargs):
self = self.with_context(mail_notify_author=True)
return super()._notify_thread(message=message, msg_vals=msg_vals, **kwargs)

def _notify_get_recipients(self, message, msg_vals, **kwargs):
"""If we are creating the calendar event from resource booking, we want to
notify only the partner_ids and not all the followers (to avoid that each email
is sent to all followers). Example: Resource booking with combination of several
users. This only happens when the subtype note is enabled by default in the
instance.
"""
res = super()._notify_get_recipients(
message=message, msg_vals=msg_vals, **kwargs
)
if self.env.context.get("resource_booking_event"):
res2 = []
partner_ids = msg_vals.get("partner_ids", [])
for item in res:
if item["id"] in partner_ids:
res2.append(item)
return res2
return res

@api.model_create_multi
def create(self, vals_list):
"""Transfer resource booking to _attendees_values by context.
Expand Down
45 changes: 44 additions & 1 deletion resource_booking/tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ def setUpClass(cls):
cls.mt_note.default = True
cls.partner.email = "ŧ[email protected]"

def test_resource_booking_message(self):
def test_resource_booking_message_01(self):
rb_model = self.env["resource.booking"]
rb = rb_model.create(
{
Expand Down Expand Up @@ -1090,3 +1090,46 @@ def test_resource_booking_message(self):
lambda x: meeting.user_id.partner_id in x.partner_ids
)
self.assertIn(meeting.user_id.partner_id, user_message.notified_partner_ids)

def test_resource_booking_message_02(self):
rb_model = self.env["resource.booking"]
combination = self.rbcs[0]
user_0 = self.users[0]
user_1 = self.users[1]
r_user_1 = self.r_users.filtered(lambda x: x.user_id == user_1)
combination.write({"resource_ids": [(4, r_user_1.id)]})
cal_mon = self.r_calendars[0]
combination.forced_calendar_id = cal_mon
rb = rb_model.create(
{
"partner_ids": [(4, self.partner.id)],
"type_id": self.rbt.id,
"combination_auto_assign": False,
"combination_id": combination.id,
"user_id": user_0.id,
}
)
# Simulate the same as portal_booking_confirm
booking_sudo = rb_model.sudo().browse(rb.id)
booking_sudo = booking_sudo.with_context(
using_portal=True, tz=booking_sudo.type_id.resource_calendar_id.tz
)
with Form(booking_sudo) as booking_form:
booking_form.start = datetime(2021, 3, 1, 10)
booking_sudo.action_confirm()
meeting = rb.meeting_id
follower = meeting.message_follower_ids.filtered(
lambda x: x.partner_id == meeting.user_id.partner_id
)
self.assertIn(self.mt_note, follower.subtype_ids)
meesages = meeting.message_ids.filtered(
lambda x: x.message_type != "notification"
)
self.assertEqual(len(meesages), 3)
partner_message = meesages.filtered(lambda x: self.partner in x.partner_ids)
self.assertNotIn(user_0.partner_id, partner_message.notified_partner_ids)
self.assertNotIn(user_1.partner_id, partner_message.notified_partner_ids)
user_0_message = meesages.filtered(lambda x: user_0.partner_id in x.partner_ids)
self.assertIn(user_0.partner_id, user_0_message.notified_partner_ids)
user_1_message = meesages.filtered(lambda x: user_1.partner_id in x.partner_ids)
self.assertIn(user_1.partner_id, user_1_message.notified_partner_ids)
Loading