Skip to content

Commit c69e40b

Browse files
Merge pull request #316 from lalithkota/17.0-develop
G2P Support Desk module fixed. Merged 1.3 into develop.
2 parents 4743ecd + 5b6d7cf commit c69e40b

14 files changed

Lines changed: 329 additions & 287 deletions

File tree

g2p_entitlement_differential/i18n/g2p_entitlement_differential.pot

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,23 @@ msgstr ""
1313
"Content-Transfer-Encoding: \n"
1414
"Plural-Forms: \n"
1515

16+
#. module: g2p_entitlement_differential
17+
#: model:ir.model.fields,field_description:g2p_entitlement_differential.field_g2p_program_entitlement_manager_cash_item__amount_field
18+
msgid "Amount Field"
19+
msgstr ""
20+
21+
#. module: g2p_entitlement_differential
22+
#. odoo-python
23+
#: code:addons/g2p_entitlement_differential/models/entitlement_manager.py:0
24+
#, python-format
25+
msgid "Amount Field can't be empty in case of Dynamic Field Amount Type"
26+
msgstr ""
27+
28+
#. module: g2p_entitlement_differential
29+
#: model:ir.model.fields,field_description:g2p_entitlement_differential.field_g2p_program_entitlement_manager_cash_item__amount_type
30+
msgid "Amount Type"
31+
msgstr ""
32+
1633
#. module: g2p_entitlement_differential
1734
#: model:ir.model,name:g2p_entitlement_differential.model_g2p_program_entitlement_manager_cash
1835
msgid "Cash Entitlement Manager"
@@ -23,6 +40,16 @@ msgstr ""
2340
msgid "Cash Entitlement Manager Items"
2441
msgstr ""
2542

43+
#. module: g2p_entitlement_differential
44+
#: model:ir.model.fields.selection,name:g2p_entitlement_differential.selection__g2p_program_entitlement_manager_cash_item__amount_type__constant
45+
msgid "Constant"
46+
msgstr ""
47+
48+
#. module: g2p_entitlement_differential
49+
#: model:ir.model.fields.selection,name:g2p_entitlement_differential.selection__g2p_program_entitlement_manager_cash_item__amount_type__dynamic_field
50+
msgid "Dynamic Field"
51+
msgstr ""
52+
2653
#. module: g2p_entitlement_differential
2754
#: model:ir.model.fields,field_description:g2p_entitlement_differential.field_g2p_program_entitlement_manager_cash__enable_inflation
2855
#: model_terms:ir.ui.view,arch_db:g2p_entitlement_differential.view_entitlement_manager_cash_form_diff_inherit
@@ -38,3 +65,10 @@ msgstr ""
3865
#: model:ir.model.fields,field_description:g2p_entitlement_differential.field_g2p_program_entitlement_manager_cash_item__name
3966
msgid "Name"
4067
msgstr ""
68+
69+
#. module: g2p_entitlement_differential
70+
#. odoo-python
71+
#: code:addons/g2p_entitlement_differential/models/entitlement_manager.py:0
72+
#, python-format
73+
msgid "There are no items entered for this entitlement manager."
74+
msgstr ""

g2p_entitlement_differential/models/entitlement_manager.py

Lines changed: 117 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Part of OpenG2P. See LICENSE file for full copyright and licensing details.
2+
import logging
23

3-
from odoo import fields, models
4+
from odoo import _, api, fields, models
5+
from odoo.exceptions import UserError
6+
7+
_logger = logging.getLogger(__name__)
48

59

