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

Commit

Permalink
Merge remote-tracking branch 'origin/117-select-the-card-type-in-the-…
Browse files Browse the repository at this point in the history
…entitlement-manager-to-be-used-in-recording-the-card-number-of-registrants-to-entitlements' into release/dev
  • Loading branch information
gonzalesedwin1123 committed Oct 19, 2023
2 parents 8222292 + 2c0d4c7 commit d929145
Show file tree
Hide file tree
Showing 18 changed files with 301 additions and 21 deletions.
21 changes: 21 additions & 0 deletions g2p_entitlement_cash/models/entitlement_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ def prepare_entitlements(self, cycle, beneficiaries):
"valid_from": entitlement_start_validity,
"valid_until": entitlement_end_validity,
}
# Check if there are additional fields to be added in entitlements
addl_fields = self._get_addl_entitlement_fields(beneficiary_id)
if addl_fields:
new_entitlements_to_create[beneficiary_id.id].update(addl_fields)

# Create entitlement records
for ent in new_entitlements_to_create:
Expand All @@ -158,6 +162,23 @@ def prepare_entitlements(self, cycle, beneficiaries):
if new_entitlements_to_create[ent]["initial_amount"] > 0.0:
self.env["g2p.entitlement"].create(new_entitlements_to_create[ent])

def _get_addl_entitlement_fields(self, beneficiary_id):
"""
This function must be overriden to add additional field to be written in the entitlements.
Add the id_number from the beneficiaries based on the id_type configured in entitlement manager.
"""
retval = None
if self.id_type:
id_docs = beneficiary_id.reg_ids.filtered(
lambda a: a.id_type.id == self.id_type.id
)
if id_docs:
id_number = id_docs[0].value
retval = {
"id_number": id_number,
}
return retval

def _get_all_beneficiaries(
self, all_beneficiaries_ids, condition, evaluate_one_item
):
Expand Down
5 changes: 4 additions & 1 deletion g2p_entitlement_cash/views/entitlement_manager_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,14 @@ Part of OpenSPP. See LICENSE file for full copyright and licensing details.
</group>
</form>
</field>
<field
name="id_type"
options="{'no_open':true,'no_create':true,'no_create_edit':true}"
/>
<field
name="entitlement_validation_group_id"
options="{'no_open':True,'no_create':True,'no_create_edit':True}"
domain="[('category_id','=',%(g2p_registry_base.openg2p_module)d)]"
colspan="4"
/>
</group>
<field name="currency_id" invisible="1" />
Expand Down
1 change: 1 addition & 0 deletions g2p_entitlement_cash/wizard/create_program_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def _get_entitlement_manager(self, program_id):
"entitlement_item_ids": entitlement_item_ids,
"max_amount": self.max_amount,
"entitlement_validation_group_id": self.entitlement_validation_group_id.id,
"id_type": self.id_type.id,
}
)

Expand Down
57 changes: 38 additions & 19 deletions spp_entitlement_in_kind/models/entitlement_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,28 +133,47 @@ def prepare_entitlements(self, cycle, beneficiaries):
multiplier = rec.max_multiplier
qty = multiplier * rec.qty

entitlements.append(
{
"cycle_id": cycle.id,
"partner_id": beneficiary_id.id,
"total_amount": rec.product_id.list_price * qty,
"product_id": rec.product_id.id,
"qty": qty,
"unit_price": rec.product_id.list_price,
"uom_id": rec.uom_id.id,
"manage_inventory": self.manage_inventory,
"warehouse_id": self.warehouse_id
and self.warehouse_id.id
or None,
"inkind_item_id": rec.id,
"state": "draft",
"valid_from": entitlement_start_validity,
"valid_until": entitlement_end_validity,
}
)
entitlement_fields = {
"cycle_id": cycle.id,
"partner_id": beneficiary_id.id,
"total_amount": rec.product_id.list_price * qty,
"product_id": rec.product_id.id,
"qty": qty,
"unit_price": rec.product_id.list_price,
"uom_id": rec.uom_id.id,
"manage_inventory": self.manage_inventory,
"warehouse_id": self.warehouse_id and self.warehouse_id.id or None,
"inkind_item_id": rec.id,
"state": "draft",
"valid_from": entitlement_start_validity,
"valid_until": entitlement_end_validity,
}
# Check if there are additional fields to be added in entitlements
addl_fields = self._get_addl_entitlement_fields(beneficiary_id)
if addl_fields:
entitlement_fields.update(addl_fields)
entitlements.append(entitlement_fields)

if entitlements:
self.env["g2p.entitlement.inkind"].create(entitlements)

