This repository has been archived by the owner on Apr 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #272 from OpenSPP/34-pmt-module-development
initital commit spp_pmt
- Loading branch information
Showing
13 changed files
with
679 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../spp_pmt |
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,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |
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,68 @@ | ||
======================== | ||
OpenSPP Proxy Means Test | ||
======================== | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Alpha | ||
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html | ||
:alt: License: LGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-openspp%2Fopenspp--registry-lightgray.png?logo=github | ||
:target: https://github.com/openspp/openspp-registry/tree/15.0/spp_pmt | ||
:alt: openspp/openspp-registry | ||
|
||
|badge1| |badge2| |badge3| | ||
|
||
OpenSPP Proxy Means Test | ||
|
||
.. IMPORTANT:: | ||
This is an alpha version, the data model and design can change at any time without warning. | ||
Only for development or testing purpose, do not use in production. | ||
`More details on development status <https://odoo-community.org/page/development-status>`_ | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/openspp/openspp-registry/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/openspp/openspp-registry/issues/new?body=module:%20spp_custom_fields_ui%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* OpenSPP.org | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
.. |maintainer-jeremi| image:: https://github.com/jeremi.png?size=40px | ||
:target: https://github.com/jeremi | ||
:alt: jeremi | ||
.. |maintainer-gonzalesedwin1123| image:: https://github.com/gonzalesedwin1123.png?size=40px | ||
:target: https://github.com/gonzalesedwin1123 | ||
:alt: gonzalesedwin1123 | ||
|
||
Current maintainers: | ||
|
||
|maintainer-jeremi| |maintainer-gonzalesedwin1123| | ||
|
||
This module is part of the `openspp/openspp-registry <https://github.com/openspp/openspp-registry/tree/15.0/spp_custom_fields_ui>`_ project on GitHub. | ||
|
||
You are welcome to contribute. |
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,3 @@ | ||
# Part of OpenSPP. See LICENSE file for full copyright and licensing details. | ||
|
||
from . import models |
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,32 @@ | ||
# Part of OpenSPP. See LICENSE file for full copyright and licensing details. | ||
|
||
|
||
{ | ||
"name": "Proxy Means Testing", | ||
"category": "OpenSPP", | ||
"version": "15.0.0.0.0", | ||
"sequence": 1, | ||
"author": "OpenSPP.org", | ||
"website": "https://github.com/openspp/openspp-registry", | ||
"license": "LGPL-3", | ||
"development_status": "Beta", | ||
"maintainers": ["dasunhegoda"], | ||
"depends": [ | ||
"base", | ||
"g2p_registry_base", | ||
"g2p_registry_group", | ||
"spp_custom_fields_ui", | ||
"spp_area", | ||
], | ||
"data": [ | ||
"security/ir.model.access.csv", | ||
"views/custom_fields_ui_view.xml", | ||
"views/custom_registrant_view.xml", | ||
], | ||
"assets": {}, | ||
"demo": [], | ||
"images": [], | ||
"application": True, | ||
"installable": True, | ||
"auto_install": False, | ||
} |
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,4 @@ | ||
# Part of OpenSPP. See LICENSE file for full copyright and licensing details. | ||
|
||
from . import pmt | ||
from . import custom_fields_ui |
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,20 @@ | ||
# Part of OpenSPP. See LICENSE file for full copyright and licensing details. | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class OpenSPPCustomFieldsUI(models.Model): | ||
_inherit = "ir.model.fields" | ||
|
||
field_weight = fields.Float("Default Weight", default=0) | ||
with_weight = fields.Boolean(default=False) | ||
area_ids = fields.One2many("spp.fields.area", "field_id", string="Areas") | ||
|
||
|
||
class OpenSPPCustomFieldsArea(models.Model): | ||
_name = "spp.fields.area" | ||
_description = "Fields Area" | ||
|
||
field_id = fields.Many2one("ir.model.fields") | ||
name = fields.Many2one("spp.area", required=True, string="Area") | ||
weight = fields.Float(required=True, default=0) |
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,88 @@ | ||
# Part of OpenSPP. See LICENSE file for full copyright and licensing details. | ||
import logging | ||
|
||
from odoo import fields, models | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
# Extending the built-in res.partner model in Odoo to accommodate PMT specific fields | ||
class G2PGroupPMT(models.Model): | ||
_inherit = "res.partner" | ||
|
||
# Boolean fields capturing specific conditions of an individual | ||
x_cst_indv_gce_ol = fields.Boolean("Lower than G.C.E. Ordinary Level") | ||
x_cst_indv_school_age = fields.Boolean( | ||
"Currently not attending school or other educational institution" | ||
) | ||
x_cst_indv_chronic_disease = fields.Boolean("Long-term (chronic) disease") | ||
x_cst_indv_disability = fields.Boolean("Disability") | ||
|
||
# Floating-point field to store the computed PMT score of the group | ||
z_ind_grp_pmt_score = fields.Float( | ||
"PMT Score of the group", | ||
compute="_compute_pmt_score", | ||
) | ||
grp_pmt_score = fields.Float( | ||
"PMT Score of the group", compute="_compute_pmt_score", store=True | ||
) | ||
area_calc = fields.Many2one("spp.area", compute="_compute_area") | ||
|
||
def _compute_area(self): | ||
for rec in self: | ||
area_calc = None | ||
if rec.is_group: | ||
if rec.group_membership_ids: | ||
individual = rec.group_membership_ids.mapped("individual.id") | ||
members = self.env["res.partner"].search( | ||
[("id", "in", individual), ("area_id", "!=", False)] | ||
) | ||
if members: | ||
area_calc = members[0].area_id.id | ||
|
||
if area_calc: | ||
rec.area_id = area_calc | ||
|
||
rec.area_calc = area_calc | ||
|
||
def _compute_pmt_score(self): | ||
|
||
hh_area = self.area_id | ||
|
||
model = self.env["ir.model"].search([("model", "=", "res.partner")]) | ||
|
||
fields = self.env["ir.model.fields"].search( | ||
[ | ||
("model_id", "=", model.id), | ||
("with_weight", "=", True), | ||
("target_type", "=", "indv"), | ||
] | ||
) | ||
weights = {} | ||
if fields: | ||
for field in fields: | ||
if hh_area: | ||
areas = field.area_ids.filtered(lambda a: a.name.id == hh_area.id) | ||
if areas: | ||
weights.update({field.name: areas[0].weight}) | ||
else: | ||
weights.update({field.name: field.field_weight}) | ||
else: | ||
weights.update({field.name: field.field_weight}) | ||
|
||
if weights: | ||
for record in self: | ||
z_ind_grp_pmt_score = 0 | ||
if record.group_membership_ids: | ||
total_score = 0.0 | ||
total_weight = 0.0 | ||
# Iterating through each member of the group to calculate the PMT score | ||
for ind in record.group_membership_ids: | ||
for field, weight in weights.items(): | ||
if hasattr(ind.individual, field): | ||
total_score += getattr(ind.individual, field) * weight | ||
total_weight += weight | ||
z_ind_grp_pmt_score = total_score / total_weight | ||
|
||
record.z_ind_grp_pmt_score = z_ind_grp_pmt_score | ||
record.grp_pmt_score = z_ind_grp_pmt_score |
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,2 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
spp_fields_area_admin,Fields Area Admin Access,spp_pmt.model_spp_fields_area,g2p_registry_base.group_g2p_admin,1,1,1,1 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.