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

Commit

Permalink
add computation by areas
Browse files Browse the repository at this point in the history
  • Loading branch information
emjay0921 committed Nov 14, 2023
1 parent 73f58a5 commit 1d1bcab
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions spp_pmt/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
"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",
],
Expand Down
12 changes: 11 additions & 1 deletion spp_pmt/models/custom_fields_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,15 @@
class OpenSPPCustomFieldsUI(models.Model):
_inherit = "ir.model.fields"

field_weight = fields.Float("Weight", default=0)
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)
12 changes: 11 additions & 1 deletion spp_pmt/models/pmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def _compute_area(self):
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(
Expand All @@ -58,7 +61,14 @@ def _compute_pmt_score(self):
weights = {}
if fields:
for field in fields:
weights.update({field.name: field.field_weight})
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:
Expand Down
2 changes: 2 additions & 0 deletions spp_pmt/security/ir.model.access.csv
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
6 changes: 6 additions & 0 deletions spp_pmt/views/custom_fields_ui_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
<xpath expr="//field[@name='copied']" position="after">
<field name="with_weight" attrs="{'invisible': [('field_category','!=','cst')]}" />
<field name="field_weight" attrs="{'invisible': [('with_weight','=',False)]}" />
<field name="area_ids" attrs="{'invisible': [('with_weight','=',False)]}">
<tree editable="bottom">
<field name="name" />
<field name="weight" />
</tree>
</field>
</xpath>
</field>
</record>
Expand Down

0 comments on commit 1d1bcab

Please sign in to comment.