-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #429 from OpenSPP/inkind-entitlement-multi-approve
added multi approve feature for in-kind entitlement
- Loading branch information
Showing
6 changed files
with
161 additions
and
0 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
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
98 changes: 98 additions & 0 deletions
98
spp_programs/wizard/multi_inkind_entitlement_approval_wizard.py
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,98 @@ | ||
from odoo import api, fields, models | ||
|
||
|
||
class MultiInKindEntitlementApprovalWiz(models.TransientModel): | ||
_name = "spp.multi.inkind.entitlement.approval.wizard" | ||
_description = "Multi In-Kind Entitlement Approval Wizard" | ||
|
||
@api.model | ||
def default_get(self, fields): | ||
res = super().default_get(fields) | ||
if self.env.context.get("active_ids"): | ||
entitlement_ids = [] | ||
for rec in self.env.context.get("active_ids"): | ||
entitlement = self.env["g2p.entitlement.inkind"].search( | ||
[ | ||
("id", "=", rec), | ||
] | ||
) | ||
if entitlement.state in ("draft", "pending_validation"): | ||
entitlement_ids.append([0, 0, {"entitlement_id": rec}]) | ||
res["entitlement_ids"] = entitlement_ids | ||
|
||
return res | ||
|
||
entitlement_ids = fields.One2many( | ||
"spp.multi.inkind.entitlement.approval", | ||
"wizard_id", | ||
string="Entitlements", | ||
required=True, | ||
) | ||
|
||
def approve_entitlements(self): | ||
if self.entitlement_ids: | ||
self.entitlement_ids.entitlement_id.approve_entitlement() | ||
|
||
def open_wizard(self): | ||
return { | ||
"name": "Multiple Inkind Entitlements Approval", | ||
"view_mode": "form", | ||
"res_model": "spp.multi.inkind.entitlement.approval.wizard", | ||
"view_id": self.env.ref("spp_programs.multi_inkind_entitlement_approval_wizard_form_view").id, | ||
"type": "ir.actions.act_window", | ||
"target": "new", | ||
"nodestroy": True, | ||
"context": self.env.context, | ||
} | ||
|
||
def close_wizard(self): | ||
return {"type": "ir.actions.act_window_close"} | ||
|
||
|
||
class MultiInKindEntitlementApproval(models.TransientModel): | ||
_name = "spp.multi.inkind.entitlement.approval" | ||
_description = "In-Kind Entitlement Approval" | ||
|
||
entitlement_id = fields.Many2one( | ||
"g2p.entitlement.inkind", | ||
"In-kind Entitlement", | ||
required=True, | ||
) | ||
|
||
wizard_id = fields.Many2one( | ||
"spp.multi.inkind.entitlement.approval.wizard", | ||
"Multi In-kind Entitlement Approval Wizard", | ||
required=True, | ||
) | ||
|
||
partner_id = fields.Many2one( | ||
"res.partner", | ||
"Registrant", | ||
related="entitlement_id.partner_id", | ||
) | ||
code = fields.Char(related="entitlement_id.code") | ||
|
||
product_id = fields.Many2one( | ||
"product.product", | ||
"Product", | ||
related="entitlement_id.product_id", | ||
) | ||
|
||
qty = fields.Integer("QTY", related="entitlement_id.qty") | ||
currency_id = fields.Many2one("res.currency", related="entitlement_id.currency_id") | ||
unit_price = fields.Monetary(string="Value/Unit", currency_field="currency_id", related="entitlement_id.unit_price") | ||
total_amount = fields.Monetary( | ||
string="Total Value", currency_field="currency_id", related="entitlement_id.total_amount" | ||
) | ||
|
||
state = fields.Selection( | ||
[ | ||
("New", "New"), | ||
("Okay", "Okay"), | ||
("Conflict", "Conflict"), | ||
("Approved", "Approved"), | ||
], | ||
"Status", | ||
readonly=True, | ||
default="New", | ||
) |
50 changes: 50 additions & 0 deletions
50
spp_programs/wizard/multi_inkind_entitlement_approval_wizard.xml
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,50 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
<record id="multi_inkind_entitlement_approval_wizard_form_view" model="ir.ui.view"> | ||
<field name="name">multi_inkind_entitlement_approval_wizard_form_view</field> | ||
<field name="model">spp.multi.inkind.entitlement.approval.wizard</field> | ||
<field name="arch" type="xml"> | ||
<form> | ||
<sheet> | ||
<field name="entitlement_ids" nolabel="1" colspan="2"> | ||
<tree create="0" editable="bottom"> | ||
<field name="entitlement_id" invisible="1" /> | ||
<field name="partner_id" readonly="1" /> | ||
<field name="code" readonly="1" /> | ||
<field name="product_id" /> | ||
<field name="qty" /> | ||
<field name="unit_price" /> | ||
<field name="total_amount" /> | ||
<field name="currency_id" invisible="1" /> | ||
<field | ||
name="state" | ||
decoration-secondary="state=='New'" | ||
decoration-primary="state=='Okay'" | ||
decoration-success="state=='Approved'" | ||
decoration-danger="state=='Conflict'" | ||
widget="badge" | ||
readonly="1" | ||
/> | ||
</tree> | ||
</field> | ||
</sheet> | ||
<footer> | ||
<button | ||
name="approve_entitlements" | ||
string="Approve" | ||
type="object" | ||
class="oe_highlight" | ||
title="Approve entitlement" | ||
/> | ||
<button | ||
name="close_wizard" | ||
string="Cancel" | ||
type="object" | ||
class="btn-secondary" | ||
title="Cancel" | ||
/> | ||
</footer> | ||
</form> | ||
</field> | ||
</record> | ||
</odoo> |