Skip to content

Commit

Permalink
[FIX] l10n_it_sdi_channel: Subscribe to related channel
Browse files Browse the repository at this point in the history
  • Loading branch information
SirTakobi committed Jan 5, 2023
1 parent 2f75593 commit f5eb003
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion l10n_it_sdi_channel/models/fatturapa_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,31 @@ class FatturaPAAttachment(models.AbstractModel):
_inherit = "fatturapa.attachment"

channel_id = fields.Many2one(
comodel_name="sdi.channel", related="company_id.sdi_channel_id", store=True
comodel_name="sdi.channel",
related="company_id.sdi_channel_id",
store=True,
)

def _message_auto_subscribe_followers(self, updated_values, default_subtype_ids):
res = super()._message_auto_subscribe_followers(
updated_values, default_subtype_ids
)
updated_channel_id = updated_values.get("channel_id")
if not updated_channel_id:
# SdI channel is not explicitly set, so SdI channel's followers
# won't be subscribed to current attachments.
# Attachments might have the SdI channel set anyway
# because it is a related field.
# Add the SdI channel's 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,
)
)
return res

0 comments on commit f5eb003

Please sign in to comment.