-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] spp_programs: Add access roles for programs, cycles, and entitl…
…ements
- Loading branch information
1 parent
6603290
commit 99d3b58
Showing
8 changed files
with
224 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ | |
from . import managers | ||
from . import programs | ||
from . import eligibility | ||
from . import g2p_entitlement |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.