summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorJérémy Hennecart <jeh@odoo.com>2020-08-27 06:55:31 +0000
committerJérémy Hennecart <jeh@odoo.com>2020-08-31 14:16:31 +0000
commitacbc97bfe290ef3c7b8f7a1160266e49485099ae (patch)
tree3e597b63a35b79f123cbe58a0010cfce32dd6d37 /addons
parentb1efd7965a3b185b95bd30beca3d1b7f08165c8a (diff)
[FIX] website_crm: fix compute on default
Now, compute's methods are executed on default, which leads to a crash when these methods try to use the actual records but there isn't one yet (e.g. at the creation of a record). - Fix the traceback raised when creating a lead because of the visitor_page_count method when self.ids is empty on default compute. - Since the default_get() and the first_onchange() are also now combined, we need to adapt the syntax of the default get for the field opportunity_ids, replacing the array of ids by the command syntax '[(6, 0, ids)]'. task-2325629
Diffstat (limited to 'addons')
-rw-r--r--addons/crm/wizard/crm_merge_opportunities.py2
-rw-r--r--addons/website_crm/models/crm_lead.py24
2 files changed, 14 insertions, 12 deletions
diff --git a/addons/crm/wizard/crm_merge_opportunities.py b/addons/crm/wizard/crm_merge_opportunities.py
index 7307bd37554..4c95d7db4ad 100644
--- a/addons/crm/wizard/crm_merge_opportunities.py
+++ b/addons/crm/wizard/crm_merge_opportunities.py
@@ -28,7 +28,7 @@ class MergeOpportunity(models.TransientModel):
if record_ids:
if 'opportunity_ids' in fields:
opp_ids = self.env['crm.lead'].browse(record_ids).filtered(lambda opp: opp.probability < 100).ids
- result['opportunity_ids'] = opp_ids
+ result['opportunity_ids'] = [(6, 0, opp_ids)]
return result
diff --git a/addons/website_crm/models/crm_lead.py b/addons/website_crm/models/crm_lead.py
index 0ea63e3b4b1..9612c9995a4 100644
--- a/addons/website_crm/models/crm_lead.py
+++ b/addons/website_crm/models/crm_lead.py
@@ -12,17 +12,19 @@ class Lead(models.Model):
@api.depends('visitor_ids.page_ids')
def _compute_visitor_page_count(self):
- self.flush(['visitor_ids'])
- sql = """ SELECT l.id as lead_id, count(*) as page_view_count
- FROM crm_lead l
- JOIN crm_lead_website_visitor_rel lv ON l.id = lv.crm_lead_id
- JOIN website_visitor v ON v.id = lv.website_visitor_id
- JOIN website_track p ON p.visitor_id = v.id
- WHERE l.id in %s
- GROUP BY l.id"""
- self.env.cr.execute(sql, (tuple(self.ids),))
- page_data = self.env.cr.dictfetchall()
- mapped_data = {data['lead_id']: data['page_view_count'] for data in page_data}
+ mapped_data = {}
+ if self.ids:
+ self.flush(['visitor_ids'])
+ sql = """ SELECT l.id as lead_id, count(*) as page_view_count
+ FROM crm_lead l
+ JOIN crm_lead_website_visitor_rel lv ON l.id = lv.crm_lead_id
+ JOIN website_visitor v ON v.id = lv.website_visitor_id
+ JOIN website_track p ON p.visitor_id = v.id
+ WHERE l.id in %s
+ GROUP BY l.id"""
+ self.env.cr.execute(sql, (tuple(self.ids),))
+ page_data = self.env.cr.dictfetchall()
+ mapped_data = {data['lead_id']: data['page_view_count'] for data in page_data}
for lead in self:
lead.visitor_page_count = mapped_data.get(lead.id, 0)