Skip to content

Commit

Permalink
T1758 FIX sending multiple exit communications to sponsors
Browse files Browse the repository at this point in the history
- Only send it when the contract is freshly terminated because of the lifecycle message
  • Loading branch information
ecino committed Oct 1, 2024
1 parent 1420e0a commit 170b8ed
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions partner_communication_compassion/models/lifecycle_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# The licence is in the file __manifest__.py
#
##############################################################################
from datetime import date

from odoo import api, models


Expand All @@ -25,7 +27,8 @@ def process_commkit(self, commkit_data):
"partner_communication_compassion.planned_exit_notification"
)
sponsorship = lifecycle.child_id.sponsorship_ids[:1]
sponsorship.send_communication(communication_type, both=True)
if sponsorship.end_date.date() == date.today():
sponsorship.send_communication(communication_type, both=True)
else:
communication_type = self.env["partner.communication.config"].search(
[
Expand All @@ -49,14 +52,19 @@ def process_commkit(self, commkit_data):
object_ids = lifecycle.child_id.sponsorship_ids[:1].id

# Generate the communication
sponsor = lifecycle.child_id.sponsorship_ids[:1].correspondent_id
self.env["partner.communication.job"].create(
{
"config_id": communication_type.id,
"partner_id": sponsor.id,
"object_ids": object_ids,
}
)
sponsorship = lifecycle.child_id.sponsorship_ids[:1]
if (
sponsorship.state == "active"
or sponsorship.end_date.date() == date.today()
):
sponsor = sponsorship.correspondent_id
self.env["partner.communication.job"].create(
{
"config_id": communication_type.id,
"partner_id": sponsor.id,
"object_ids": object_ids,
}
)
return ids


Expand Down

0 comments on commit 170b8ed

Please sign in to comment.