Skip to content

Commit dbfd9d4

Browse files
committed
add event statistics cycle to UI
1 parent fa2bd92 commit dbfd9d4

File tree

3 files changed

+649
-11
lines changed

3 files changed

+649
-11
lines changed

spp_farmer_registry_laos/models/event_data.py

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Part of OpenSPP. See LICENSE file for full copyright and licensing details.
22

3-
from odoo import fields, models
3+
from odoo import api, fields, models
44

55

66
class OpenSPPStatisticsCycle(models.Model):
@@ -49,3 +49,66 @@ def get_view_id(self):
4949
This retrieves the View ID of this model
5050
"""
5151
return self.env["ir.ui.view"].search([("model", "=", self._name), ("type", "=", "form")], limit=1).id
52+
53+
54+
class OpenSPPStatisticsCycleResPartner(models.Model):
55+
_inherit = "res.partner"
56+
57+
active_event_cycle = fields.Many2one("spp.event.cycle", compute="_compute_active_event_cycle")
58+
59+
statistics_program_id = fields.Many2one("g2p.program", "Program", related="active_event_cycle.program_id")
60+
statistics_cycle_id = fields.Many2one("g2p.cycle", "Cycle", related="active_event_cycle.cycle_id")
61+
statistics_event_type = fields.Selection(string="Event Type", related="active_event_cycle.event_type")
62+
statistics_no_hh_member = fields.Integer("No. of HH Member", related="active_event_cycle.no_hh_member")
63+
statistics_no_indigenous = fields.Integer("No. of Indigenous", related="active_event_cycle.no_indigenous")
64+
statistics_percent_indigenous = fields.Float("% of Indigenous", related="active_event_cycle.percent_indigenous")
65+
statistics_no_15_35 = fields.Integer("No. of Member in 15-35", related="active_event_cycle.no_15_35")
66+
statistics_percent_15_35 = fields.Float("% of Member in 15-35", related="active_event_cycle.percent_15_35")
67+
statistics_no_woman_headed = fields.Integer("No. of Woman-headed HH", related="active_event_cycle.no_woman_headed")
68+
statistics_no_better_off = fields.Integer("No. of Better-off HH", related="active_event_cycle.no_better_off")
69+
statistics_no_medium = fields.Integer("No. of Medium HH", related="active_event_cycle.no_medium")
70+
statistics_no_poor = fields.Integer("No. of Poor HH", related="active_event_cycle.no_poor")
71+
statistics_no_male = fields.Integer("No. of Male", related="active_event_cycle.no_male")
72+
statistics_no_female = fields.Integer("No. of Female", related="active_event_cycle.no_female")
73+
statistics_no_both = fields.Integer("No. of Both", related="active_event_cycle.no_both")
74+
statistics_no_implemented = fields.Integer("No. of Implemented", related="active_event_cycle.no_implemented")
75+
statistics_no_on_going = fields.Integer("No. of On-going", related="active_event_cycle.no_on_going")
76+
statistics_no_not_implemented = fields.Integer(
77+
"No. of Not Implemented", related="active_event_cycle.no_not_implemented"
78+
)
79+
statistics_production_area = fields.Float("Production Area (ha)", related="active_event_cycle.production_area")
80+
statistics_agricultural_yield = fields.Float(
81+
"Agricultural Yield (ton)", related="active_event_cycle.agricultural_yield"
82+
)
83+
statistics_agricultural_productivity = fields.Float(
84+
"Agricultural Productivity (ton/ha)", related="active_event_cycle.agricultural_productivity"
85+
)
86+
statistics_no_livestock_project = fields.Integer(
87+
"No. of Livestock provided by project", related="active_event_cycle.no_livestock_project"
88+
)
89+
statistics_no_livestock_present = fields.Integer(
90+
"No. of Livestock at present", related="active_event_cycle.no_livestock_present"
91+
)
92+
statistics_no_livestock_consumption = fields.Integer(
93+
"No. of Livestock consumption", related="active_event_cycle.no_livestock_consumption"
94+
)
95+
statistics_no_livestock_sold = fields.Integer(
96+
"No. of Livestock sold", related="active_event_cycle.no_livestock_sold"
97+
)
98+
statistics_no_livestock_increase = fields.Integer(
99+
"No. of Livestock increase", related="active_event_cycle.no_livestock_increase"
100+
)
101+
102+
@api.depends("event_data_ids")
103+
def _compute_active_event_cycle(self):
104+
"""
105+
This computes the active Statistics cycle event of the group
106+
"""
107+
for rec in self:
108+
event_data = rec._get_active_event_id("spp.event.cycle")
109+
rec.active_event_cycle = None
110+
if event_data:
111+
event_data_res_id = self.env["spp.event.data"].search([("id", "=", event_data)], limit=1).res_id
112+
rec.active_event_cycle = (
113+
self.env["spp.event.cycle"].search([("id", "=", event_data_res_id)], limit=1).id
114+
)

spp_farmer_registry_laos/models/farm.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22

3-
from odoo import api, fields, models
3+
from odoo import fields, models
44

55
_logger = logging.getLogger(__name__)
66

@@ -9,15 +9,6 @@ class Farm(models.Model):
99
_inherit = "res.partner"
1010

1111
farm_prod_ids = fields.One2many("spp.farm.activity", "prod_farm_id", string="Products")
12-
active_event_cycle = fields.Many2one("spp.event.data", compute="_compute_active_event_cycle")
13-
14-
@api.depends("event_data_ids")
15-
def _compute_active_event_cycle(self):
16-
"""
17-
This computes the active farm event of the group
18-
"""
19-
for rec in self:
20-
rec.active_event_cycle = rec._get_active_event_id("spp.event.cycle")
2112

2213
# overwrite for now since we will not create an individual per group in this module
2314
def create_update_farmer(self, farm):

0 commit comments

Comments
 (0)