| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 3 |
|
| 4 |
from odoo.addons.website_slides.controllers.main import WebsiteSlides |
| 5 |
from odoo.http import request, route |
| 6 |
from odoo.tools import format_amount |
| 7 |
|
| 8 |
|
| 9 |
class WebsiteSaleSlides(WebsiteSlides): |
| 10 |
|
| 11 |
@route('/slides/get_course_products', type='jsonrpc', auth='user') |
| 12 |
def get_course_products(self): |
| 13 |
"""Return a list of the course products values with formatted price.""" |
| 14 |
products = request.env['product.product'].search([('service_tracking', '=', 'course')]) |
| 15 |
|
| 16 |
return [{ |
| 17 |
'id': product.id, |
| 18 |
'name': f'{product.name} ({format_amount(request.env, product.list_price, product.currency_id)})', |
| 19 |
} for product in products] |
| 20 |
|
| 21 |
def _prepare_additional_channel_values(self, values, **kwargs): |
| 22 |
values = super(WebsiteSaleSlides, self)._prepare_additional_channel_values(values, **kwargs) |
| 23 |
channel = values['channel'] |
| 24 |
if channel.enroll == 'payment': |
| 25 |
# search the product to apply ACLs, notably on published status, to avoid access errors |
| 26 |
product = request.env['product.product'].search([('id', '=', channel.product_id.id)]) if channel.product_id else request.env['product.product'] |
| 27 |
if product: |
| 28 |
values['product_info'] = product._get_combination_info_variant() |
| 29 |
else: |
| 30 |
values['product_info'] = False |
| 31 |
return values |