[FIX] website_slides: better reorder after category deletion
Currently deleting a category with slides is not supported as it should be voided before being unlinked. This commit allows to unlink a category by moving all its slides in uncategorized section. This require a small reordering of sequences as category computation is based on sequence of slides in a given channel. Task ID 2276559 Prepares Task ID 2093671 PR #52917 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
@@ -711,6 +711,18 @@ class Channel(models.Model):
|
||||
|
||||
return category_data
|
||||
|
||||
def _move_category_slides(self, category, new_category):
|
||||
if not category.slide_ids:
|
||||
return
|
||||
truncated_slide_ids = [slide_id for slide_id in self.slide_ids.ids if slide_id not in category.slide_ids.ids]
|
||||
if new_category:
|
||||
place_idx = truncated_slide_ids.index(new_category.id)
|
||||
ordered_slide_ids = truncated_slide_ids[:place_idx] + category.slide_ids.ids + truncated_slide_ids[place_idx]
|
||||
else:
|
||||
ordered_slide_ids = category.slide_ids.ids + truncated_slide_ids
|
||||
for index, slide_id in enumerate(ordered_slide_ids):
|
||||
self.env['slide.slide'].browse([slide_id]).sequence = index + 1
|
||||
|
||||
def _resequence_slides(self, slide, force_category=False):
|
||||
ids_to_resequence = self.slide_ids.ids
|
||||
index_of_added_slide = ids_to_resequence.index(slide.id)
|
||||
|
||||
@@ -460,6 +460,8 @@ class Slide(models.Model):
|
||||
def unlink(self):
|
||||
if self.question_ids and self.channel_id.channel_partner_ids:
|
||||
raise UserError(_("People already took this quiz. To keep course progression it should not be deleted."))
|
||||
for category in self.filtered(lambda slide: slide.is_category):
|
||||
category.channel_id._move_category_slides(category, False)
|
||||
super(Slide, self).unlink()
|
||||
|
||||
# ---------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user