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

T1808 - Sponsor cannot see terminated child before being notified of exit #42

Merged
merged 5 commits into from
Sep 23, 2024
Merged
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
34 changes: 16 additions & 18 deletions my_compassion/controllers/my_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,20 @@


def _get_user_children(state=None):
env = request.env
partner = env.user.partner_id
return _get_sponsorships(partner, state).mapped("child_id").sorted("preferred_name")


def _get_sponsorships(partner, state=None):
"""
Find all the children for which the connected user has a contract for.
There is the possibility to fetch either only active children or only those
Find all the sponsorships of the given user.
There is the possibility to fetch either only active sponsorships or only those
that are terminated / cancelled. By default, all sponsorships are returned

:return: a recordset of child.compassion which the connected user sponsors
:return: a recordset of recurring.contract of the given user
"""
env = request.env
partner = env.user.partner_id
end_reason_child_depart = env.ref("sponsorship_compassion.end_reason_depart")

def filter_sponsorships(sponsorship):
Expand Down Expand Up @@ -72,8 +77,6 @@ def filter_sponsorships(sponsorship):
partner.get_portal_sponsorships()
.with_context(allow_during_suspension=True)
.filtered(filter_sponsorships)
.mapped("child_id")
.sorted("preferred_name")
)


Expand Down Expand Up @@ -498,21 +501,16 @@ def my_donations(self, invoice_page=1, invoice_per_page=12, **kw):
]
)

sponsorships = partner.sponsorship_ids.filtered(
lambda s: s.state in ["waiting", "active", "mandate"]
and partner == s.mapped("partner_id")
)
currency = sponsorships.mapped("pricelist_id.currency_id")[:1].name
active_sponsorships = _get_sponsorships(partner, state="active")
currency = active_sponsorships.mapped("pricelist_id.currency_id")[:1].name

# Dict of groups mapped to their sponsorships, and total amount
# {group: (<sponsorships recordset>, total_amount string), ...}
sponsorships_by_group = {
g: (
sponsorships.filtered(lambda s, g=g: s.group_id == g),
f"{int(g.total_amount):,d} {currency}",
)
for g in sponsorships.mapped("group_id")
}
sponsorships_by_group = {}
for g in active_sponsorships.mapped("group_id"):
sponsorships = active_sponsorships.filtered(lambda s, g=g: s.group_id == g)
total = int(sum(sponsorships.mapped("total_amount")))
sponsorships_by_group[g] = (sponsorships, f"{total:,d} {currency}")

values = self._prepare_portal_layout_values()
pager = request.website.pager(
Expand Down
Loading