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

[FIX] I follower delle Fatture Elettroniche hanno sottotipi diversi dal canale SdI #2934

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
89 changes: 78 additions & 11 deletions l10n_it_fatturapa_sdicoop/tests/test_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -57,16 +66,74 @@ 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
self.assertIn(
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,
)
18 changes: 12 additions & 6 deletions l10n_it_sdi_channel/models/fatturapa_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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