Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

added one time distribution in creating program in wizard #104

Merged
merged 2 commits into from
Sep 19, 2023
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
4 changes: 3 additions & 1 deletion spp_programs/models/programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

import logging

from odoo import _, models
from odoo import _, fields, models

_logger = logging.getLogger(__name__)


class CustomG2PProgram(models.Model):
_inherit = "g2p.program"

is_one_time_distribution = fields.Boolean("One-time Distribution")

def import_eligible_registrants(self, state="draft"):
eligibility_managers = self.get_managers(self.MANAGER_ELIGIBILITY)
if eligibility_managers:
Expand Down
10 changes: 10 additions & 0 deletions spp_programs/views/programs_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ Part of OpenSPP. See LICENSE file for full copyright and licensing details.
name="groups"
>!g2p_programs.g2p_program_validator, !g2p_programs.g2p_program_cycle_approver</attribute>
</xpath>

<xpath expr="//button[@name='create_new_cycle']" position="before">
<field name="is_one_time_distribution" invisible="1" />
</xpath>
<xpath expr="//button[@name='create_new_cycle']" position="attributes">
<attribute name="states" />
<attribute
name="attrs"
>{'invisible': ['|', ('is_one_time_distribution', '=', True), ('state', '!=', 'active')]}</attribute>
</xpath>
</field>
</record>

Expand Down
8 changes: 7 additions & 1 deletion spp_programs/wizard/create_program_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def _get_admin_area_domain(self):

admin_area_ids = fields.Many2many("spp.area", domain=_get_admin_area_domain)

# Tag-based Eligibility Manager
is_one_time_distribution = fields.Boolean("One-time Distribution")

eligibility_kind = fields.Selection(
[("default_eligibility", "Default")],
"Eligibility Manager",
Expand Down Expand Up @@ -89,12 +90,17 @@ def create_program(self):
# Set Default Entitlement Manager
vals.update(rec._get_entitlement_manager(program_id))

vals.update({"is_one_time_distribution": rec.is_one_time_distribution})

# Complete the program data
program.update(vals)

if rec.import_beneficiaries == "yes":
rec.program_wizard_import_beneficiaries(program)

if rec.is_one_time_distribution:
program.create_new_cycle()

# Open the newly created program
action = {
"name": _("Programs"),
Expand Down
16 changes: 16 additions & 0 deletions spp_programs/wizard/create_program_wizard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ Part of OpenSPP. See LICENSE file for full copyright and licensing details.
/>
</group>
</xpath>

<xpath expr="//page[@name='cycle']/group/div/group" position="before">
<group>
<field name="is_one_time_distribution" />
</group>
</xpath>

<xpath expr="//page[@name='cycle']/group/div/group[2]" position="attributes">
<attribute name="attrs">{'invisible': [('is_one_time_distribution', '=', True)]}</attribute>
</xpath>

<xpath expr="//page[@name='cycle']/group/div/group[3]" position="attributes">
<attribute
name="attrs"
>{'invisible': ['|', ('rrule_type', '!=', 'monthly'), ('is_one_time_distribution', '=', True)]}</attribute>
</xpath>
</field>
</record>
</odoo>