From b0ec64bafe37b1fa54305b2843b923a73a1b7208 Mon Sep 17 00:00:00 2001 From: Simone Rubino Date: Wed, 14 Sep 2022 10:59:32 +0200 Subject: [PATCH 1/2] [REF] l10n_it_fatturapa_sdicoop: Add Test for Followers Subscription --- .../tests/test_notification.py | 89 ++++++++++++++++--- 1 file changed, 78 insertions(+), 11 deletions(-) diff --git a/l10n_it_fatturapa_sdicoop/tests/test_notification.py b/l10n_it_fatturapa_sdicoop/tests/test_notification.py index a687e28724bc..c9183209c25b 100644 --- a/l10n_it_fatturapa_sdicoop/tests/test_notification.py +++ b/l10n_it_fatturapa_sdicoop/tests/test_notification.py @@ -4,20 +4,29 @@ from odoo.addons.l10n_it_fatturapa_in.tests.fatturapa_common import ( FatturapaCommon, ) -from odoo.tests import new_test_user +from odoo.tests import new_test_user, SavepointCase -class TestBillNotification (FatturapaCommon): +class TestBillNotification (FatturapaCommon, SavepointCase): - def setUp(self): - super().setUp() - self.notified_user = new_test_user( - self.env, + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.notified_user = new_test_user( + cls.env, login='Notify E-bill', ) - self.sdicoop_channel = self.env.ref( + cls.not_notified_user = new_test_user( + cls.env, + login='Do not Notify E-bill', + ) + cls.sdicoop_channel = cls.env.ref( 'l10n_it_fatturapa_sdicoop.sdi_channel_sdicoop', ) + cls.channel_received_e_bill = \ + cls.env.ref('l10n_it_sdi_channel.sdi_channel_e_bill_received') + cls.attachment_received_e_bill = \ + cls.env.ref('l10n_it_sdi_channel.e_bill_received') def test_e_bill_created_notify(self): """ @@ -57,12 +66,9 @@ def test_e_bill_created_notify(self): attachment.message_partner_ids, ) # There is a message of subtype E-bill received - received_e_bill_subtype = self.env.ref( - 'l10n_it_sdi_channel.e_bill_received', - ) messages = attachment.message_ids received_e_bill_message = messages.filtered( - lambda m: m.subtype_id == received_e_bill_subtype + lambda m: m.subtype_id == self.attachment_received_e_bill ) self.assertEqual(len(received_e_bill_message), 1) # The message notifies the SdI channel's follower @@ -70,3 +76,64 @@ def test_e_bill_created_notify(self): notified_partner, received_e_bill_message.needaction_partner_ids, ) + + def test_e_bill_created_no_notify(self): + """ + When an E-bill is received, + the channel followers that do not have the 'E-bill received' subtype + are not notified. + """ + # Arrange: Set the channel in the company, + # and a follower for the channel + company = self.env.user.company_id + not_notified_partner = self.not_notified_user.partner_id + company.sdi_channel_id = self.sdicoop_channel + all_subtypes, internal_subtypes, external_subtypes = \ + self.env['mail.message.subtype'].default_subtypes( + self.sdicoop_channel._name, + ) + self.sdicoop_channel.message_subscribe( + partner_ids=not_notified_partner.ids, + subtype_ids=(all_subtypes - self.channel_received_e_bill).ids, + ) + # pre-condition: the Partner is following the SdI Channel, + # but not the E-bill Received Subtype + self.assertIn( + not_notified_partner, + company.sdi_channel_id.message_partner_ids, + ) + received_e_bill_followers = self.sdicoop_channel.message_follower_ids \ + .filtered( + lambda f: self.channel_received_e_bill in f.subtype_ids + ) \ + .mapped('partner_id') + self.assertNotIn( + not_notified_partner, + received_e_bill_followers, + ) + + # Act: Receive the E-bill + file_name = 'IT05979361218_001.xml' + file_path, file_content = self.getFile( + file_name, + module_name='l10n_it_fatturapa_sdicoop', + ) + attachment = self.sdicoop_channel.receive_fe( + { + file_name: file_content, + }, + {}, + ) + + # Assert: There is a message of subtype E-bill received, + # but the partner is not following it + messages = attachment.message_ids + received_e_bill_message = messages.filtered( + lambda m: m.subtype_id == self.attachment_received_e_bill + ) + self.assertEqual(len(received_e_bill_message), 1) + # The message notifies the SdI channel's follower + self.assertNotIn( + not_notified_partner, + received_e_bill_message.needaction_partner_ids, + ) From b7bf3295972541182fc28f0baa205018c01e64b7 Mon Sep 17 00:00:00 2001 From: Simone Rubino Date: Tue, 13 Sep 2022 16:17:37 +0200 Subject: [PATCH 2/2] [FIX] l10n_it_sdi_channel: Followers Subscription Followers of new Electronic Invoice are not following the same Subtypes as its SdI Channel --- .../models/fatturapa_attachment.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/l10n_it_sdi_channel/models/fatturapa_attachment.py b/l10n_it_sdi_channel/models/fatturapa_attachment.py index c57cd6b4d0c7..acd9219c61d7 100644 --- a/l10n_it_sdi_channel/models/fatturapa_attachment.py +++ b/l10n_it_sdi_channel/models/fatturapa_attachment.py @@ -27,10 +27,16 @@ def _message_auto_subscribe_followers( # but only if all the attachments share the same SdI channel channel = self.mapped('channel_id') if all(attachment.channel_id == channel for attachment in self): - for partner_follower in channel.message_partner_ids: - res.append(( - partner_follower.id, - default_subtype_ids, - False, - )) + subtype_model = self.env['mail.message.subtype'] + child_ids, def_ids, all_int_ids, parent, relation = \ + subtype_model._get_auto_subscription_subtypes(self._name) + for channel_follower in channel.message_follower_ids: + for channel_subtype in channel_follower.subtype_ids: + attachment_subtype_id = parent.get(channel_subtype.id) + if attachment_subtype_id: + res.append(( + channel_follower.partner_id.id, + [attachment_subtype_id], + False, + )) return res