Files
odoo_source/addons/website_sale_slides/controllers/slides.py
T
Jérémy Hennecart (jeh) 5881195bfe [FIX] website_sale_slides: fix sync between product and course
Before, each time we created a course "on payment". The product
linked to it was automatically unpublished. If multiple course
share the same product this leads to issues. Indeed, with the
product unpublished all the courses depending on the product are
no longer buyable.
To avoid this, we synchronise the published value when the
course is published which published the product.
If we create a new course or unpublished a previous course linked
to a product, we don't update the published value of the product
unless all courses linked to this product are unpublished.

We also fix a Forbidden error raised when the product was unpublished
but not the course. This was leading to a previous member to not have
access to a course he previously buyed.

task-2842624

Part-of: odoo/odoo#90736
2022-06-01 16:26:08 +02:00

44 lines
2.1 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.website_slides.controllers.main import WebsiteSlides
from odoo.http import request, route
from odoo.tools import format_amount
class WebsiteSaleSlides(WebsiteSlides):
@route('/slides/get_course_products', type='json', auth='user')
def get_course_products(self):
"""Return a list of the course products values with formatted price."""
products = request.env['product.product'].search([('detailed_type', '=', 'course')])
return [{
'id': product.id,
'name': f'{product.name} ({format_amount(request.env, product.list_price, product.currency_id)})',
} for product in products]
def _prepare_additional_channel_values(self, values, **kwargs):
values = super(WebsiteSaleSlides, self)._prepare_additional_channel_values(values, **kwargs)
channel = values['channel']
if channel.enroll == 'payment':
# search the product to apply ACLs, notably on published status, to avoid access errors
product = request.env['product.product'].search([('id', '=', channel.product_id.id)]) if channel.product_id else request.env['product.product']
if product:
pricelist = request.website.get_current_pricelist()
values['product_info'] = channel.product_id.product_tmpl_id._get_combination_info(product_id=channel.product_id.id, pricelist=pricelist)
values['product_info']['currency_id'] = request.website.currency_id
else:
values['product_info'] = False
return values
def _slide_channel_prepare_values(self, **kwargs):
"""Parse the values posted when we create a new course
from website to add the selected product.
"""
channel = super(WebsiteSaleSlides, self)._slide_channel_prepare_values(**kwargs)
channel['enroll'] = kwargs.get('enroll')
if channel['enroll'] == 'payment' and 'product_id' in kwargs:
channel['product_id'] = int(kwargs['product_id'])
return channel