[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
This commit is contained in:
Christophe Matthieu 2013-09-02 12:46:46 +02:00
parent f0021c5cc5
commit 9183757380
8 changed files with 72 additions and 37 deletions

View File

@ -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:

View File

@ -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': [],

View File

@ -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

View File

@ -15,7 +15,9 @@
<template id="event_website_sale_mycart" inherit_id="website_sale.mycart">
<xpath expr="//small[@class='text-error']" position="replace">
<small t-if="line.product_id.lst_price != line.price_unit and not line.event_id" class="text-error" style="text-decoration: line-through;"><t t-esc="line.product_id.lst_price" /></small>
<t t-if="(not line.event_id or line.event_ticket_id and line.event_ticket_id.price == line.product_id.lst_price)">
<small class="text-error" style="text-decoration: line-through;"><t t-esc="line.product_id.lst_price" /></small>
</t>
</xpath>
</template>

View File

@ -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/<path:path>/add_cart/', '/shop/add_cart/', '/shop/add_cart/<product_id>/', '/shop/<path:path>/add_cart/<product_id>/'], 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/<path:path>/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/<product_id>/', '/shop/<path:path>/remove_cart/<product_id>/'], 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/<path:path>/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/<product_id>/<set_number>/', '/shop/<path:path>/set_cart/<product_id>/<set_number>/'], 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/<path:path>/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:

View File

@ -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;
}
});

View File

@ -120,7 +120,7 @@
<b><t t-esc="product.product_variant_ids[0].price" /></b>
</div>
<div class="mb8 mt8">
<a t-if="product.website_published" t-attf-href="./add_cart/#{ product.id }/" class="btn btn-default btn-sm btn-success">Add to cart</a>
<a t-if="product.website_published" t-attf-href="./add_cart/?product_id=#{ product.id }" class="btn btn-default btn-sm btn-success">Add to cart</a>
</div>
</div>
</div>
@ -147,7 +147,7 @@
<div id="product_detail">
<t t-call="website.publish"><t t-set="object" t-value="product"/></t>
<h1 t-field="product.name"></h1>
<a t-if="not product.product_variant_ids" t-attf-href="./add_cart/#{ product.id }/" class="btn btn-default btn-sm btn-success pull-right">Add to cart</a>
<a t-if="not product.product_variant_ids" t-attf-href="./add_cart/?product_id=#{ product.id }" class="btn btn-default btn-sm btn-success pull-right">Add to cart</a>
<form t-if="len(product.product_variant_ids) > 1" action="./add_cart/" class="pull-right">
<label label-default="label-default" class="radio" t-foreach="product.product_variant_ids" t-as="product">
<input type="radio" name="product_id" t-att-value="product.id" t-att-checked="product == product.product_variant_ids[0] or None"/>
@ -216,22 +216,25 @@
<tbody t-if="order and order.order_line">
<t t-foreach="order.order_line" t-as="line">
<tr>
<td>
<td colspan="2" t-if="not line.product_id.product_tmpl_id"></td>
<td t-if="line.product_id.product_tmpl_id">
<a t-attf-href="/shop/product/#{ line.product_id.product_tmpl_id.id }/"><img class="img-rounded" t-att-src="line.product_id.img('image_small')"/></a>
</td>
<td>
<td t-if="line.product_id.product_tmpl_id">
<a t-attf-href="/shop/product/#{ line.product_id.product_tmpl_id.id }/"><span t-field="line.name"/></a><br/>
<small t-field="line.product_id.description_sale"/>
</td>
<td>
<small t-if="line.product_id.lst_price != line.price_unit" class="text-error" style="text-decoration: line-through;"><t t-esc="line.product_id.lst_price" /></small>
<t t-if="line.product_id.product_tmpl_id and line.product_id.lst_price != line.price_unit">
<small class="text-error" style="text-decoration: line-through;"><t t-esc="line.product_id.lst_price" /></small>
</t>
<span t-field="line.price_unit"></span>
</td>
<td>
<div class="pull-right">
<input type="text" class="js_quantity input-sm col-md-5" t-att-data-id="line.product_id.id" t-att-value="line.product_uom_qty"/>
<a t-attf-href="./remove_cart/#{ line.product_id.id }/" class="btn btn-default mb8 btn-sm btn-inverse">-</a>
<a t-attf-href="./add_cart/#{ line.product_id.id }/" class="btn btn-default mb8 btn-sm btn-success">+</a>
<input type="text" class="js_quantity input-sm col-md-5" t-att-data-id="line.id" t-att-value="line.product_uom_qty"/>
<a t-attf-href="./remove_cart/?order_line_id=#{ line.id }" class="btn btn-default mb8 btn-sm btn-inverse">-</a>
<a t-attf-href="./add_cart/?order_line_id=#{ line.id }" class="btn btn-default mb8 btn-sm btn-success">+</a>
</div>
</td>
</tr>
@ -281,7 +284,7 @@
</td>
<td>
<div class="pull-right">
<a t-attf-href="./add_cart/#{ product.id }/" class="btn btn-sm btn-success">+</a>
<a t-attf-href="./add_cart/?product_id=#{ product.id }" class="btn btn-sm btn-success">+</a>
</div>
</td>
</tr>

View File

@ -19,6 +19,7 @@
#
##############################################################################
from openerp import SUPERUSER_ID
from openerp.osv import osv, fields
@ -36,9 +37,6 @@ class product_template(osv.osv):
'suggested_product_id': fields.many2one('product.product', 'Suggested For Product'),
'suggested_product_ids': fields.one2many('product.product', 'suggested_product_id', 'Suggested Products'),
}
_defaults = {
'website_published': lambda *args: True
}
def recommended_products(self, cr, uid, ids, context=None):
id = ids[0]
@ -78,3 +76,15 @@ class sale_order(osv.osv):
order = self.browse(cr, uid, ids[0], context=context)
return sum(l.product_uom_qty for l in (order.order_line or []))
class sale_order_line(osv.osv):
_inherit = "sale.order.line"
def _recalculate_product_values(self, cr, uid, ids, product_id=None, context=None):
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
return self.product_id_change(cr, uid, [],
pricelist=context.pop('pricelist'),
product=product_id,
partner_id=user_obj.browse(cr, SUPERUSER_ID, uid).partner_id.id,
context=context)['value']