[FIX] website_event: use correct subtype when (un)publishing

is_published has been renamed in website_published in e3d2b01 but not in
_track_subtype().

steps to reproduce:
- add a follower to an event, select the two event subtypes on this follower
- check this event on the website and publish/unpublish it
- check chatter, tracking values have been created
- no message have been sent

before this commit:
- subtypes mt_event_published and mt_event_unpublished are not used

after this commit:
- a message is sent when an event is (un)published

opw-3582596

closes odoo/odoo#144912

X-original-commit: 1b94aca1bd00d136e05f2fd2cbbd4691940eea19
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Signed-off-by: Nicolas Danhier (nda) <nda@odoo.com>
This commit is contained in:
nda
2023-12-04 20:30:40 +00:00
parent 8703b011aa
commit 22115d6d3b
3 changed files with 41 additions and 4 deletions
+4 -4
View File
@@ -454,10 +454,10 @@ class Event(models.Model):
def _track_subtype(self, init_values):
self.ensure_one()
if 'is_published' in init_values and self.is_published:
return self.env.ref('website_event.mt_event_published')
elif 'is_published' in init_values and not self.is_published:
return self.env.ref('website_event.mt_event_unpublished')
if init_values.keys() & {'is_published', 'website_published'}:
if self.is_published:
return self.env.ref('website_event.mt_event_published', raise_if_not_found=False)
return self.env.ref('website_event.mt_event_unpublished', raise_if_not_found=False)
return super(Event, self)._track_subtype(init_values)
def _get_event_resource_urls(self):
+1
View File
@@ -2,6 +2,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import test_event_internals
from . import test_event_mail
from . import test_event_menus
from . import test_event_visitor
from . import test_website_event
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from datetime import datetime, timedelta
from odoo.addons.mail.tests.common import MailCommon
from odoo.tests import tagged
@tagged('post_install', '-at_install')
class TestMail(MailCommon):
def test_website_publish_notification(self):
""" Test that the published/unpublished notifications are sent when publishing/unpublishing an event"""
published_subtype = self.env.ref('website_event.mt_event_published')
unpublished_subtype = self.env.ref('website_event.mt_event_unpublished')
event = self.env['event.event'].create({
'name': 'Event',
'date_begin': datetime.today() - timedelta(days=1),
'date_end': datetime.today() + timedelta(days=1),
})
self.flush_tracking()
follower = self.user_employee.partner_id
event.message_subscribe(partner_ids=follower.ids, subtype_ids=[published_subtype.id, unpublished_subtype.id])
event.website_published = True
self.flush_tracking()
event.website_published = False
self.flush_tracking()
unpublished_message, published_message, creation_message = event.message_ids
self.assertEqual(unpublished_message.subtype_id, unpublished_subtype)
self.assertEqual(published_message.subtype_id, published_subtype)
self.assertEqual(creation_message.subtype_id, self.env.ref('mail.mt_note'))