From 9183757380537e53324e52a2249feb2fc056dd3b Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 2 Sep 2013 12:46:46 +0200 Subject: [PATCH] [FIX] website_event vs website_sale: variation of ticket price with pricelist if the ticket have the same price of the product. If the price is different, do not change the price of the ticket bzr revid: chm@openerp.com-20130902104646-argn1gu8rk2p1w7a --- addons/event_sale/event_sale.py | 4 +- addons/website_event/__openerp__.py | 1 + addons/website_event/event.py | 18 ++++++-- addons/website_event/views/website_event.xml | 4 +- addons/website_sale/controllers/main.py | 42 +++++++++++-------- .../static/src/js/website_sale.js | 3 +- addons/website_sale/views/website_sale.xml | 21 ++++++---- addons/website_sale/website_sale.py | 16 +++++-- 8 files changed, 72 insertions(+), 37 deletions(-) diff --git a/addons/event_sale/event_sale.py b/addons/event_sale/event_sale.py index 21682d18373..979d34060ed 100644 --- a/addons/event_sale/event_sale.py +++ b/addons/event_sale/event_sale.py @@ -47,7 +47,8 @@ class sale_order_line(osv.osv): def product_id_change(self, cr, uid, ids, pricelist, - product, qty=0, + product, + qty=0, uom=False, qty_uos=0, uos=False, @@ -88,7 +89,6 @@ class sale_order_line(osv.osv): 'event_id': order_line.event_id.id, 'event_ticket_id': order_line.event_ticket_id and order_line.event_ticket_id.id or None, } - print dic if order_line.event_ticket_id: if order_line.event_ticket_id.register_avail != 9999 and dic['nb_register'] > order_line.event_ticket_id.register_avail: diff --git a/addons/website_event/__openerp__.py b/addons/website_event/__openerp__.py index 3b763b51d20..9a697d6f7c4 100644 --- a/addons/website_event/__openerp__.py +++ b/addons/website_event/__openerp__.py @@ -15,6 +15,7 @@ OpenERP Blog 'views/website_event.xml', 'security/ir.model.access.csv', 'security/website_event.xml', + 'event_demo.xml', ], 'qweb': ['static/src/xml/*.xml'], 'demo': [], diff --git a/addons/website_event/event.py b/addons/website_event/event.py index a5ca4a05a5e..80dcb1971e9 100644 --- a/addons/website_event/event.py +++ b/addons/website_event/event.py @@ -17,9 +17,6 @@ class event(osv.osv): 'website_published': fields.boolean('Available in the website'), 'description_website': fields.html('Description for the website'), } - _defaults = { - 'website_published': True - } class event_event(osv.osv): _inherit = "event.event" @@ -33,3 +30,18 @@ class event_event(osv.osv): partner = self.browse(cr, uid, ids[0], context=context) if partner.address_id: return self.browse(cr, SUPERUSER_ID, ids[0], context=context).address_id.google_map_link() + +class sale_order_line(osv.osv): + _inherit = "sale.order.line" + + def _recalculate_product_values(self, cr, uid, ids, product_id=None, context=None): + if not ids: + return super(sale_order_line, self)._recalculate_product_values(cr, uid, ids, product_id, context=context) + + order_line = self.browse(cr, uid, ids[0], context=context) + product = product_id and self.pool.get('product.product').browse(cr, uid, product_id, context=context) or order_line.product_id + res = super(sale_order_line, self)._recalculate_product_values(cr, uid, ids, product.id, context=context) + if product.event_type_id and order_line.event_ticket_id and order_line.event_ticket_id.price != product.lst_price: + res.update({'price_unit': order_line.event_ticket_id.price}) + + return res diff --git a/addons/website_event/views/website_event.xml b/addons/website_event/views/website_event.xml index a4c120ffe81..8dcfb1dc794 100644 --- a/addons/website_event/views/website_event.xml +++ b/addons/website_event/views/website_event.xml @@ -15,7 +15,9 @@ diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 569a6e724c9..675114b8cfa 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -146,13 +146,13 @@ class Ecommerce(http.Controller): values.update(order.onchange_pricelist_id(pricelist_id, None)['value']) order.write(values) for line in order.order_line: - self.add_product_to_cart(line.product_id.id, 0) + self.add_product_to_cart(order_line_id=line.id, number=0) - def add_product_to_cart(self, product_id=0, number=1, set_number=-1): + 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') - user_obj = request.registry.get('res.users') product_id = product_id and int(product_id) or 0 + order = get_current_order() if not order: order = get_order() @@ -163,9 +163,18 @@ class Ecommerce(http.Controller): # values initialisation values = {} - order_line_ids = order_line_obj.search(request.cr, SUPERUSER_ID, [('order_id', '=', order.id), ('product_id', '=', product_id)], context=context) + + domain = [('order_id', '=', order.id)] + if order_line_id: + domain += [('id', '=', order_line_id)] + else: + domain += [('product_id', '=', product_id)] + + order_line_ids = order_line_obj.search(request.cr, SUPERUSER_ID, domain, context=context) if order_line_ids: order_line = order_line_obj.read(request.cr, SUPERUSER_ID, order_line_ids, [], context=context)[0] + if not product_id: + product_id = order_line['product_id'][0] if set_number >= 0: quantity = set_number else: @@ -178,10 +187,7 @@ class Ecommerce(http.Controller): quantity = 1 # change and record value - pricelist_id = order.pricelist_id and order.pricelist_id.id or False - vals = order_line_obj.product_id_change(request.cr, SUPERUSER_ID, [], pricelist_id, product_id, - partner_id=user_obj.browse(request.cr, SUPERUSER_ID, request.uid).partner_id.id, - context=context)['value'] + vals = order_line_obj._recalculate_product_values(request.cr, request.uid, order_line_ids, product_id, context=context) values.update(vals) values['product_uom_qty'] = quantity @@ -210,7 +216,7 @@ class Ecommerce(http.Controller): suggested_ids = [] if order: for line in order.order_line: - suggested_ids += [p.id for p in line.product_id.suggested_product_ids for line in order.order_line] + suggested_ids += [p.id for p in line.product_id and line.product_id.suggested_product_ids or [] for line in order.order_line] suggested_ids = prod_obj.search(request.cr, request.uid, [('id', 'in', suggested_ids)]) # select 3 random products suggested_products = [] @@ -224,21 +230,21 @@ class Ecommerce(http.Controller): }) return website.render("website_sale.mycart", values) - @http.route(['/shop//add_cart/', '/shop/add_cart/', '/shop/add_cart//', '/shop//add_cart//'], type='http', auth="public") - def add_cart(self, path=None, product_id=0, remove=None): - self.add_product_to_cart(product_id, number=(remove and -1 or 1)) + @http.route(['/shop//add_cart/', '/shop/add_cart/'], type='http', auth="public") + def add_cart(self, path=None, product_id=None, order_line_id=None, remove=None): + self.add_product_to_cart(product_id=product_id, order_line_id=order_line_id, number=(remove and -1 or 1)) if path: return werkzeug.utils.redirect("/shop/%s/" % path) else: return werkzeug.utils.redirect("/shop/") - @http.route(['/shop/remove_cart//', '/shop//remove_cart//'], type='http', auth="public") - def remove_cart(self, path=None, product_id=0): - return self.add_cart(product_id=product_id, path=path, remove=True) + @http.route(['/shop/remove_cart/', '/shop//remove_cart/'], type='http', auth="public") + def remove_cart(self, path=None, product_id=None, order_line_id=None): + return self.add_cart(product_id=product_id, order_line_id=order_line_id, path=path, remove=True) - @http.route(['/shop/set_cart///', '/shop//set_cart///'], type='http', auth="public") - def set_cart(self, path=None, product_id=0, set_number=0): - self.add_product_to_cart(product_id, set_number=set_number) + @http.route(['/shop/set_cart/', '/shop//set_cart/'], type='http', auth="public") + def set_cart(self, path=None, product_id=None, order_line_id=None, set_number=0): + self.add_product_to_cart(product_id=product_id, order_line_id=order_line_id, set_number=set_number) if path: return werkzeug.utils.redirect("/shop/%s/" % path) else: diff --git a/addons/website_sale/static/src/js/website_sale.js b/addons/website_sale/static/src/js/website_sale.js index e79b6a4341c..cf517314abe 100644 --- a/addons/website_sale/static/src/js/website_sale.js +++ b/addons/website_sale/static/src/js/website_sale.js @@ -6,7 +6,8 @@ $(document).ready(function () { $(".oe_website_sale .oe_mycart input.js_quantity").change(function () { var value = parseInt($(this).val()); if (!isNaN(value)) { - window.location.href = window.location.origin + window.location.pathname + 'set_cart/' + $(this).data('id') + '/' + value + '/'; + window.location.href = window.location.origin + window.location.pathname + + 'set_cart/?order_line_id=' + $(this).data('id') + '&set_number=' + value; } }); diff --git a/addons/website_sale/views/website_sale.xml b/addons/website_sale/views/website_sale.xml index 849109c33d9..0592054e23a 100644 --- a/addons/website_sale/views/website_sale.xml +++ b/addons/website_sale/views/website_sale.xml @@ -120,7 +120,7 @@ € @@ -147,7 +147,7 @@

- Add to cart + Add to cart