[FIX] bemade_time_off_follower: validation error

Fixes a validation error that occurred when the alternate follower was
already in the list of recipients for the mail.thread.
This commit is contained in:
Marc Durepos 2024-09-20 10:14:57 -04:00
parent 626d4c5dc2
commit 017bde45dd
2 changed files with 25 additions and 16 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "Time Off Alternative Follower", "name": "Time Off Alternative Follower",
"version": "17.0.0.0.2", "version": "17.0.0.0.3",
"category": "Extra Tools", "category": "Extra Tools",
"summary": "Add Alternative Follower When Receiving Message While On Time Off", "summary": "Add Alternative Follower When Receiving Message While On Time Off",
"author": "Bemade", "author": "Bemade",

View file

@ -19,7 +19,7 @@ class MailThread(models.AbstractModel):
# Get the current datetime # Get the current datetime
now = fields.Datetime.now() now = fields.Datetime.now()
recipient_partner_ids = [recipient["id"] for recipient in recipients]
# Loop through each recipient # Loop through each recipient
for recipient in recipients: for recipient in recipients:
# Search for a user with the same partner_id as the recipient # Search for a user with the same partner_id as the recipient
@ -59,11 +59,14 @@ class MailThread(models.AbstractModel):
and leave.alternate_follower_id.partner_id.id not in recipients and leave.alternate_follower_id.partner_id.id not in recipients
): ):
# Log the addition of the alternate follower # Log the addition of the alternate follower
# Add the alternate follower to the recipients list
alternate_follower_id = (
leave.alternate_follower_id.partner_id.id)
if alternate_follower_id not in recipient_partner_ids:
_logger.info( _logger.info(
f"Adding {leave.alternate_follower_id.partner_id.name} as follower for {employee.name} " f"Adding {leave.alternate_follower_id.partner_id.name} as follower for {employee.name} "
f"while on time off." f"while on time off."
) )
# Add the alternate follower to the recipients list
recipients.append( recipients.append(
{ {
"id": leave.alternate_follower_id.partner_id.id, "id": leave.alternate_follower_id.partner_id.id,
@ -74,6 +77,12 @@ class MailThread(models.AbstractModel):
"type": "user", "type": "user",
} }
) )
else:
_logger.info(
f"{leave.alternate_follower_id.partner_id.name}"
f" is already a recipient. Skipping alternate "
f"follower addition."
)
else: else:
_logger.info( _logger.info(
f"Not adding {leave.alternate_follower_id.partner_id.name} for {employee.name}, All ready " f"Not adding {leave.alternate_follower_id.partner_id.name} for {employee.name}, All ready "