610
class G2PCashEntitlementManager(models.Model):
@@ -18,20 +22,108 @@ def _get_all_beneficiaries(self, all_beneficiaries_ids, condition, evaluate_one_
1822
return beneficiaries_ids
1923
return all_beneficiaries_ids
2024

21-
def prepare_entitlements(self, cycle, beneficiaries):
22-
res = super().prepare_entitlements(cycle, beneficiaries)
25+
def prepare_entitlements(self, cycle, beneficiaries): # noqa: C901
26+
# NOTE: This method is an enriched implementation of the prepare_entitlements method
27+
# from spp_entitlement_cash (by OpenSPP):
28+
# <https://github.com/OpenSPP/openspp-modules/tree/17.0/spp_entitlement_cash>
29+
30+
# TODO: Refactor this method once a dedicated _compute_entitlement_amount method is introduced.
31+
if not self.entitlement_item_ids:
32+
raise UserError(_("There are no items entered for this entitlement manager."))
2333

2434
all_beneficiaries_ids = beneficiaries.mapped("partner_id.id")
2535

26-
for ben in all_beneficiaries_ids:
27-
entitlement = self.env["g2p.entitlement"].search(
28-
[("partner_id", "=", ben), ("cycle_id", "=", cycle.id)]
36+
new_entitlements_to_create = {}
37+
for rec in self.entitlement_item_ids:
38+
_logger.info(f"Rec Amount: {rec.amount}")
39+
if rec.condition:
40+
beneficiaries_ids = self._get_all_beneficiaries(
41+
all_beneficiaries_ids, rec.condition, self.evaluate_one_item
42+
)
43+
else:
44+
beneficiaries_ids = all_beneficiaries_ids
45+
_logger.info(f"Beneficiaries IDs: {beneficiaries_ids}")
46+
47+
beneficiaries_with_entitlements = (
48+
self.env["g2p.entitlement"]
49+
.search(
50+
[
51+
("cycle_id", "=", cycle.id),
52+
("partner_id", "in", beneficiaries_ids),
53+
]
54+
)
55+
.mapped("partner_id.id")
2956
)
30-
if entitlement:
31-
if self.inflation_rate and self.enable_inflation:
32-
entitlement.initial_amount = entitlement.initial_amount * self.inflation_rate
57+
entitlements_to_create = [
58+
beneficiaries_id
59+
for beneficiaries_id in beneficiaries_ids
60+
if beneficiaries_id not in beneficiaries_with_entitlements
61+
]
62+
63+
entitlement_start_validity = cycle.start_date
64+
entitlement_end_validity = cycle.end_date
65+
entitlement_currency = rec.currency_id.id
66+
67+
beneficiaries_with_entitlements_to_create = self.env["res.partner"].browse(entitlements_to_create)
68+
69+
for beneficiary_id in beneficiaries_with_entitlements_to_create:
70+
if rec.multiplier_field:
71+
# Get the multiplier value from multiplier_field else return the default multiplier=1
72+
multiplier = beneficiary_id.mapped(rec.multiplier_field.name)
73+
if multiplier:
74+
multiplier = multiplier[0] or 0
75+
else:
76+
multiplier = 1
77+
if rec.max_multiplier > 0 and multiplier > rec.max_multiplier:
78+
multiplier = rec.max_multiplier
79+
_logger.info(f"Multiplier: {multiplier}")
3380

34-
return res
81+
amount = 0.0
82+
if rec.amount_type == "dynamic_field":
83+
if not rec.amount_field:
84+
raise UserError(_("Amount Field can't be empty in case of Dynamic Field Amount Type"))
85+
else:
86+
amount_field = beneficiary_id.mapped(rec.amount_field.name)
87+
if amount_field:
88+
amount_field = amount_field[0] or 0
89+
amount = float(amount_field) * float(multiplier)
90+
else:
91+
amount = rec.amount * float(multiplier)
92+
93+
# Compute the sum of cash entitlements
94+
if beneficiary_id.id in new_entitlements_to_create:
95+
amount = amount + new_entitlements_to_create[beneficiary_id.id]["initial_amount"]
96+
# Check if amount > max_amount; ignore if max_amount is set to 0
97+
if self.max_amount > 0.0 and amount > self.max_amount:
98+
amount = self.max_amount
99+
100+
new_entitlements_to_create[beneficiary_id.id] = {
101+
"cycle_id": cycle.id,
102+
"partner_id": beneficiary_id.id,
103+
"initial_amount": amount,
104+
"currency_id": entitlement_currency,
105+
"state": "draft",
106+
"is_cash_entitlement": True,
107+
"valid_from": entitlement_start_validity,
108+
"valid_until": entitlement_end_validity,
109+
}
110+
# Check if there are additional fields to be added in entitlements
111+
addl_fields = self._get_addl_entitlement_fields(beneficiary_id)
112+
if addl_fields:
113+
new_entitlements_to_create[beneficiary_id.id].update(addl_fields)
114+
115+
# Create entitlement records
116+
for ent in new_entitlements_to_create:
117+
initial_amount = new_entitlements_to_create[ent]["initial_amount"]
118+
new_entitlements_to_create[ent]["initial_amount"] = self._check_subsidy(initial_amount)
119+
if self.inflation_rate and self.enable_inflation:
120+
new_entitlements_to_create[ent]["initial_amount"] = (
121+
new_entitlements_to_create[ent]["initial_amount"] * self.inflation_rate
122+
)
123+
124+
# Create non-zero entitlements only
125+
if new_entitlements_to_create[ent]["initial_amount"] > 0.0:
126+
self.env["g2p.entitlement"].create(new_entitlements_to_create[ent])
35127

36128
def show_approve_entitlements(self, entitlement):
37129
# TODO: Enable the multi-stage entitlement approval
@@ -42,3 +134,18 @@ class G2PCashEntitlementItem(models.Model):
42134
_inherit = "g2p.program.entitlement.manager.cash.item"
43135

44136
name = fields.Char()
137+
138+
amount_type = fields.Selection(
139+
[("constant", "Constant"), ("dynamic_field", "Dynamic Field")], default="constant", required=True
140+
)
141+
amount_field = fields.Many2one(
142+
"ir.model.fields",
143+
domain=[("model_id.model", "=", "res.partner"), ("ttype", "=", "integer")],
144+
)
145+
146+
@api.onchange("amount_type")
147+
def onchange_amount_type(self):
148+
if self.amount_type == "dynamic_field":
149+
self.amount = 0.0
150+
else:
151+
self.amount_field = None

g2p_entitlement_differential/views/entitlement_manager_view.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,22 @@ Part of OpenG2P. See LICENSE file for full copyright and licensing details.
2424
>
2525
<field name="name" />
2626
</xpath>
27+
<xpath expr="//field[@name='entitlement_item_ids']/tree/field[@name='amount']" position="replace">
28+
<field name="amount_type" />
29+
<field name="amount_field" invisible="amount_type == 'constant'" />
30+
<field name="amount" invisible="amount_type == 'dynamic_field'" />
31+
</xpath>
2732
<xpath expr="//field[@name='entitlement_item_ids']/form/group/field" position="before">
2833
<field name="name" />
2934
</xpath>
35+
<xpath
36+
expr="//field[@name='entitlement_item_ids']/form/group/field[@name='amount']"
37+
position="replace"
38+
>
39+
<field name="amount_type" />
40+
<field name="amount_field" invisible="amount_type == 'constant'" />
41+
<field name="amount" invisible="amount_type == 'dynamic_field'" />
42+
</xpath>
3043
</field>
3144
</record>
3245
</odoo>

g2p_payment_g2p_connect/models/payment_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def payments_status_check(self, id_):
268268
}
269269
try:
270270
_logger.info("G2P Connect Disbursement Status Data: %s", status_data)
271-
token = self.create_jwt_token(json.dumps(status_data, separators=(",", ":")))
271+
token = payment_manager.create_jwt_token(json.dumps(status_data, separators=(",", ":")))
272272
headers = {
273273
"Accept": "application/json",
274274
"Content-Type": "application/json",

g2p_support_desk/models/support_ticket.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class SupportTicket(models.Model):
6060
# response_time = fields.Float(
6161
# string="Response Time (Hours)", readonly=True, compute="_compute_response_time", store=True
6262
# )
63+
resolution_message = fields.Html()
6364
resolution_time = fields.Float(string="Resolution Time (Hours)")
6465

6566
def action_assign_to_me(self):

g2p_support_desk/views/support_ticket_views.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@
7272
<page string="Description" name="description">
7373
<field name="description" placeholder="Add a description..." />
7474
</page>
75+
<page string="Resolution" name="resolution">
76+
<group>
77+
<field name="resolution_message" placeholder="Add a resolution..." />
78+
<field name="resolution_time" />
79+
</group>
80+
</page>
7581
</notebook>
7682
</sheet>
7783
<div class="oe_chatter">

g2p_theme/__manifest__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"author": "OpenG2P",
77
"website": "https://openg2p.org",
88
"license": "LGPL-3",
9-
"depends": ["base", "web", "auth_signup", "website"],
9+
"depends": ["base", "web", "auth_signup"],
1010
"data": [
1111
"templates/g2p_login_page.xml",
1212
"templates/g2p_reset_password.xml",
@@ -18,7 +18,7 @@
1818
"g2p_theme/static/src/css/style.css",
1919
],
2020
"web.assets_frontend": [
21-
"g2p_theme/static/src/scss/new_login_page.scss",
21+
"g2p_theme/static/src/scss/g2p_login_page.scss",
2222
],
2323
},
2424
"demo": [],

g2p_theme/i18n/g2p_theme.pot

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ msgstr ""
5454

5555
#. module: g2p_theme
5656
#: model_terms:ir.ui.view,arch_db:g2p_theme.g2p_reset_password
57-
#: model_terms:ir.ui.view,arch_db:g2p_theme.login
5857
msgid "Logo"
5958
msgstr ""
6059

@@ -80,3 +79,8 @@ msgstr ""
8079
#: model_terms:ir.ui.view,arch_db:g2p_theme.g2p_reset_password
8180
msgid "Your Email / Username"
8281
msgstr ""
82+
83+
#. module: g2p_theme
84+
#: model_terms:ir.ui.view,arch_db:g2p_theme.login
85+
msgid "organization Logo"
86+
msgstr ""

g2p_theme/static/src/scss/assets_menu.scss

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)