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({