[FIX] website_slides: fix slide.slide statistics compute method

The slide.slide and slide.channel "_compute_slides_statistics" methods do not
always assign a default value for the "total_slides" field.

This can cause some CacheMiss and seem related to nondeterministic errors on
the runbot.

Task#2123711
Runbot build error ID 247

closes odoo/odoo#41942

X-original-commit: c240d04ed0518897f76b315cd354ea6606aea645
Signed-off-by: awa-odoo <awa-odoo@users.noreply.github.com>
This commit is contained in:
Aurélien Warnon
2019-12-12 13:38:51 +00:00
parent 7876af3ad0
commit 648bbbec9a
3 changed files with 14 additions and 10 deletions
@@ -246,13 +246,14 @@ class Channel(models.Model):
""" Compute statistics based on all existing slide types """
slide_types = self.env['slide.slide']._fields['slide_type'].get_values(self.env)
keys = ['nbr_%s' % slide_type for slide_type in slide_types]
result = dict((cid, dict((key, 0) for key in keys)) for cid in self.ids)
result = dict((cid, dict((key, 0) for key in keys + ['total_slides'])) for cid in self.ids)
for res_group in read_group_res:
cid = res_group['channel_id'][0]
result[cid]['total_slides'] = 0
for slide_type in slide_types:
result[cid]['nbr_%s' % slide_type] += res_group.get('slide_type', '') == slide_type and res_group['__count'] or 0
result[cid]['total_slides'] += result[cid]['nbr_%s' % slide_type]
slide_type = res_group.get('slide_type')
if slide_type:
slide_type_count = res_group.get('__count', 0)
result[cid]['nbr_%s' % slide_type] = slide_type_count
result[cid]['total_slides'] += slide_type_count
return result
def _compute_rating_stats(self):
+6 -5
View File
@@ -288,13 +288,14 @@ class Slide(models.Model):
""" Compute statistics based on all existing slide types """
slide_types = self.env['slide.slide']._fields['slide_type'].get_values(self.env)
keys = ['nbr_%s' % slide_type for slide_type in slide_types]
result = dict((cid, dict((key, 0) for key in keys)) for cid in self.ids)
result = dict((cid, dict((key, 0) for key in keys + ['total_slides'])) for cid in self.ids)
for res_group in read_group_res:
cid = res_group['category_id'][0]
result[cid]['total_slides'] = 0
for slide_type in slide_types:
result[cid]['nbr_%s' % slide_type] += res_group.get('slide_type', '') == slide_type and res_group['__count'] or 0
result[cid]['total_slides'] += result[cid]['nbr_%s' % slide_type]
slide_type = res_group.get('slide_type')
if slide_type:
slide_type_count = res_group.get('__count', 0)
result[cid]['nbr_%s' % slide_type] = slide_type_count
result[cid]['total_slides'] += slide_type_count
return result
@api.depends('slide_partner_ids.partner_id')
@@ -165,6 +165,7 @@ class TestSlideStatistics(common.SlidesCase):
category.nbr_document,
len(category.channel_id.slide_ids.filtered(lambda s: s.category_id == category and s.slide_type == 'document')))
self.assertEqual(self.channel.total_slides, 3, 'The channel should contain 3 slides')
self.assertEqual(category.total_slides, 2, 'The first category should contain 2 slides')
other_category = self.env['slide.slide'].with_user(self.user_officer).create({
'name': 'Other Category',
@@ -179,3 +180,4 @@ class TestSlideStatistics(common.SlidesCase):
self.slide_3.write({'sequence': 6})
self.assertEqual(category.total_slides, 1, 'The first category should contain 1 slide')
self.assertEqual(other_category.total_slides, 1, 'The other category should contain 1 slide')
self.assertEqual(self.channel.total_slides, 3, 'The channel should still contain 3 slides')