From 0b4d052bb56d1e384f714d72ecd73624b4adb697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 12 Sep 2019 12:11:56 +0000 Subject: [PATCH] [FIX] website_sale_slides: synchronize publish status of a channel and its product Currently when creating a payment-based channel with its product and then publishing the channel public users cannot browse the channel as the product is not readable. This commit fixes that by synchronizing the publish status of channels and their products. Task 2067872 (eLearning internal testing) PR #36756 --- .../website_sale_slides/models/slide_channel.py | 17 +++++++++++++++++ .../tests/test_course_purchase_flow.py | 1 + 2 files changed, 18 insertions(+) diff --git a/addons/website_sale_slides/models/slide_channel.py b/addons/website_sale_slides/models/slide_channel.py index 685e0af9aa0..bb95e2e0ab5 100644 --- a/addons/website_sale_slides/models/slide_channel.py +++ b/addons/website_sale_slides/models/slide_channel.py @@ -31,6 +31,23 @@ class Channel(models.Model): for channel in self: channel.product_sale_revenues = rg_data.get(channel.product_id.id, 0) + @api.model + def create(self, vals): + channel = super(Channel, self).create(vals) + if channel.enroll == 'payment': + channel._synchronize_product_publish() + return channel + + def write(self, vals): + res = super(Channel, self).write(vals) + if 'is_published' in vals: + self.filtered(lambda channel: channel.enroll == 'payment')._synchronize_product_publish() + return res + + def _synchronize_product_publish(self): + self.filtered(lambda channel: channel.is_published and not channel.product_id.is_published).sudo().product_id.write({'is_published': True}) + self.filtered(lambda channel: not channel.is_published and channel.product_id.is_published).sudo().product_id.write({'is_published': False}) + def action_view_sales(self): action = self.env.ref('website_sale_slides.sale_report_action_slides').read()[0] action['domain'] = [('product_id', 'in', self.product_id.ids)] diff --git a/addons/website_sale_slides/tests/test_course_purchase_flow.py b/addons/website_sale_slides/tests/test_course_purchase_flow.py index 8bce4fea63a..09db54f7f21 100644 --- a/addons/website_sale_slides/tests/test_course_purchase_flow.py +++ b/addons/website_sale_slides/tests/test_course_purchase_flow.py @@ -13,6 +13,7 @@ class TestCoursePurchaseFlow(common.SlidesCase): 'list_price': 150, 'type': 'service', 'invoice_policy': 'order', + 'is_published': True, }) self.channel.write({