def _get_addl_entitlement_fields(self, beneficiary_id):
"""
This function must be overriden to add additional field to be written in the entitlements.
Add the id_number from the beneficiaries based on the id_type configured in entitlement manager.
"""
retval = None
if self.id_type:
id_docs = beneficiary_id.reg_ids.filtered(
lambda a: a.id_type.id == self.id_type.id
)
if id_docs:
id_number = id_docs[0].value
retval = {
"id_number": id_number,
}
return retval

def set_pending_validation_entitlements(self, cycle):
"""Set In-Kind Entitlements to Pending Validation.
In-kind Entitlement Manager :meth:`set_pending_validation_entitlements`.
Expand Down
5 changes: 4 additions & 1 deletion spp_entitlement_in_kind/views/entitlement_manager_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,14 @@ Part of OpenSPP. See LICENSE file for full copyright and licensing details.
</group>
</form>
</field>
<field
name="id_type"
options="{'no_open':true,'no_create':true,'no_create_edit':true}"
/>
<field
name="entitlement_validation_group_id"
options="{'no_open':True,'no_create':True,'no_create_edit':True}"
domain="[('category_id','=',%(g2p_registry_base.openg2p_module)d)]"
colspan="4"
/>
</group>
</page>
Expand Down
1 change: 1 addition & 0 deletions spp_entitlement_in_kind/wizard/create_program_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def _get_entitlement_manager(self, program_id):
"evaluate_single_item": self.evaluate_single_item,
"entitlement_item_ids": entitlement_item_ids,
"entitlement_validation_group_id": self.entitlement_validation_group_id.id,
"id_type": self.id_type.id,
"manage_inventory": self.manage_inventory,
"warehouse_id": self.warehouse_id.id,
}
Expand Down
2 changes: 2 additions & 0 deletions spp_programs/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
"security/ir.model.access.csv",
"views/main_view.xml",
"views/entitlement_view.xml",
"views/entitlement_cash_view.xml",
"views/cycle_view.xml",
"views/programs_view.xml",
"views/registrant_view.xml",
"views/inkind_entitlement_report_view.xml",
"views/managers/eligibility_manager_view.xml",
"views/managers/entitlement_manager_view.xml",
"wizard/inkind_entitlement_report_wiz.xml",
"wizard/create_program_wizard.xml",
"report/program_approval_receipt.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 @@ -3,6 +3,7 @@
from . import constants
from . import cycle
from . import entitlement
from . import entitlement_cash
from . import registrant
from . import stock
from . import managers
Expand Down
2 changes: 2 additions & 0 deletions spp_programs/models/entitlement.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def _generate_code(self):
domain=[("is_registrant", "=", True)],
index=True,
)
id_number = fields.Char()

service_point_id = fields.Many2one("spp.service.point", "Service Point")

company_id = fields.Many2one("res.company", default=lambda self: self.env.company)
Expand Down
9 changes: 9 additions & 0 deletions spp_programs/models/entitlement_cash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Part of OpenSPP. See LICENSE file for full copyright and licensing details.

from odoo import fields, models


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

id_number = fields.Char()
2 changes: 2 additions & 0 deletions spp_programs/models/managers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

from . import eligibility_manager
from . import cycle_manager
from . import entitlement_manager
from . import entitlement_manager_default
8 changes: 8 additions & 0 deletions spp_programs/models/managers/entitlement_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Part of OpenSPP. See LICENSE file for full copyright and licensing details.
from odoo import fields, models


class BaseEntitlementManager(models.AbstractModel):
_inherit = "g2p.base.program.entitlement.manager"

id_type = fields.Many2one("g2p.id.type", "ID Type to store in entitlements")
101 changes: 101 additions & 0 deletions spp_programs/models/managers/entitlement_manager_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Part of OpenSPP. See LICENSE file for full copyright and licensing details.
import logging

from odoo import models

_logger = logging.getLogger(__name__)


class G2PDefaultEntitlementManagerCustom(models.Model):
"""
G2PDefaultEntitlementManagerCustom adds the configured card number in
generating entitlements using the default entitlement manager.
If the value of id_type in the entitlement manager is set, then all generated entitlements
will store the beneficiaries card number (configured card type in entitlement manager).
"""

_inherit = "g2p.program.entitlement.manager.default"

def prepare_entitlements(self, cycle, beneficiaries):
"""Prepare entitlements.
This overrides the Default Entitlement Manager :meth:`prepare_entitlements`
to support the storing of additional fields in the generated entitlements.
:param cycle: The cycle.
:param beneficiaries: The beneficiaries.
:return:
"""
benecifiaries_ids = beneficiaries.mapped("partner_id.id")

benecifiaries_with_entitlements = (
self.env["g2p.entitlement"]
.search(
[("cycle_id", "=", cycle.id), ("partner_id", "in", benecifiaries_ids)]
)
.mapped("partner_id.id")
)
entitlements_to_create = [
benecifiaries_id
for benecifiaries_id in benecifiaries_ids
if benecifiaries_id not in benecifiaries_with_entitlements
]

entitlement_start_validity = cycle.start_date
entitlement_end_validity = cycle.end_date
entitlement_currency = self.currency_id.id

beneficiaries_with_entitlements_to_create = self.env["res.partner"].browse(
entitlements_to_create
)

individual_count = beneficiaries_with_entitlements_to_create.count_individuals()
individual_count_map = dict(individual_count)

entitlements = []
for beneficiary_id in beneficiaries_with_entitlements_to_create:
amount = self._calculate_amount(
beneficiary_id, individual_count_map.get(beneficiary_id.id, 0)
)
transfer_fee = 0.0
if self.transfer_fee_pct > 0.0:
transfer_fee = amount * (self.transfer_fee_pct / 100.0)
elif self.transfer_fee_amt > 0.0:
transfer_fee = self.transfer_fee_amt

entitlement_fields = {
"cycle_id": cycle.id,
"partner_id": beneficiary_id.id,
"initial_amount": amount,
"transfer_fee": transfer_fee,
"currency_id": entitlement_currency,
"state": "draft",
"is_cash_entitlement": True,
"valid_from": entitlement_start_validity,
"valid_until": entitlement_end_validity,
}
# Check if there are additional fields to be added in entitlements
addl_fields = self._get_addl_entitlement_fields(beneficiary_id)
if addl_fields:
entitlement_fields.update(addl_fields)
entitlements.append(entitlement_fields)

if entitlements:
self.env["g2p.entitlement"].create(entitlements)

def _get_addl_entitlement_fields(self, beneficiary_id):
"""
This function must be overriden to add additional field to be written in the entitlements.
Add the id_number from the beneficiaries based on the id_type configured in entitlement manager.
"""
retval = None
if self.id_type:
id_docs = beneficiary_id.reg_ids.filtered(
lambda a: a.id_type.id == self.id_type.id
)
if id_docs:
id_number = id_docs[0].value
retval = {
"id_number": id_number,
}
return retval
29 changes: 29 additions & 0 deletions spp_programs/views/entitlement_cash_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Part of OpenSPP. See LICENSE file for full copyright and licensing details.
-->
<odoo>
<record id="view_entitlement_tree_custom_spp_programs" model="ir.ui.view">
<field name="name">view_entitlement_tree_custom_spp_programs</field>
<field name="model">g2p.entitlement</field>
<field name="inherit_id" ref="g2p_programs.view_entitlement_tree" />
<field name="priority">2000</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="after">
<field name="id_number" />
</xpath>
</field>
</record>

<record id="view_entitlement_form_custom_spp_programs" model="ir.ui.view">
<field name="name">view_entitlement_form_custom_spp_programs</field>
<field name="model">g2p.entitlement</field>
<field name="inherit_id" ref="g2p_programs.view_entitlement_form" />
<field name="priority">2000</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="after">
<field name="id_number" readonly="1" />
</xpath>
</field>
</record>
</odoo>
2 changes: 2 additions & 0 deletions spp_programs/views/entitlement_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Part of OpenSPP. See LICENSE file for full copyright and licensing details.
<field name="name" />
<field name="code" />
<field name="partner_id" />
<field name="id_number" />
<field name="service_point_id" />
<field name="program_id" />
<field name="cycle_id" />
Expand Down Expand Up @@ -72,6 +73,7 @@ Part of OpenSPP. See LICENSE file for full copyright and licensing details.
readonly="1"
options="{'no_open':True,'no_quick_create':True,'no_create':True}"
/>
<field name="id_number" readonly="1" />
<field
name="program_id"
options="{'no_open':True,'no_quick_create':True,'no_create':True}"
Expand Down
26 changes: 26 additions & 0 deletions spp_programs/views/managers/entitlement_manager_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Part of OpenSPP. See LICENSE file for full copyright and licensing details.
-->
<odoo>

<record id="view_entitlement_manager_default_form_spp" model="ir.ui.view">
<field name="name">view_entitlement_manager_default_form_spp</field>
<field name="model">g2p.program.entitlement.manager.default</field>
<field name="priority">1000</field>
<field name="inherit_id" ref="g2p_programs.view_entitlement_manager_default_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='entitlement_validation_group_id']" position="before">
<field
name="id_type"
colspan="2"
options="{'no_open':true,'no_create':true,'no_create_edit':true}"
/>
</xpath>
<xpath expr="//field[@name='entitlement_validation_group_id']" position="attributes">
<attribute name="colspan">2</attribute>
</xpath>
</field>
</record>

</odoo>
Loading

0 comments on commit d929145

Please sign in to comment.