From d2a743cbdef157aa5e54aded27c405310419fd8b Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 2 Oct 2013 09:12:39 +0200 Subject: [PATCH] [IMP] website_sale: context, routes bzr revid: chm@openerp.com-20131002071239-4glhz7g8iz1r9gea --- .../website/static/src/js/website.snippets.js | 6 +- addons/website_event/event.py | 2 +- addons/website_sale/controllers/main.py | 55 ++++++++----------- .../static/src/js/website_sale.js | 10 ++-- addons/website_sale/views/website_sale.xml | 22 ++++---- addons/website_sale/website_sale.py | 8 ++- 6 files changed, 49 insertions(+), 54 deletions(-) diff --git a/addons/website/static/src/js/website.snippets.js b/addons/website/static/src/js/website.snippets.js index 9d0c0242b5c..3de2ddaeabb 100644 --- a/addons/website/static/src/js/website.snippets.js +++ b/addons/website/static/src/js/website.snippets.js @@ -825,7 +825,7 @@ editor.on('start', self, function (o) {o.url = bg_value;}); editor.on('save', self, function (o) { var $bg = typeof bg == 'string' ? self.$target.find(bg) : $(bg); - $bg.css("background-image", "url('" + o.url + "')"); + $bg.css("background-image", "url(" + o.url + ")"); }); editor.appendTo($('body')); } @@ -834,13 +834,13 @@ if ($(this).data("value")) { var src = $(this).data("value"); var $bg = typeof bg == 'string' ? self.$target.find(bg) : $(bg); - $bg.css("background-image", "url('" + src + "')"); + $bg.css("background-image", "url(" + src + ")"); } }) .on('mouseout', function (event) { var src = $ul.find('li.active').data("value"); var $bg = typeof bg == 'string' ? self.$target.find(bg) : $(bg); - $bg.css("background-image", "url('" + src + "')"); + $bg.css("background-image", "url(" + src + ")"); }); }, }); diff --git a/addons/website_event/event.py b/addons/website_event/event.py index 15340444807..0362b5845b7 100644 --- a/addons/website_event/event.py +++ b/addons/website_event/event.py @@ -64,7 +64,7 @@ class event(osv.osv): class sale_order_line(osv.osv): _inherit = "sale.order.line" - def _recalculate_product_values(self, cr, uid, ids, product_id=None, context=None): + def _recalculate_product_values(self, cr, uid, ids, product_id=0, context=None): if not ids: return super(sale_order_line, self)._recalculate_product_values(cr, uid, ids, product_id, context=context) diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 9b9ae135119..06c5a8288d2 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -12,19 +12,19 @@ def get_order(order_id=None): # check if order allready exists if order_id: try: - order = order_obj.browse(request.cr, SUPERUSER_ID, order_id, request.context) + order = order_obj.browse(request.cr, SUPERUSER_ID, order_id, context=request.context) order.pricelist_id except: order_id = None if not order_id: fields = [k for k, v in order_obj._columns.items()] - order_value = order_obj.default_get(request.cr, SUPERUSER_ID, fields, request.context) + order_value = order_obj.default_get(request.cr, SUPERUSER_ID, fields, context=request.context) if request.httprequest.session.get('ecommerce_pricelist'): order_value['pricelist_id'] = request.httprequest.session['ecommerce_pricelist'] - order_value['partner_id'] = request.registry.get('res.users').browse(request.cr, SUPERUSER_ID, request.uid, request.context).partner_id.id + order_value['partner_id'] = request.registry.get('res.users').browse(request.cr, SUPERUSER_ID, request.uid, context=request.context).partner_id.id order_value.update(order_obj.onchange_partner_id(request.cr, SUPERUSER_ID, [], order_value['partner_id'], context=request.context)['value']) - order_id = order_obj.create(request.cr, SUPERUSER_ID, order_value, request.context) - order = order_obj.browse(request.cr, SUPERUSER_ID, order_id, request.context) + order_id = order_obj.create(request.cr, SUPERUSER_ID, order_value, context=request.context) + order = order_obj.browse(request.cr, SUPERUSER_ID, order_id, context=request.context) request.httprequest.session['ecommerce_order_id'] = order.id return order_obj.browse(request.cr, SUPERUSER_ID, order_id, @@ -250,26 +250,24 @@ class Ecommerce(http.Controller): } return request.website.render("website_sale.products", values) - @website.route(['/shop/product//'], type='http', auth="public", multilang=True) + @website.route(['/shop/product//'], type='http', auth="public", multilang=True) def product(self, cat_id=0, product_id=0, **post): if 'promo' in post: self.change_pricelist(post.get('promo')) - product_id = product_id and int(product_id) or 0 product_obj = request.registry.get('product.template') category_obj = request.registry.get('product.public.category') category_ids = category_obj.search(request.cr, request.uid, [(1, '=', 1)], context=request.context) - category_list = category_obj.name_get(request.cr, request.uid, category_ids, request.context) + category_list = category_obj.name_get(request.cr, request.uid, category_ids, context=request.context) category_list = sorted(category_list, key=lambda category: category[1]) - request.context['pricelist'] = self.get_pricelist() - category = None if post.get('category_id') and int(post.get('category_id')): category = category_obj.browse(request.cr, request.uid, int(post.get('category_id')), context=request.context) + request.context['pricelist'] = self.get_pricelist() product = product_obj.browse(request.cr, request.uid, product_id, context=request.context) values = { @@ -282,7 +280,7 @@ class Ecommerce(http.Controller): } return request.website.render("website_sale.product", values) - @website.route(['/shop/add_product/', '/shop/category//add_product/'], type='http', auth="public", multilang=True) + @website.route(['/shop/add_product/', '/shop/category//add_product/'], type='http', auth="public", multilang=True) def add_product(self, cat_id=0, **post): product_id = request.registry.get('product.product').create(request.cr, request.uid, {'name': 'New Product', 'public_categ_id': cat_id}, request.context) @@ -320,13 +318,11 @@ class Ecommerce(http.Controller): def add_product_to_cart(self, product_id=0, order_line_id=0, number=1, set_number=-1): order_line_obj = request.registry.get('sale.order.line') - product_id = product_id and int(product_id) or 0 - order = get_current_order() if not order: order = get_order() - context = dict(request.context, pricelist=self.get_pricelist()) + request.context = dict(request.context, pricelist=self.get_pricelist()) quantity = 0 @@ -339,9 +335,9 @@ class Ecommerce(http.Controller): else: domain += [('product_id', '=', product_id)] - order_line_ids = order_line_obj.search(request.cr, SUPERUSER_ID, domain, context=context) + order_line_ids = order_line_obj.search(request.cr, SUPERUSER_ID, domain, context=request.context) if order_line_ids: - order_line = order_line_obj.read(request.cr, SUPERUSER_ID, order_line_ids, [], context=context)[0] + order_line = order_line_obj.read(request.cr, SUPERUSER_ID, order_line_ids, [], context=request.context)[0] if not product_id: product_id = order_line['product_id'][0] if set_number >= 0: @@ -352,11 +348,11 @@ class Ecommerce(http.Controller): quantity = 0 else: fields = [k for k, v in order_line_obj._columns.items()] - values = order_line_obj.default_get(request.cr, SUPERUSER_ID, fields, context=context) + values = order_line_obj.default_get(request.cr, SUPERUSER_ID, fields, context=request.context) quantity = 1 # change and record value - vals = order_line_obj._recalculate_product_values(request.cr, request.uid, order_line_ids, product_id, context=context) + vals = order_line_obj._recalculate_product_values(request.cr, request.uid, order_line_ids, product_id, context=request.context) values.update(vals) values['product_uom_qty'] = quantity @@ -364,13 +360,13 @@ class Ecommerce(http.Controller): values['order_id'] = order.id if order_line_ids: - order_line_obj.write(request.cr, SUPERUSER_ID, order_line_ids, values, context=context) + order_line_obj.write(request.cr, SUPERUSER_ID, order_line_ids, values, context=request.context) if not quantity: - order_line_obj.unlink(request.cr, SUPERUSER_ID, order_line_ids, context=context) + order_line_obj.unlink(request.cr, SUPERUSER_ID, order_line_ids, context=request.context) else: #values['name'] = "website order" - order_line_id = order_line_obj.create(request.cr, SUPERUSER_ID, values, context=context) - order.write({'order_line': [(4, order_line_id)]}, context=context) + order_line_id = order_line_obj.create(request.cr, SUPERUSER_ID, values, context=request.context) + order.write({'order_line': [(4, order_line_id)]}, context=request.context) return [quantity, order.get_total_quantity()] @@ -403,7 +399,7 @@ class Ecommerce(http.Controller): @website.route(['/shop//add_cart/', '/shop/add_cart/'], type='http', auth="public", multilang=True) def add_cart(self, path=None, product_id=None, order_line_id=None, remove=None, **kw): - self.add_product_to_cart(product_id=product_id, order_line_id=order_line_id, number=(remove and -1 or 1)) + self.add_product_to_cart(product_id=product_id and int(product_id), order_line_id=order_line_id and int(order_line_id), number=(remove and -1 or 1)) return request.redirect("/shop/mycart/") @website.route(['/shop/add_cart_json/'], type='json', auth="public") @@ -569,14 +565,14 @@ class Ecommerce(http.Controller): def change_sequence(self, id, top): product_obj = request.registry.get('product.template') if top: - product_obj.set_sequence_top(request.cr, request.uid, [id], request.context) + product_obj.set_sequence_top(request.cr, request.uid, [id], context=request.context) else: - product_obj.set_sequence_bottom(request.cr, request.uid, [id], request.context) + product_obj.set_sequence_bottom(request.cr, request.uid, [id], context=request.context) @website.route(['/shop/change_styles/'], type='json', auth="public") def change_styles(self, id, style_id): product_obj = request.registry.get('product.template') - product = product_obj.browse(request.cr, request.uid, id, request.context) + product = product_obj.browse(request.cr, request.uid, id, context=request.context) remove = [] active = False @@ -586,14 +582,11 @@ class Ecommerce(http.Controller): active = True break - style = request.registry.get('website.product.style').browse(request.cr, request.uid, style_id, request.context) + style = request.registry.get('website.product.style').browse(request.cr, request.uid, style_id, context=request.context) if remove: - print "remove", remove product.write({'website_style_ids': [(3, rid) for rid in remove]}) - if not active: - print "add", style.id product.write({'website_style_ids': [(4, style.id)]}) return not active @@ -601,7 +594,7 @@ class Ecommerce(http.Controller): @website.route(['/shop/change_size/'], type='json', auth="public") def change_size(self, id, x, y): product_obj = request.registry.get('product.template') - product = product_obj.browse(request.cr, request.uid, id, request.context) + product = product_obj.browse(request.cr, request.uid, id, context=request.context) return product.write({'website_size_x': x, 'website_size_y': y}) # vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/website_sale/static/src/js/website_sale.js b/addons/website_sale/static/src/js/website_sale.js index 0512288e4de..60bb42a6e10 100644 --- a/addons/website_sale/static/src/js/website_sale.js +++ b/addons/website_sale/static/src/js/website_sale.js @@ -36,20 +36,18 @@ $(document).ready(function () { }); // hack to add and rome from cart with json - $('.oe_website_sale a[href*="/add_cart/"], a[href*="/remove_cart/"]').on('click', function (ev) { + $('.oe_website_sale a[href*="/add_cart/"],.oe_website_sale a[href*="/remove_cart/"]').on('click', function (ev) { ev.preventDefault(); var $link = $(ev.currentTarget); - var product_id = $link.attr("href").match(/product_id=([0-9]+)/)[1]; - if (product_id) { - product_id = +product_id; - } + var product = $link.attr("href").match(/product_id=([0-9]+)/); + var product_id = product ? +product[1] : 0; openerp.jsonRpc("/shop/add_cart_json/", 'call', {'product_id': product_id, 'order_line_id': $link.data('id'), 'remove': $link.is('[href*="/remove_cart/"]')}) .then(function (data) { if (!data[0]) { location.reload(); } set_my_cart_quantity(data[1]); - $link.parent().find(".js_quantity").val(data[0]); + $link.parents(".input-group:first").find(".js_quantity").val(data[0]); }); return false; }); diff --git a/addons/website_sale/views/website_sale.xml b/addons/website_sale/views/website_sale.xml index 4a3d64436be..f7fee366b40 100644 --- a/addons/website_sale/views/website_sale.xml +++ b/addons/website_sale/views/website_sale.xml @@ -313,14 +313,16 @@
-
- -
-

-
-

- -

+ +
+ + + + € +   + +

+

@@ -427,14 +429,14 @@
- + - + diff --git a/addons/website_sale/website_sale.py b/addons/website_sale/website_sale.py index 37ad53a0322..f1b4bd9f0c7 100644 --- a/addons/website_sale/website_sale.py +++ b/addons/website_sale/website_sale.py @@ -34,13 +34,15 @@ class sale_order(osv.Model): class sale_order_line(osv.Model): _inherit = "sale.order.line" - def _recalculate_product_values(self, cr, uid, ids, product_id=None, context=None): + def _recalculate_product_values(self, cr, uid, ids, product_id=0, context=None): if context is None: context = {} user_obj = self.pool.get('res.users') - product_id = product_id or ids and self.browse(cr, uid, ids[0], context=context).product_id.id + product_id = product_id and int(product_id) or \ + ids and self.browse(cr, uid, ids[0], context=context).product_id.id + return self.product_id_change( - cr, SUPERUSER_ID, [], + cr, SUPERUSER_ID, ids, pricelist=context.pop('pricelist'), product=product_id, partner_id=user_obj.browse(cr, SUPERUSER_ID, uid).partner_id.id,