Skip to content
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
2 changes: 1 addition & 1 deletion partner_communication_compassion/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# pylint: disable=C8101
{
"name": "Compassion Partner Communications",
"version": "14.0.1.1.1",
"version": "14.0.1.2.0",
"category": "Other",
"author": "Compassion CH",
"license": "AGPL-3",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from datetime import datetime

from dateutil.relativedelta import relativedelta
from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
openupgrade.logged_query(
env.cr,
"""
UPDATE recurring_contract
SET exit_communication_sent = COALESCE (sds_state_date, end_date, write_date)
WHERE state = 'terminated'
AND (end_date IS NULL OR end_date <= CURRENT_DATE - INTERVAL '6 months')
""",
Comment thread
ecino marked this conversation as resolved.
)
six_month_ago = datetime.today() - relativedelta(months=6)
Comment thread
ecino marked this conversation as resolved.
terminated_sponsorships = env["recurring.contract"].search(
[
("state", "=", "terminated"),
("end_date", ">", six_month_ago),
]
)
exit_configs = env.ref(
"partner_communication_compassion.lifecycle_child_planned_exit"
) + env.ref("partner_communication_compassion.lifecycle_child_unplanned_exit")
for contract in terminated_sponsorships:
exit_dates = env["partner.communication.job"].search_read(
[
("config_id", "in", exit_configs.ids),
("state", "=", "done"),
("sent_date", "!=", False),
(
"partner_id",
"in",
(contract.partner_id + contract.correspondent_id).ids,
),
("object_ids", "like", contract.id),
Comment thread
ecino marked this conversation as resolved.
],
["sent_date"],
)
Comment thread
ecino marked this conversation as resolved.
if exit_dates:
contract.exit_communication_sent = max(r["sent_date"] for r in exit_dates)
1 change: 1 addition & 0 deletions partner_communication_compassion/models/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class RecurringContract(models.Model):
help="Indicates a new picture was received and not yet "
"transmitted to the sponsor."
)
exit_communication_sent = fields.Datetime()

@api.onchange("origin_id", "correspondent_id")
def _do_not_send_letter_to_transfer(self):
Expand Down
10 changes: 10 additions & 0 deletions partner_communication_compassion/models/partner_communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ def send(self):
if biennials:
for child in biennials.get_objects():
child.sponsorship_ids[0].new_picture = False
exit_confs = self.env.ref(
"partner_communication_compassion.lifecycle_child_planned_exit"
) + self.env.ref(
"partner_communication_compassion.lifecycle_child_unplanned_exit"
)
exits = self.filtered(lambda j: j.state == "done" and j.config_id in exit_confs)
if exits:
exits.get_objects().write(
{"exit_communication_sent": fields.Datetime.now()}
)
return res

def cancel(self):
Expand Down
6 changes: 2 additions & 4 deletions sbc_compassion/models/correspondence.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,9 @@ def _get_uuid(self):
return str(uuid.uuid4())

def _compute_is_final_letter(self):
final_type = self.env.ref("sbc_compassion.correspondence_type_final")
for letter in self:
letter.is_final_letter = (
"Final Letter" in letter.communication_type_ids.mapped("name")
or letter.sponsorship_state != "active"
)
letter.is_final_letter = final_type in letter.communication_type_ids

def _compute_preferred_dpi(self):
for letter in self:
Expand Down
6 changes: 5 additions & 1 deletion sbc_compassion/views/correspondence_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
<field name="name">correspondence.tree</field>
<field name="model">correspondence</field>
<field name="arch" type="xml">
<tree string="Correspondence" decoration-danger="is_final_letter">
<tree
string="Correspondence"
decoration-danger="is_final_letter or sponsorship_state != 'active'"
>
<field name="scanned_date" />
<field name="sponsorship_id" />
<field name="kit_identifier" />
<field name="direction" />
<field name="status_date" />
<field name="state" />
<field name="is_final_letter" invisible="1" />
<field name="sponsorship_state" invisible="1" />
</tree>
</field>
</record>
Expand Down
Loading