Skip to content

Commit

Permalink
Merge pull request #655 from OpenSPP/649-compliance-module-fix
Browse files Browse the repository at this point in the history
add button to show all cycle members
  • Loading branch information
emjay0921 authored Nov 11, 2024
2 parents d89b986 + 3507470 commit 0501c8e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
7 changes: 6 additions & 1 deletion spp_programs/views/cycle_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ Part of OpenSPP. See LICENSE file for full copyright and licensing details.
</xpath>
<xpath expr="//button[@name='open_entitlements_form']" position="attributes">
<attribute name="invisible">entitlements_count == 0</attribute>
<attribute name="icon">fa-calculator</attribute>
</xpath>
<xpath expr="//button[@name='open_entitlements_form']" position="after">
<button
type="object"
class="oe_stat_button"
icon="fa-folder-open-o"
icon="fa-calculator"
name="open_entitlements_form"
invisible="inkind_entitlements_count == 0"
>
Expand All @@ -57,6 +58,10 @@ Part of OpenSPP. See LICENSE file for full copyright and licensing details.
invisible="state != 'draft' or inkind_entitlements_count == 0"
/>
</xpath>

<xpath expr="//button[@name='open_payments_form']" position="attributes">
<attribute name="icon">fa-file-text-o</attribute>
</xpath>
</field>
</record>

Expand Down
29 changes: 29 additions & 0 deletions spp_programs_compliance_criteria/models/g2p_cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class G2pCycle(models.Model):
_inherit = "g2p.cycle"

allow_filter_compliance_criteria = fields.Boolean(compute="_compute_allow_filter_compliance_criteria")
all_members_count = fields.Integer(string="# Enrollments", readonly=True, compute="_compute_all_members_count")

@api.depends("program_id", "program_id.compliance_managers")
def _compute_allow_filter_compliance_criteria(self):
Expand Down Expand Up @@ -36,3 +37,31 @@ def _get_compliance_criteria_domain(self):
membership = self.cycle_membership_ids if self.cycle_membership_ids else None
domain.append(manager_ref._prepare_eligible_domain(membership))
return OR(domain)

def _compute_all_members_count(self):
for rec in self:
domain = rec._get_beneficiaries_domain(None)
members_count = self.env["g2p.cycle.membership"].search_count(domain)
rec.update({"all_members_count": members_count})

def open_all_members_form(self):
self.ensure_one()

action = {
"name": _("Cycle Members"),
"type": "ir.actions.act_window",
"res_model": "g2p.cycle.membership",
"context": {
"create": False,
"default_cycle_id": self.id,
},
"view_mode": "list,form",
"domain": [("cycle_id", "=", self.id)],
}
return action

def open_members_form(self):
self.ensure_one()
action = super().open_members_form()
action["name"] = _("Cycle Beneficiaries")
return action
15 changes: 15 additions & 0 deletions spp_programs_compliance_criteria/views/g2p_cycle_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@
/>
<field name="allow_filter_compliance_criteria" invisible="1" />
</xpath>

<xpath expr="//button[@name='open_members_form']" position="before">
<button
type="object"
class="oe_stat_button"
title="Open all members form"
icon="fa-list-alt"
name="open_all_members_form"
>
<div class="o_form_field o_stat_info">
<field name="all_members_count" class="o_stat_value" />
<span class="o_stat_text">Enrollments</span>
</div>
</button>
</xpath>
</field>
</record>

Expand Down

0 comments on commit 0501c8e

Please sign in to comment.