mirror of
https://github.com/bringout/oca-ocb-sale.git
synced 2026-04-26 13:12:06 +02:00
19.0 vanilla
This commit is contained in:
parent
79f83631d5
commit
73afc09215
6267 changed files with 1534193 additions and 1130106 deletions
|
|
@ -1,2 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import main
|
||||
|
|
|
|||
|
|
@ -1,41 +1,48 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from odoo import http
|
||||
from odoo.http import request
|
||||
from odoo.addons.website_sale.controllers.main import WebsiteSale
|
||||
import json
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.http import Controller, request, route
|
||||
|
||||
|
||||
class WebsiteSaleProductComparison(WebsiteSale):
|
||||
class WebsiteSaleProductComparison(Controller):
|
||||
|
||||
@http.route('/shop/compare', type='http', auth="public", website=True, sitemap=False)
|
||||
@route('/shop/compare', type='http', auth='public', website=True, sitemap=False)
|
||||
def product_compare(self, **post):
|
||||
values = {}
|
||||
product_ids = [int(i) for i in post.get('products', '').split(',') if i.isdigit()]
|
||||
if not product_ids:
|
||||
return request.redirect("/shop")
|
||||
return request.redirect('/shop')
|
||||
|
||||
# use search to check read access on each record/ids
|
||||
products = request.env['product.product'].search([('id', 'in', product_ids)])
|
||||
values['products'] = products.with_context(display_default_code=False)
|
||||
return request.render("website_sale_comparison.product_compare", values)
|
||||
|
||||
@http.route(['/shop/get_product_data'], type='json', auth="public", website=True)
|
||||
def get_product_data(self, product_ids, cookies=None):
|
||||
ret = {}
|
||||
|
||||
website = request.env['website'].get_current_website()
|
||||
pricelist = website.pricelist_id
|
||||
products = request.env['product.product'].search([('id', 'in', product_ids)])
|
||||
|
||||
if cookies is not None:
|
||||
ret['cookies'] = json.dumps(request.env['product.product'].search([('id', 'in', list(set(product_ids + cookies)))]).ids)
|
||||
|
||||
products = products.with_context(pricelist=pricelist.id, display_default_code=False)
|
||||
for product in products:
|
||||
ret[product.id] = {
|
||||
'render': request.env['ir.ui.view']._render_template(
|
||||
"website_sale_comparison.product_product",
|
||||
{'product': product, 'website': website}
|
||||
),
|
||||
'product': dict(id=product.id, name=product.name, display_name=product.display_name),
|
||||
return request.render(
|
||||
'website_sale_comparison.product_compare',
|
||||
{
|
||||
'products': products.with_context(display_default_code=False),
|
||||
}
|
||||
return ret
|
||||
)
|
||||
|
||||
@route('/shop/compare/get_product_data', type='jsonrpc', auth='public', website=True)
|
||||
def get_product_data(self, product_ids):
|
||||
products = request.env['product.product'].search([('id', 'in', product_ids)])
|
||||
product_data = []
|
||||
|
||||
for product in products:
|
||||
combination_info = product._get_combination_info_variant()
|
||||
product_data_item = {
|
||||
'id': product.id,
|
||||
'display_name': combination_info['display_name'],
|
||||
'website_url': product.website_url,
|
||||
'image_url': product._get_image_1024_url(),
|
||||
'price': combination_info['price'],
|
||||
'prevent_zero_price_sale': combination_info['prevent_zero_price_sale'],
|
||||
'currency_id': combination_info['currency'].id,
|
||||
}
|
||||
if combination_info['has_discounted_price']:
|
||||
product_data_item['strikethrough_price'] = combination_info['list_price']
|
||||
elif (
|
||||
combination_info.get('compare_list_price')
|
||||
and combination_info['compare_list_price'] > combination_info['price']
|
||||
):
|
||||
product_data_item['strikethrough_price'] = combination_info['compare_list_price']
|
||||
product_data.append(product_data_item)
|
||||
|
||||
return product_data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue