Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added PMT #51

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ addon | version | maintainers | summary
[g2p_registry_id_deduplication](g2p_registry_id_deduplication/) | 17.0.0.0.0 | | OpenG2P Registry ID Deduplication
[g2p_social_registry](g2p_social_registry/) | 17.0.0.0.0 | | OpenG2P Social Registry
[g2p_social_registry_model](g2p_social_registry_model/) | 17.0.0.0.0 | | G2P Social Registry: Demo
[g2p_social_registry_proxy_means_test](g2p_social_registry_proxy_means_test/) | 17.0.0.0.0 | | G2P Social Registry: PMT
[g2p_social_registry_theme](g2p_social_registry_theme/) | 17.0.0.0.0 | | OpenG2P Social Registry: Theme

[//]: # (end addons)
Expand Down
433 changes: 0 additions & 433 deletions g2p_social_registry_model/i18n/g2p_social_registry_model.pot

This file was deleted.

3 changes: 3 additions & 0 deletions g2p_social_registry_proxy_means_test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# G2P Social Registry: PMT

Refer to https://docs.openg2p.org.
3 changes: 3 additions & 0 deletions g2p_social_registry_proxy_means_test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Part of OpenG2P. See LICENSE file for full copyright and licensing details.

from . import models
23 changes: 23 additions & 0 deletions g2p_social_registry_proxy_means_test/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Part of OpenG2P. See LICENSE file for full copyright and licensing details.
{
"name": "G2P Social Registry: PMT",
"category": "G2P",
"version": "17.0.0.0.0",
"sequence": 1,
"author": "OpenG2P",
"website": "https://openg2p.org",
"license": "LGPL-3",
"depends": ["base", "web", "g2p_registry_base", "g2p_social_registry"],
"data": [
"security/ir.model.access.csv",
"views/pmt_config_view.xml",
"views/individual_view.xml",
"views/group_view.xml",
],
"assets": {},
"demo": [],
"images": [],
"application": True,
"installable": True,
"auto_install": False,
}
4 changes: 4 additions & 0 deletions g2p_social_registry_proxy_means_test/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Part of OpenG2P. See LICENSE file for full copyright and licensing details.
from . import proxy_means_test_line
from . import proxy_means_test_params
from . import res_partner
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class SRProxyMeanTestLine(models.Model):
_name = "sr.proxy.means.test.line"
_description = "Proxy Means Test Line"

pmt_id = fields.Many2one("sr.proxy.means.test.params", string="Proxy Means Test")
pmt_field = fields.Selection(selection="get_fields_label", string="Field")
pmt_weightage = fields.Float(string="Weightage")

@api.constrains("pmt_id", "pmt_field")
def _check_unique_field_weightage(self):
for line in self:
duplicate = self.search_count(
[("pmt_id", "=", line.pmt_id.id), ("pmt_field", "=", line.pmt_field), ("id", "!=", line.id)]
)
if duplicate:
raise ValidationError(_("The combination of PMT field and weightage already exist."))

def get_fields_label(self):
reg_info = self.env["res.partner"]
ir_model_obj = self.env["ir.model.fields"]
excluded_fields = {
"pmt_score",
"message_needaction_counter",
"message_has_error_counter",
"message_attachment_count",
"message_bounce",
"active_lang_count",
"partner_latitude",
"partner_longitude",
"color",
"id",
"meeting_count",
"employees_count",
"partner_gid",
"certifications_count",
"certifications_company_count",
"event_count",
"payment_token_count",
"days_sales_outstanding",
"journal_item_count",
"bank_account_count",
"supplier_rank",
"customer_rank",
"duplicated_bank_account_partners_count",
"task_count",
"z_ind_grp_num_individuals",
"program_membership_count",
"entitlements_count",
"cycles_count",
"inkind_entitlements_count",
"credit_limit",
}

choice = []
for field in reg_info._fields.items():
ir_model_field = ir_model_obj.search([("model", "=", "res.partner"), ("name", "=", field[0])])
field_type = ir_model_field.ttype
if field_type in ["integer", "float"] and field[0] not in excluded_fields:
choice.append((field[0], field[0]))
return choice

def write(self, vals):
res = super().write(vals)
for line in self:
line.pmt_id.compute_related_partners_pmt_score()
return res
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class SRProxyMeanTestParams(models.Model):
_name = "sr.proxy.means.test.params"
_description = "Proxy Means Test Params"
_rec_name = "pmt_name"

pmt_name = fields.Char(
string="PMT Name",
)
target = fields.Selection(
[("individual", "Individual"), ("group", "Group")],
)
kind = fields.Many2one(
"g2p.group.kind",
)

pmt_line_ids = fields.One2many("sr.proxy.means.test.line", "pmt_id", string="Proxy Means Test Lines")

target_name = fields.Boolean(default=True)

@api.onchange("target")
def _onchange_target(self):
if self.target == "group":
self.write({"target_name": False})
else:
self.write({"target_name": True})

@api.constrains("target", "kind")
def _check_unique_pmt(self):
for rec in self:
existing_pmt = self.search_count(
[("target", "=", rec.target), ("kind", "=", rec.kind.id), ("id", "!=", rec.id)]
)

if existing_pmt > 0:
raise ValidationError(_("A Proxy Means Test for this kind and target already exists."))

@api.model
def create(self, vals):
if "target" in vals and "kind" in vals:
existing_pmt = self.search_count([("target", "=", vals["target"]), ("kind", "=", vals["kind"])])
if existing_pmt > 0:
raise ValidationError(_("A Proxy Means Test for this kind and target already exists."))

rec = super().create(vals)
rec.compute_related_partners_pmt_score()
return rec

def write(self, vals):
for rec in self:
if "target" in vals and vals["target"] != rec.target:
existing_pmt = self.search_count(
[("target", "=", vals["target"]), ("kind", "=", rec.kind.id), ("id", "!=", rec.id)]
)
if existing_pmt > 0:
raise ValidationError(_("A Proxy Means Test for this kind and target already exists."))

if "kind" in vals and vals["kind"] != rec.kind.id:
existing_pmt = self.search_count(
[("target", "=", rec.target), ("kind", "=", vals["kind"]), ("id", "!=", rec.id)]
)
if existing_pmt > 0:
raise ValidationError(_("A Proxy Means Test for this kind and target already exists."))

rec = super().write(vals)
for record in self:
record.compute_related_partners_pmt_score()
return rec

def unlink(self):
for rec in self:
partners = self.env["res.partner"].search([("kind", "=", rec.kind.id)])
for partner in partners:
partner.pmt_score = 0

rec.pmt_line_ids.unlink()
return super().unlink()

def compute_related_partners_pmt_score(self):
if (
not self.target
or not self.pmt_name
or not self.pmt_line_ids
or (self.target == "group" and not self.kind)
):
return
partners = self.env["res.partner"].search([("kind", "=", self.kind.id)])
for partner in partners:
partner._compute_pmt_score()
69 changes: 69 additions & 0 deletions g2p_social_registry_proxy_means_test/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from odoo import api, fields, models


class ResPartner(models.Model):
_inherit = "res.partner"

pmt_score = fields.Float(string="PMT Score", compute="_compute_pmt_score", store=True)

@api.depends("kind", "is_group")
def _compute_pmt_score(self):
for partner in self:
score = 0.0
pmt_params = self.env["sr.proxy.means.test.params"]

if partner.is_group:
pmt_params = pmt_params.search(
[("target", "=", "group"), ("kind", "=", partner.kind.id)], limit=1
)
else:
pmt_params = pmt_params.search([("target", "=", "individual")], limit=1)

if not pmt_params:
partner.pmt_score = 0
continue

for line in pmt_params.pmt_line_ids:
field_value = getattr(partner, line.pmt_field, 0)
score += field_value * line.pmt_weightage

partner.pmt_score = score

@api.model
def compute_existing_pmt_scores(self):
partners = self.search([])
for partner in partners:
partner._compute_pmt_score()

@api.model
def create(self, vals):
partner = super().create(vals)
partner._compute_pmt_score()
return partner

def _get_fields_with_x_prefix(self):
all_fields = self._fields
return [field_name[2:] for field_name in all_fields if field_name.startswith("x_")]

def write(self, vals):
res = super().write(vals)
pmt_params = self.env["sr.proxy.means.test.params"]

if self.is_group:
pmt_params = pmt_params.search([("target", "=", "group"), ("kind", "=", self.kind.id)], limit=1)
else:
pmt_params = pmt_params.search([("target", "=", "individual")], limit=1)

fields_to_check = ["income"]

if pmt_params:
for line in pmt_params.pmt_line_ids:
if line.pmt_field not in fields_to_check:
fields_to_check.append(line.pmt_field)

fields_to_check.extend(self._get_fields_with_x_prefix())

if any(field in vals for field in fields_to_check):
for partner in self:
partner._compute_pmt_score()
return res
3 changes: 3 additions & 0 deletions g2p_social_registry_proxy_means_test/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_sr_proxy_means_test_params,access.sr.proxy.means.test.params,model_sr_proxy_means_test_params,base.group_user,1,1,1,1
access_sr_proxy_means_test_line,access.sr.proxy.means.test.line,model_sr_proxy_means_test_line,base.group_user,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.
24 changes: 24 additions & 0 deletions g2p_social_registry_proxy_means_test/views/group_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Part of OpenG2P. See LICENSE file for full copyright and licensing details.
-->
<odoo>
<record id="view_group_form_inherit" model="ir.ui.view">
<field name="name">Group Form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="g2p_registry_group.view_groups_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='kind']" position="after">
<label
for="pmt_score"
string="PMT Score: "
class="bg-success text-dark"
style="padding: 5px; border-radius: 3px; font-weight: bold;"
/>
<div class="o_row">
<field name="pmt_score" string="PMT Score" />
</div>
</xpath>
</field>
</record>
</odoo>
24 changes: 24 additions & 0 deletions g2p_social_registry_proxy_means_test/views/individual_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Part of OpenG2P. See LICENSE file for full copyright and licensing details.
-->
<odoo>
<record id="view_individual_form_inherit" model="ir.ui.view">
<field name="name">Individual Form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="g2p_registry_individual.view_individuals_form" />
<field name="arch" type="xml">
<xpath expr="//div[@class='oe_edit_only']" position="after">
<div class="o_row">
<label
for="pmt_score"
string="PMT Score: "
class="bg-success text-dark"
style="padding: 5px; border-radius: 3px; font-weight: bold;"
/>
<field name="pmt_score" />
</div>
</xpath>
</field>
</record>
</odoo>
Loading
Loading