From 61426a0576f710fdd049fc4ed8f6c18740fd153a Mon Sep 17 00:00:00 2001 From: red Date: Thu, 9 Jan 2025 20:58:29 +0800 Subject: [PATCH 1/3] [IMP] spp_programs_compliance_criteria: add context to button --- spp_programs_compliance_criteria/views/g2p_program_views.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spp_programs_compliance_criteria/views/g2p_program_views.xml b/spp_programs_compliance_criteria/views/g2p_program_views.xml index b48b55cda..deacf6532 100644 --- a/spp_programs_compliance_criteria/views/g2p_program_views.xml +++ b/spp_programs_compliance_criteria/views/g2p_program_views.xml @@ -19,7 +19,7 @@ title="Open Form" class="btn-success" invisible="not manager_ref_id" - context="{'default_program_id': id, 'create': False}" + context="{'default_program_id': id, 'create': False, 'compliance_manager': True}" /> Date: Tue, 14 Jan 2025 22:45:52 +0800 Subject: [PATCH 2/3] [IMP] spp_programs: add previous and next cycle --- spp_programs/models/cycle.py | 33 +++++++++++++++++++ spp_programs/models/managers/cycle_manager.py | 8 +++++ 2 files changed, 41 insertions(+) diff --git a/spp_programs/models/cycle.py b/spp_programs/models/cycle.py index e768aaf47..653e9dda1 100644 --- a/spp_programs/models/cycle.py +++ b/spp_programs/models/cycle.py @@ -16,11 +16,44 @@ class G2PCycle(models.Model): validate_async_err = fields.Boolean(default=False) + prev_cycle_id = fields.Many2one("g2p.cycle", "Previous Cycle", readonly=True) + next_cycle_id = fields.Many2one("g2p.cycle", "Next Cycle", readonly=True) + def _compute_inkind_entitlements_count(self): for rec in self: entitlements_count = self.env["g2p.entitlement.inkind"].search_count([("cycle_id", "=", rec.id)]) rec.update({"inkind_entitlements_count": entitlements_count}) + def get_previous_cycle(self): + self.ensure_one() + if self.prev_cycle_id: + return self.prev_cycle_id + else: + sorted_cycles = self.program_id.cycle_ids.sorted(key="create_date") + current_index = sorted_cycles.ids.index(self.id) + if current_index > 0: + # Return the previous cycle + self.prev_cycle_id = sorted_cycles[current_index - 1] + return sorted_cycles[current_index - 1] + else: + # Return None or False if there is no previous cycle + return None + + def get_next_cycle(self): + self.ensure_one() + if self.next_cycle_id: + return self.next_cycle_id + else: + sorted_cycles = self.program_id.cycle_ids.sorted(key="create_date") + current_index = sorted_cycles.ids.index(self.id) + if current_index < len(sorted_cycles) - 1: + # Return the next cycle + self.next_cycle_id = sorted_cycles[current_index + 1] + return sorted_cycles[current_index + 1] + else: + # Return None or False if there is no next cycle + return None + def get_entitlements( self, state, diff --git a/spp_programs/models/managers/cycle_manager.py b/spp_programs/models/managers/cycle_manager.py index c3fbed972..faa688a15 100644 --- a/spp_programs/models/managers/cycle_manager.py +++ b/spp_programs/models/managers/cycle_manager.py @@ -37,3 +37,11 @@ def _prepare_entitlements(self, cycle, offset=0, limit=None, do_count=False): # Update Statistics cycle._compute_inkind_entitlements_count() return + + def new_cycle(self, name, new_start_date, sequence): + for rec in self: + latest_cycle = rec.program_id.cycle_ids.sorted(key="create_date", reverse=True)[:1] + cycle = super(CustomDefaultCycleManager, rec).new_cycle(name, new_start_date, sequence) + latest_cycle.write({"next_cycle_id": cycle.id}) + cycle.write({"prev_cycle_id": latest_cycle.id}) + return cycle From 5ab6f76d85531d18ee2aa58d0aae0cbeb496f7b6 Mon Sep 17 00:00:00 2001 From: red Date: Mon, 20 Jan 2025 11:03:31 +0800 Subject: [PATCH 3/3] [RMV] spp_programs_compliance_criteria: remove unnecessary code --- spp_programs_compliance_criteria/views/g2p_program_views.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spp_programs_compliance_criteria/views/g2p_program_views.xml b/spp_programs_compliance_criteria/views/g2p_program_views.xml index deacf6532..b48b55cda 100644 --- a/spp_programs_compliance_criteria/views/g2p_program_views.xml +++ b/spp_programs_compliance_criteria/views/g2p_program_views.xml @@ -19,7 +19,7 @@ title="Open Form" class="btn-success" invisible="not manager_ref_id" - context="{'default_program_id': id, 'create': False, 'compliance_manager': True}" + context="{'default_program_id': id, 'create': False}" />