summaryrefslogtreecommitdiff
path: root/addons/event_crm/models/event_event.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/event_crm/models/event_event.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/event_crm/models/event_event.py')
-rw-r--r--addons/event_crm/models/event_event.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/addons/event_crm/models/event_event.py b/addons/event_crm/models/event_event.py
new file mode 100644
index 00000000..ac71958c
--- /dev/null
+++ b/addons/event_crm/models/event_event.py
@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import fields, models, api
+
+
+class EventEvent(models.Model):
+ _name = "event.event"
+ _inherit = "event.event"
+
+ lead_ids = fields.One2many(
+ 'crm.lead', 'event_id', string="Leads", groups='sales_team.group_sale_salesman',
+ help="Leads generated from this event")
+ lead_count = fields.Integer(
+ string="# Leads", compute='_compute_lead_count', groups='sales_team.group_sale_salesman',
+ help="Counter for the leads linked to this event")
+
+ @api.depends('lead_ids')
+ def _compute_lead_count(self):
+ lead_data = self.env['crm.lead'].read_group(
+ [('event_id', 'in', self.ids)],
+ ['event_id'], ['event_id']
+ )
+ mapped_data = {item['event_id'][0]: item['event_id_count'] for item in lead_data}
+ for event in self:
+ event.lead_count = mapped_data.get(event.id, 0)