|
1 | 1 | # Part of OpenSPP. See LICENSE file for full copyright and licensing details.
|
2 | 2 |
|
3 |
| -from odoo import fields, models |
| 3 | +from odoo import api, fields, models |
4 | 4 |
|
5 | 5 |
|
6 | 6 | class OpenSPPStatisticsCycle(models.Model):
|
@@ -49,3 +49,66 @@ def get_view_id(self):
|
49 | 49 | This retrieves the View ID of this model
|
50 | 50 | """
|
51 | 51 | 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 | + ) |
0 commit comments