Skip to content

Commit

Permalink
[ADD] spp_programs: Add access roles for programs, cycles, and entitl…
Browse files Browse the repository at this point in the history
…ements
  • Loading branch information
reichie020212 committed Dec 12, 2024
1 parent 6603290 commit 99d3b58
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 2 deletions.
2 changes: 2 additions & 0 deletions spp_programs/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"product",
"stock",
"spp_user_roles",
"spp_registry_base",
],
"data": [
"data/user_roles.xml",
Expand All @@ -33,6 +34,7 @@
"views/inkind_entitlement_report_view.xml",
"views/managers/eligibility_manager_view.xml",
"views/managers/entitlement_manager_view.xml",
"views/g2p_entitlement_view.xml",
"wizard/inkind_entitlement_report_wiz.xml",
"wizard/create_program_wizard.xml",
"wizard/multi_inkind_entitlement_approval_wizard.xml",
Expand Down
1 change: 1 addition & 0 deletions spp_programs/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
from . import managers
from . import programs
from . import eligibility
from . import g2p_entitlement
58 changes: 58 additions & 0 deletions spp_programs/models/g2p_entitlement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from odoo import SUPERUSER_ID, _, api, fields, models


class G2PEntitlement(models.Model):
_inherit = "g2p.entitlement"

state = fields.Selection(
selection_add=[("reject", "Rejected")],
)

@api.model
def _get_view(self, view_id=None, view_type="form", **options):
# to bypass the validation in g2p_programs/models/entitlement.py
if not self.env.user.has_group("g2p_registry_base.group_g2p_admin"):
other_user = self.env["res.users"].browse(SUPERUSER_ID)
self = self.with_user(other_user)

arch, view = super()._get_view(view_id, view_type, **options)

return arch, view

def reject_entitlement(self):
if self.env.user.has_group("spp_programs.approve_entitlement"):
for rec in self.sudo():
rec.state = "reject"

return {
"type": "ir.actions.client",
"tag": "display_notification",
"params": {
"title": _("Entitlement"),
"message": "Entitlement Rejected",
"sticky": False,
"type": "danger",
"next": {
"type": "ir.actions.act_window_close",
},
},
}
else:
return {
"type": "ir.actions.client",
"tag": "display_notification",
"params": {
"title": _("Entitlement"),
"message": "You are not authorized to reject entitlement",
"sticky": False,
"type": "danger",
"next": {
"type": "ir.actions.act_window_close",
},
},
}

def approve_entitlement(self):
if self.env.user.has_group("spp_programs.approve_entitlement"):
super(G2PEntitlement, self.sudo()).approve_entitlement()
super().approve_entitlement()
55 changes: 55 additions & 0 deletions spp_programs/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ spp_programs_stock_route_program_validator,SPP Entitlement Stock Location Route
spp_programs_stock_move_program_validator,SPP Entitlement Stock Move Program Validator Access,stock.model_stock_move,g2p_programs.g2p_program_validator,1,1,1,0
spp_programs_stock_rule_program_validator,SPP Entitlement Stock Rule Program Validator Access,stock.model_stock_rule,g2p_programs.g2p_program_validator,1,0,0,0

g2p_programs.g2p_program_manager_access,Program Manager Access,g2p_programs.model_g2p_program,base.group_user,1,0,0,0

read_ui_view_access,Read UI View Access,base.model_ir_ui_view,spp_programs.read_program_cycle_entitlement,1,0,0,0
read_program_access,Read Program Access,g2p_programs.model_g2p_program,spp_programs.read_program_cycle_entitlement,1,0,0,0
read_program_membership_access,Read Program Membership Access,g2p_programs.model_g2p_program_membership,spp_programs.read_program_cycle_entitlement,1,0,0,0
Expand All @@ -67,3 +69,56 @@ read_program_entitlement_manager_access,Read Program Entitlement Manager Access,
read_program_entitlement_manager_default_access,Read Program Entitlement Default Manager Access,g2p_programs.model_g2p_program_entitlement_manager_default,spp_programs.read_program_cycle_entitlement,1,0,0,0
read_program_payment_manager_access,Read Program Payment Manager Access,g2p_programs.model_g2p_program_payment_manager,spp_programs.read_program_cycle_entitlement,1,0,0,0
read_program_payment_manager_default_access,Read Program Payment Manager Default Access,g2p_programs.model_g2p_program_payment_manager_default,spp_programs.read_program_cycle_entitlement,1,0,0,0

write_ui_view_access,Write UI View Access,base.model_ir_ui_view,spp_programs.write_program_cycle_entitlement,1,1,0,0
write_program_access,Write Program Access,g2p_programs.model_g2p_program,spp_programs.write_program_cycle_entitlement,1,1,0,0
write_program_membership_access,Write Program Membership Access,g2p_programs.model_g2p_program_membership,spp_programs.write_program_cycle_entitlement,1,1,1,0
write_cycle_access,Write Cycle Access,g2p_programs.model_g2p_cycle,spp_programs.write_program_cycle_entitlement,1,1,0,0
write_cycle_membership_access,Write Cycle Membership Access,g2p_programs.model_g2p_cycle_membership,spp_programs.write_program_cycle_entitlement,1,1,1,0
write_entitlement_access,Write Entitlement Access,g2p_programs.model_g2p_entitlement,spp_programs.write_program_cycle_entitlement,1,1,0,0
write_entitlement_inkind_access,Write Entitlement Inkind Access,spp_programs.model_g2p_entitlement_inkind,spp_programs.write_program_cycle_entitlement,1,1,0,0
write_payment_access,Write Payment Access,g2p_programs.model_g2p_payment,spp_programs.write_program_cycle_entitlement,1,1,0,0
write_payment_batch_access,Write Payment Batch Access,g2p_programs.model_g2p_payment_batch,spp_programs.write_program_cycle_entitlement,1,1,0,0
write_eligibility_manager_access,Write Eligibility Manager Access,g2p_programs.model_g2p_eligibility_manager,spp_programs.write_program_cycle_entitlement,1,1,0,0
write_program_membership_manager_default_access,Write Program Membership Manager Default Access,g2p_programs.model_g2p_program_membership_manager_default,spp_programs.write_program_cycle_entitlement,1,1,0,0
write_deduplication_manager_access,Write Deduplication Manager Access,g2p_programs.model_g2p_deduplication_manager,spp_programs.write_program_cycle_entitlement,1,1,0,0
write_deduplication_manager_default_access,Write Deduplication Manager Default Access,g2p_programs.model_g2p_deduplication_manager_default,spp_programs.write_program_cycle_entitlement,1,1,0,0
write_program_notification_manager_access,Write Program Notification Manager Access,g2p_programs.model_g2p_program_notification_manager,spp_programs.write_program_cycle_entitlement,1,1,0,0
write_program_notification_manager_sms_access,Write Program Notification Manager SMS Access,g2p_programs.model_g2p_program_notification_manager_sms,spp_programs.write_program_cycle_entitlement,1,1,0,0
write_program_manager_access,Write Program Manager Access,g2p_programs.model_g2p_program_manager,spp_programs.write_program_cycle_entitlement,1,1,0,0
write_program_manager_default_access,Write Program Manager Default Access,g2p_programs.model_g2p_program_manager_default,spp_programs.write_program_cycle_entitlement,1,1,0,0
write_cycle_manager_access,Write Cycle Manager Access,g2p_programs.model_g2p_cycle_manager,spp_programs.write_program_cycle_entitlement,1,1,0,0
write_cycle_manager_default_access,Write Cycle Manager Default Access,g2p_programs.model_g2p_cycle_manager_default,spp_programs.write_program_cycle_entitlement,1,1,0,0
write_program_entitlement_manager_access,Write Program Entitlement Manager Access,g2p_programs.model_g2p_program_entitlement_manager,spp_programs.write_program_cycle_entitlement,1,1,0,0
write_program_entitlement_manager_default_access,Write Program Entitlement Default Manager Access,g2p_programs.model_g2p_program_entitlement_manager_default,spp_programs.write_program_cycle_entitlement,1,1,0,0
write_program_payment_manager_access,Write Program Payment Manager Access,g2p_programs.model_g2p_program_payment_manager,spp_programs.write_program_cycle_entitlement,1,1,0,0
write_program_payment_manager_default_access,Write Program Payment Manager Default Access,g2p_programs.model_g2p_program_payment_manager_default,spp_programs.write_program_cycle_entitlement,1,1,0,0

create_ui_view_access,Create UI View Access,base.model_ir_ui_view,spp_programs.create_program_cycle_entitlement,1,0,1,0
create_program_access,Create Program Access,g2p_programs.model_g2p_program,spp_programs.create_program_cycle_entitlement,1,0,1,0
create_program_membership_access,Create Program Membership Access,g2p_programs.model_g2p_program_membership,spp_programs.create_program_cycle_entitlement,1,1,1,0
create_cycle_access,Create Cycle Access,g2p_programs.model_g2p_cycle,spp_programs.create_program_cycle_entitlement,1,0,1,0
create_cycle_membership_access,Create Cycle Membership Access,g2p_programs.model_g2p_cycle_membership,spp_programs.create_program_cycle_entitlement,1,1,1,0
create_entitlement_access,Create Entitlement Access,g2p_programs.model_g2p_entitlement,spp_programs.create_program_cycle_entitlement,1,0,1,0
create_entitlement_inkind_access,Create Entitlement Inkind Access,spp_programs.model_g2p_entitlement_inkind,spp_programs.create_program_cycle_entitlement,1,0,1,0
create_payment_access,Create Payment Access,g2p_programs.model_g2p_payment,spp_programs.create_program_cycle_entitlement,1,0,1,0
create_payment_batch_access,Create Payment Batch Access,g2p_programs.model_g2p_payment_batch,spp_programs.create_program_cycle_entitlement,1,0,1,0
create_eligibility_manager_access,Create Eligibility Manager Access,g2p_programs.model_g2p_eligibility_manager,spp_programs.create_program_cycle_entitlement,1,0,1,0
create_program_membership_manager_default_access,Create Program Membership Manager Default Access,g2p_programs.model_g2p_program_membership_manager_default,spp_programs.create_program_cycle_entitlement,1,0,1,0
create_deduplication_manager_access,Create Deduplication Manager Access,g2p_programs.model_g2p_deduplication_manager,spp_programs.create_program_cycle_entitlement,1,0,1,0
create_deduplication_manager_default_access,Create Deduplication Manager Default Access,g2p_programs.model_g2p_deduplication_manager_default,spp_programs.create_program_cycle_entitlement,1,0,1,0
create_program_notification_manager_access,Create Program Notification Manager Access,g2p_programs.model_g2p_program_notification_manager,spp_programs.create_program_cycle_entitlement,1,0,1,0
create_program_notification_manager_sms_access,Create Program Notification Manager SMS Access,g2p_programs.model_g2p_program_notification_manager_sms,spp_programs.create_program_cycle_entitlement,1,0,1,0
create_program_manager_access,Create Program Manager Access,g2p_programs.model_g2p_program_manager,spp_programs.create_program_cycle_entitlement,1,0,1,0
create_program_manager_default_access,Create Program Manager Default Access,g2p_programs.model_g2p_program_manager_default,spp_programs.create_program_cycle_entitlement,1,0,1,0
create_cycle_manager_access,Create Cycle Manager Access,g2p_programs.model_g2p_cycle_manager,spp_programs.create_program_cycle_entitlement,1,0,1,0
create_cycle_manager_default_access,Create Cycle Manager Default Access,g2p_programs.model_g2p_cycle_manager_default,spp_programs.create_program_cycle_entitlement,1,0,1,0
create_program_entitlement_manager_access,Create Program Entitlement Manager Access,g2p_programs.model_g2p_program_entitlement_manager,spp_programs.create_program_cycle_entitlement,1,0,1,0
create_program_entitlement_manager_default_access,Create Program Entitlement Default Manager Access,g2p_programs.model_g2p_program_entitlement_manager_default,spp_programs.create_program_cycle_entitlement,1,0,1,0
create_program_payment_manager_access,Create Program Payment Manager Access,g2p_programs.model_g2p_program_payment_manager,spp_programs.create_program_cycle_entitlement,1,0,1,0
create_program_payment_manager_default_access,Create Program Payment Manager Default Access,g2p_programs.model_g2p_program_payment_manager_default,spp_programs.create_program_cycle_entitlement,1,0,1,0
create_program_wizard_access,Create Program Wizard Access,g2p_programs.model_g2p_program_create_wizard,spp_programs.create_program_cycle_entitlement,1,1,1,0

approve_entitlement_access,Approve Entitlement Access,g2p_programs.model_g2p_entitlement,spp_programs.approve_entitlement,1,0,0,0

reject_entitlement_access,Reject Entitlement Access,g2p_programs.model_g2p_entitlement,spp_programs.reject_entitlement,1,0,0,0
26 changes: 25 additions & 1 deletion spp_programs/security/security_access.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
<record model="ir.module.category" id="program_access_module">
<field name="name">Program Access</field>
<field name="description">User access level for Program</field>
<field name="sequence">3</field>
<field name="sequence">10</field>
</record>

<record id="read_program_cycle_entitlement" model="res.groups">
<field name="name">Read Program/Cycle/Entitlement</field>
<field name="category_id" ref="spp_programs.program_access_module" />
<field name="implied_ids" eval="[Command.link(ref('spp_registry_base.read_registry'))]" />
<field
name="users"
eval="[Command.link(ref('base.user_root')), Command.link(ref('base.user_admin'))]"
Expand All @@ -27,6 +28,29 @@
<record id="create_program_cycle_entitlement" model="res.groups">
<field name="name">Create Program/Cycle/Entitlement</field>
<field name="category_id" ref="spp_programs.program_access_module" />
<field
name="implied_ids"
eval="[Command.link(ref('spp_programs.write_program_cycle_entitlement')), Command.link(ref('g2p_programs.g2p_program_manager'))]"
/>
<field
name="users"
eval="[Command.link(ref('base.user_root')), Command.link(ref('base.user_admin'))]"
/>
</record>

<record id="approve_entitlement" model="res.groups">
<field name="name">Approve Entitlement</field>
<field name="category_id" ref="spp_programs.program_access_module" />
<field name="implied_ids" eval="[Command.link(ref('spp_programs.read_program_cycle_entitlement'))]" />
<field
name="users"
eval="[Command.link(ref('base.user_root')), Command.link(ref('base.user_admin'))]"
/>
</record>

<record id="reject_entitlement" model="res.groups">
<field name="name">Reject Entitlement</field>
<field name="category_id" ref="spp_programs.program_access_module" />
<field name="implied_ids" eval="[Command.link(ref('spp_programs.read_program_cycle_entitlement'))]" />
<field
name="users"
Expand Down
28 changes: 28 additions & 0 deletions spp_programs/views/cycle_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,34 @@ Part of OpenSPP. See LICENSE file for full copyright and licensing details.
<xpath expr="//button[@name='copy_beneficiaries_from_program']" position="attributes">
<attribute name="string">Copy New Beneficiaries from Program</attribute>
<attribute name="title">Copy New Beneficiaries from Program</attribute>
<attribute
name="groups"
>g2p_registry_base.group_g2p_admin,g2p_programs.g2p_program_manager,spp_programs.write_program_cycle_entitlement</attribute>
</xpath>
<xpath expr="//button[@name='check_eligibility']" position="attributes">
<attribute
name="groups"
>g2p_registry_base.group_g2p_admin,g2p_programs.g2p_program_manager,spp_programs.write_program_cycle_entitlement</attribute>
</xpath>
<xpath expr="//button[@name='prepare_entitlement']" position="attributes">
<attribute
name="groups"
>g2p_registry_base.group_g2p_admin,g2p_programs.g2p_program_manager,spp_programs.create_program_cycle_entitlement</attribute>
</xpath>
<xpath expr="//button[@name='approve']" position="attributes">
<attribute
name="groups"
>g2p_registry_base.group_g2p_admin,g2p_programs.g2p_program_manager,g2p_programs.g2p_program_cycle_approver</attribute>
</xpath>
<xpath expr="//button[@name='to_approve']" position="attributes">
<attribute
name="groups"
>g2p_registry_base.group_g2p_admin,g2p_programs.g2p_program_manager,g2p_programs.g2p_program_cycle_approver</attribute>
</xpath>
<xpath expr="//button[@name='reset_draft']" position="attributes">
<attribute
name="groups"
>g2p_registry_base.group_g2p_admin,g2p_programs.g2p_program_manager,g2p_programs.g2p_program_cycle_approver</attribute>
</xpath>
<xpath expr="//button[@name='open_payments_form']" position="attributes">
<attribute name="icon">fa-file-text-o</attribute>
Expand Down
35 changes: 35 additions & 0 deletions spp_programs/views/g2p_entitlement_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="inherit_view_entitlement_form" model="ir.ui.view">
<field name="name">inherit_view_entitlement_form</field>
<field name="model">g2p.entitlement</field>
<field name="priority">1</field>
<field name="inherit_id" ref="g2p_programs.view_entitlement_form" />
<field name="arch" type="xml">
<xpath expr="//button[@name='approve_entitlement']" position="attributes">
<attribute
name="groups"
>g2p_registry_base.group_g2p_admin,g2p_programs.g2p_program_manager,g2p_programs.g2p_finance_validator,spp_programs.approve_entitlement</attribute>
</xpath>
<xpath expr="//button[@name='approve_entitlement']" position="after">
<button
type="object"
class="btn-danger"
icon="fa-thumbs-o-down"
name="reject_entitlement"
title="Reject entitlement"
invisible="state not in ('draft','pending_validation')"
string="Reject Entitlement"
confirm="Are you sure you want to reject this entitlement?"
groups="g2p_registry_base.group_g2p_admin,g2p_programs.g2p_program_manager,g2p_programs.g2p_finance_validator,spp_programs.reject_entitlement"
/>
</xpath>
</field>
</record>

<record id="g2p_programs.menu_entitlement" model="ir.ui.menu">
<field name="groups_id" eval="[(4,ref('spp_programs.read_program_cycle_entitlement'))]" />
</record>

</odoo>
Loading

0 comments on commit 99d3b58

Please sign in to comment.