summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorGoffin Simon <sig@odoo.com>2020-10-28 18:48:09 +0000
committerGoffin Simon <sig@odoo.com>2020-10-29 14:50:15 +0000
commit7449c8a6643477742616bf236f2f2c90aec68581 (patch)
treee36c91ade9776aec4ce0208aeec778da55e31eb9 /addons
parent425bcdf0ff5989720ade194913ff920cba62d146 (diff)
[FIX] crm: Smart button for meetings not working
Steps to reproduce the bug: - Let's consider a company contact C with two children CH1 and CH2 - Create a meeting for CH1 and a meeting for CH2 Bug: The count of meetings in C was displaying 0 instead of 2 PS: set() is used to avoid to count several times the same event for a partner. If for example CH1 and CH2 attend to the same event, only one event must be counted for the parent C opw:2360155 Co-authored-by: nim-odoo <nim@odoo.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/crm/models/res_partner.py38
1 files changed, 30 insertions, 8 deletions
diff --git a/addons/crm/models/res_partner.py b/addons/crm/models/res_partner.py
index 49ebc452775..d9430beada2 100644
--- a/addons/crm/models/res_partner.py
+++ b/addons/crm/models/res_partner.py
@@ -58,30 +58,52 @@ class Partner(models.Model):
partner.opportunity_count = partners.get(partner.id, 0)
def _compute_meeting_count(self):
+ result = self._compute_meeting()
+ for p in self:
+ p.meeting_count = len(result.get(p.id, []))
+
+ def _compute_meeting(self):
if self.ids:
+ all_partners = self.with_context(active_test=False).search([('id', 'child_of', self.ids)])
self.env.cr.execute("""
SELECT res_partner_id, calendar_event_id, count(1)
FROM calendar_event_res_partner_rel
WHERE res_partner_id IN %s
GROUP BY res_partner_id, calendar_event_id
- """, [tuple(self.ids)])
+ """, [tuple(all_partners.ids)])
meeting_data = self.env.cr.fetchall()
+
+ # Keep only valid meeting data based on record rules of events
events = [row[1] for row in meeting_data]
- valid_events = self.env['calendar.event'].search([('id', 'in', events)]) # filter for ACLs
- meetings = dict((m[0], m[2]) for m in meeting_data if m[1] in valid_events.ids)
- else:
- meetings = dict()
- for partner in self:
- partner.meeting_count = meetings.get(partner.id, 0)
+ events = self.env['calendar.event'].search([('id', 'in', events)]).ids
+ meeting_data = [m for m in meeting_data if m[1] in events]
+
+ # Create a dict {partner_id: event_ids} and fill with events linked to the partner
+ meetings = {p.id: set() for p in all_partners}
+ for m in meeting_data:
+ meetings[m[0]].add(m[1])
+
+ # Add the events linked to the children of the partner
+ all_partners.read(['parent_id'])
+ for p in all_partners:
+ partner = p
+ while partner:
+ if partner in self:
+ meetings[partner.id] |= meetings[p.id]
+ partner = partner.parent_id
+ return {p.id: list(meetings[p.id]) for p in self}
+ return {}
+
def schedule_meeting(self):
+ self.ensure_one()
partner_ids = self.ids
partner_ids.append(self.env.user.partner_id.id)
action = self.env["ir.actions.actions"]._for_xml_id("calendar.action_calendar_event")
action['context'] = {
'default_partner_ids': partner_ids,
}
- action['domain'] = [('id', 'in', self.meeting_ids.ids)]
+ action['domain'] = [('id', 'in', self._compute_meeting()[self.id])]
return action
def action_view_opportunity(self):