This repository has been archived by the owner on Mar 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/117-select-the-card-type-in-the-…
…entitlement-manager-to-be-used-in-recording-the-card-number-of-registrants-to-entitlements' into release/dev
- Loading branch information
Showing
18 changed files
with
301 additions
and
21 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
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
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,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() |
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,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
101
spp_programs/models/managers/entitlement_manager_default.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,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 |
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,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> |
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,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> |
Oops, something went wrong.