diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 486914dfd6a..871622c9a26 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -98,18 +98,33 @@ class QueryURL(object): return path -def get_pricelist(): - cr, uid, context, pool = request.cr, request.uid, request.context, request.registry - sale_order = context.get('sale_order') - if sale_order: - pricelist = sale_order.pricelist_id - else: - partner = pool['res.users'].browse(cr, SUPERUSER_ID, uid, context=context).partner_id - pricelist = partner.property_product_pricelist - return pricelist - class website_sale(http.Controller): + def get_pricelist(self): + cr, uid, context, pool = request.cr, request.uid, request.context, request.registry + sale_order = context.get('sale_order') + if sale_order: + pricelist = sale_order.pricelist_id + else: + partner = pool['res.users'].browse(cr, SUPERUSER_ID, uid, context=context).partner_id + pricelist = partner.property_product_pricelist + return pricelist + + def get_attribute_value_ids(self, product): + cr, uid, context, pool = request.cr, request.uid, request.context, request.registry + currency_obj = pool['res.currency'] + attribute_value_ids = [] + if request.website.pricelist_id.id != context['pricelist']: + website_currency_id = request.website.currency_id.id + currency_id = self.get_pricelist().currency_id.id + for p in product.product_variant_ids: + price = currency_obj.compute(cr, uid, website_currency_id, currency_id, p.lst_price) + attribute_value_ids.append([p.id, map(int, p.attribute_value_ids), p.price, price]) + else: + attribute_value_ids = [[p.id, map(int, p.attribute_value_ids), p.price, p.lst_price] for p in product.product_variant_ids] + + return attribute_value_ids + @http.route(['/shop', '/shop/page/', '/shop/category/', @@ -194,7 +209,6 @@ class website_sale(http.Controller): cr, uid, context, pool = request.cr, request.uid, request.context, request.registry category_obj = pool['product.public.category'] template_obj = pool['product.template'] - currency_obj = pool['res.currency'] context.update(active_id=product.id) @@ -215,16 +229,6 @@ class website_sale(http.Controller): context['pricelist'] = int(self.get_pricelist()) product = template_obj.browse(cr, uid, int(product), context=context) - attribute_value_ids = [] - if request.website.pricelist_id.id != context['pricelist']: - company_currency_id = request.website.company_currency_id.id - currency_id = self.get_pricelist().currency_id.id - for p in product.product_variant_ids: - price = currency_obj.compute(cr, uid, company_currency_id, currency_id, p.lst_price) - attribute_value_ids.append([p.id, map(int, p.attribute_value_ids), p.price, price]) - else: - attribute_value_ids = [[p.id, map(int, p.attribute_value_ids), p.price, p.lst_price] for p in product.product_variant_ids] - values = { 'search': search, 'category': category, @@ -235,7 +239,7 @@ class website_sale(http.Controller): 'category_list': category_list, 'main_object': product, 'product': product, - 'attribute_value_ids': attribute_value_ids + 'get_attribute_value_ids': self.get_attribute_value_ids } return request.website.render("website_sale.product", values) @@ -279,7 +283,7 @@ class website_sale(http.Controller): prod_obj = pool['product.product'] order = request.website.sale_get_order(force_create=1) - line_id, quantity = order._cart_update(product_id=int(product_id), add_qty=int(add_qty), set_qty=int(set_qty)) + order._cart_update(product_id=int(product_id), add_qty=int(add_qty), set_qty=int(set_qty)) if goto_shop: return request.redirect("/shop/product/%s" % slug(prod_obj.browse(cr, uid, product_id).product_tmpl_id)) @@ -289,16 +293,14 @@ class website_sale(http.Controller): @http.route(['/shop/cart/update_json'], type='json', auth="public", methods=['POST'], website=True) def cart_update_json(self, product_id, line_id, add_qty=None, set_qty=None, display=True): order = request.website.sale_get_order(force_create=1) - line_id, quantity = order._cart_update(product_id=product_id, line_id=line_id, add_qty=add_qty, set_qty=set_qty) + value = order._cart_update(product_id=product_id, line_id=line_id, add_qty=add_qty, set_qty=set_qty) if not display: return None - return { - 'quantity': quantity, - 'cart_quantity': order.cart_quantity, - 'website_sale.total': request.website._render("website_sale.total", { - 'website_sale_order': request.website.sale_get_order() - }) - } + value['cart_quantity'] = order.cart_quantity + value['website_sale.total'] = request.website._render("website_sale.total", { + 'website_sale_order': request.website.sale_get_order() + }) + return value #------------------------------------------------------ # Checkout diff --git a/addons/website_sale/models/sale_order.py b/addons/website_sale/models/sale_order.py index 49f69c9ff57..165030f9f1a 100644 --- a/addons/website_sale/models/sale_order.py +++ b/addons/website_sale/models/sale_order.py @@ -4,7 +4,6 @@ import random from openerp import SUPERUSER_ID from openerp.osv import osv, orm, fields from openerp.addons.web.http import request -from openerp.tools.translate import _ class payment_transaction(orm.Model): @@ -15,13 +14,6 @@ class payment_transaction(orm.Model): 'sale_order_id': fields.many2one('sale.order', 'Sale Order'), } -class sale_order_line(osv.Model): - _inherit = "sale.order.line" - _columns = { - 'linked_line_id': fields.many2one('sale.order.line', 'Linked Order Line', domain="[('order_id','!=',order_id)]"), - 'option_line_ids': fields.one2many('sale.order.line', 'linked_line_id', string='Options Linked'), - } - class sale_order(osv.Model): _inherit = "sale.order" @@ -51,7 +43,7 @@ class sale_order(osv.Model): 'order': order } - def _cart_find_product_line(self, cr, uid, ids, product_id=None, line_id=None, context=None, *args): + def _cart_find_product_line(self, cr, uid, ids, product_id=None, line_id=None, context=None, **kwargs): for so in self.browse(cr, uid, ids, context=context): domain = [('order_id', '=', so.id), ('product_id', '=', product_id)] if line_id: @@ -81,14 +73,14 @@ class sale_order(osv.Model): values['tax_id'] = [(6, 0, values['tax_id'])] return values - def _cart_update(self, cr, uid, ids, product_id=None, line_id=None, add_qty=0, set_qty=0, context=None, *args): + def _cart_update(self, cr, uid, ids, product_id=None, line_id=None, add_qty=0, set_qty=0, context=None, **kwargs): """ Add or set product quantity, add_qty can be negative """ sol = self.pool.get('sale.order.line') quantity = 0 for so in self.browse(cr, uid, ids, context=context): if line_id != False: - line_ids = so._cart_find_product_line(product_id, line_id, context=context, *args) + line_ids = so._cart_find_product_line(product_id, line_id, context=context, **kwargs) if line_ids: line_id = line_ids[0] @@ -114,7 +106,7 @@ class sale_order(osv.Model): values['product_uom_qty'] = quantity sol.write(cr, SUPERUSER_ID, [line_id], values, context=context) - return (line_id, quantity) + return {'line_id': line_id, 'quantity': quantity} def _cart_accessories(self, cr, uid, ids, context=None): for order in self.browse(cr, uid, ids, context=context): diff --git a/addons/website_sale/static/src/css/website_sale.css b/addons/website_sale/static/src/css/website_sale.css index c3774f9ed03..8055d0ad310 100644 --- a/addons/website_sale/static/src/css/website_sale.css +++ b/addons/website_sale/static/src/css/website_sale.css @@ -302,7 +302,7 @@ display: none; } -.css_not_available.js_product > *:nth-child(3) > *, .css_not_available.js_product *:nth-child(4) > * { +.css_not_available.js_product > *:nth-child(4) > * { display: none; } .css_not_available.js_product .product_price, .css_not_available.js_product .css_quantity { diff --git a/addons/website_sale/static/src/css/website_sale.sass b/addons/website_sale/static/src/css/website_sale.sass index 17dfcb8ea44..f08b635124c 100644 --- a/addons/website_sale/static/src/css/website_sale.sass +++ b/addons/website_sale/static/src/css/website_sale.sass @@ -260,7 +260,7 @@ .css_not_available_msg display: none .css_not_available.js_product - > *:nth-child(3) > *, *:nth-child(4) > * + > *:nth-child(4) > * display: none .product_price, .css_quantity display: none diff --git a/addons/website_sale/static/src/js/website_sale.js b/addons/website_sale/static/src/js/website_sale.js index c9a8c8eea3a..6cc283976d0 100644 --- a/addons/website_sale/static/src/js/website_sale.js +++ b/addons/website_sale/static/src/js/website_sale.js @@ -15,9 +15,10 @@ $(document).ready(function () { $(".oe_website_sale .oe_cart input.js_quantity").change(function () { var $input = $(this); var value = parseInt($input.val(), 10); + var line_id = parseInt($input.data('line-id'),10); if (isNaN(value)) value = 0; openerp.jsonRpc("/shop/cart/update_json", 'call', { - 'line_id': parseInt($input.data('line-id'),10), + 'line_id': line_id, 'product_id': parseInt($input.data('product-id'),10), 'set_qty': value}) .then(function (data) { @@ -33,13 +34,15 @@ $(document).ready(function () { var $q = $(".my_cart_quantity"); $q.parent().parent().removeClass("hidden", !data.quantity); $q.html(data.cart_quantity).hide().fadeIn(600); + $input.val(data.quantity); + $('.js_quantity[data-line-id='+line_id+']').val(data.quantity).html(data.quantity); $("#cart_total").replaceWith(data['website_sale.total']); }); }); // hack to add and rome from cart with json - $('.oe_website_sale a.js_add_cart_json').on('click', function (ev) { + $('.oe_website_sale').on('click', 'a.js_add_cart_json', function (ev) { ev.preventDefault(); var $link = $(ev.currentTarget); var $input = $link.parent().parent().find("input"); @@ -82,9 +85,9 @@ $(document).ready(function () { return price + (dec ? '' : '.0') + (dec%10 ? '' : '0'); } - $('input.js_variant_change, select.js_variant_change').change(function (ev) { + $('.oe_website_sale').on('change', 'input.js_variant_change, select.js_variant_change', function (ev) { var $ul = $(this).parents('ul.js_add_cart_variants:first'); - var $parent = $ul.parents('.js_product:first'); + var $parent = $ul.closest('.js_product'); var $product_id = $parent.find('input.product_id').first(); var $price = $parent.find(".oe_price:first .oe_currency_value"); var $default_price = $parent.find(".oe_default_price:first .oe_currency_value"); @@ -121,7 +124,7 @@ $(document).ready(function () { return; } } - $input.parents("label:first").addClass("css_not_available"); + $input.closest("label").addClass("css_not_available"); $input.find("option[value='" + id + "']").addClass("css_not_available"); }); @@ -139,42 +142,13 @@ $(document).ready(function () { $('input.js_variant_change, select.js_variant_change', this).first().trigger('change'); }); - $("input.js_quantity").change(function (event) { - var qty = parseFloat($(this).val()); - if (qty === 1) { - $(".js_remove .js_items").addClass("hidden"); - $(".js_remove .js_item").removeClass("hidden"); - } else { - $(".js_remove .js_items").removeClass("hidden").text($(".js_remove .js_items").text().replace(/[0-9.,]+/, qty)); - $(".js_remove .js_item").addClass("hidden"); - } - }); - - - $('#product_detail form[action^="/shop/cart/update"] .a-submit').off("click").click(function (event) { - event.preventDefault(); - var $link = $(this); - var $form = $link.parents("form:first"); - var quantity = parseInt($('input[name="add_qty"]:last').val() || 1, 10); - var defs = []; - $link.attr('disabled', 'disabled'); - $.when.apply($.when, defs).then(function () { - if ($link.hasClass("js_goto_shop")) { - $form.prepend(''); - } - $form.submit(); - }); - return false; - }); - - - $(".oe_website_sale select[name='country_id']").change(function () { + $(".oe_website_sale").on('change', "select[name='country_id']", function () { var $select = $("select[name='state_id']"); $select.find("option:not(:first)").hide(); var nb = $select.find("option[data-country_id="+($(this).val() || 0)+"]").show().size(); $select.parent().toggle(nb>1); }).change(); - $(".oe_website_sale select[name='shipping_country_id']").change(function () { + $(".oe_website_sale").on('change', "select[name='shipping_country_id']", function () { var $select = $("select[name='shipping_state_id']"); $select.find("option:not(:first)").hide(); var nb = $select.find("option[data-country_id="+($(this).val() || 0)+"]").show().size(); diff --git a/addons/website_sale/views/templates.xml b/addons/website_sale/views/templates.xml index 3372fc26748..7e4252df18e 100644 --- a/addons/website_sale/views/templates.xml +++ b/addons/website_sale/views/templates.xml @@ -76,7 +76,7 @@   @@ -416,7 +416,7 @@