From 290341b4555a96ac0bc698054e2944ccc7d43518 Mon Sep 17 00:00:00 2001 From: Lucas Lefevre Date: Thu, 12 Sep 2019 11:31:04 +0000 Subject: [PATCH] [FIX] website_slides: still another fix of computed fields This commit fixes 2 issues coming from the recent ORM changes: records are new records in onchange and compute methods must assign a value for all records. In an onchange method, self.ids is a list of integer (real records) whereas self.id is a NewId (virtual record) Here a result dict was built using the reals ids as keys but later NewIds are used as keys. Solution is to use record._origin to access the real record. Moreover, the two dicts `result` and `type_stats` are the same. Assigning one into the other is useless. Task 2067872 (eLearning internal testing) PR #36756 --- addons/website_slides/models/slide_slide.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/addons/website_slides/models/slide_slide.py b/addons/website_slides/models/slide_slide.py index 1a99c84129a..69206edd916 100644 --- a/addons/website_slides/models/slide_slide.py +++ b/addons/website_slides/models/slide_slide.py @@ -265,7 +265,8 @@ class Slide(models.Model): def _compute_slides_statistics(self): # Do not use dict.fromkeys(self.ids, dict()) otherwise it will use the same dictionnary for all keys. # Therefore, when updating the dict of one key, it updates the dict of all keys. - result = {_id: {} for _id in self.ids} + keys = ['nbr_%s' % slide_type for slide_type in self.env['slide.slide']._fields['slide_type'].get_values(self.env)] + default_vals = dict((key, 0) for key in keys) res = self.env['slide.slide'].read_group( [('is_published', '=', True), ('category_id', 'in', self.ids), ('is_category', '=', False)], @@ -273,11 +274,9 @@ class Slide(models.Model): lazy=False) type_stats = self._compute_slides_statistics_type(res) - for cid, cdata in type_stats.items(): - result[cid].update(cdata) for record in self: - record.update(result[record.id]) + record.update(type_stats.get(record._origin.id, default_vals)) def _compute_slides_statistics_type(self, read_group_res): """ Compute statistics based on all existing slide types """