[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
This commit is contained in:
Thibault Delavallée
2019-09-13 10:05:43 +00:00
parent 290341b455
commit 0b4d052bb5
2 changed files with 18 additions and 0 deletions
@@ -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)]
@@ -13,6 +13,7 @@ class TestCoursePurchaseFlow(common.SlidesCase):
'list_price': 150,
'type': 'service',
'invoice_policy': 'order',
'is_published': True,
})
self.channel.write({