[IMP] website_sale: context, routes
bzr revid: chm@openerp.com-20131002071239-4glhz7g8iz1r9gea
This commit is contained in:
parent
8da11482c4
commit
d2a743cbde
|
@ -825,7 +825,7 @@
|
||||||
editor.on('start', self, function (o) {o.url = bg_value;});
|
editor.on('start', self, function (o) {o.url = bg_value;});
|
||||||
editor.on('save', self, function (o) {
|
editor.on('save', self, function (o) {
|
||||||
var $bg = typeof bg == 'string' ? self.$target.find(bg) : $(bg);
|
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'));
|
editor.appendTo($('body'));
|
||||||
}
|
}
|
||||||
|
@ -834,13 +834,13 @@
|
||||||
if ($(this).data("value")) {
|
if ($(this).data("value")) {
|
||||||
var src = $(this).data("value");
|
var src = $(this).data("value");
|
||||||
var $bg = typeof bg == 'string' ? self.$target.find(bg) : $(bg);
|
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) {
|
.on('mouseout', function (event) {
|
||||||
var src = $ul.find('li.active').data("value");
|
var src = $ul.find('li.active').data("value");
|
||||||
var $bg = typeof bg == 'string' ? self.$target.find(bg) : $(bg);
|
var $bg = typeof bg == 'string' ? self.$target.find(bg) : $(bg);
|
||||||
$bg.css("background-image", "url('" + src + "')");
|
$bg.css("background-image", "url(" + src + ")");
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -64,7 +64,7 @@ class event(osv.osv):
|
||||||
class sale_order_line(osv.osv):
|
class sale_order_line(osv.osv):
|
||||||
_inherit = "sale.order.line"
|
_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:
|
if not ids:
|
||||||
return super(sale_order_line, self)._recalculate_product_values(cr, uid, ids, product_id, context=context)
|
return super(sale_order_line, self)._recalculate_product_values(cr, uid, ids, product_id, context=context)
|
||||||
|
|
||||||
|
|
|
@ -12,19 +12,19 @@ def get_order(order_id=None):
|
||||||
# check if order allready exists
|
# check if order allready exists
|
||||||
if order_id:
|
if order_id:
|
||||||
try:
|
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
|
order.pricelist_id
|
||||||
except:
|
except:
|
||||||
order_id = None
|
order_id = None
|
||||||
if not order_id:
|
if not order_id:
|
||||||
fields = [k for k, v in order_obj._columns.items()]
|
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'):
|
if request.httprequest.session.get('ecommerce_pricelist'):
|
||||||
order_value['pricelist_id'] = request.httprequest.session['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_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_id = order_obj.create(request.cr, SUPERUSER_ID, order_value, context=request.context)
|
||||||
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)
|
||||||
request.httprequest.session['ecommerce_order_id'] = order.id
|
request.httprequest.session['ecommerce_order_id'] = order.id
|
||||||
|
|
||||||
return order_obj.browse(request.cr, SUPERUSER_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)
|
return request.website.render("website_sale.products", values)
|
||||||
|
|
||||||
@website.route(['/shop/product/<product_id>/'], type='http', auth="public", multilang=True)
|
@website.route(['/shop/product/<int:product_id>/'], type='http', auth="public", multilang=True)
|
||||||
def product(self, cat_id=0, product_id=0, **post):
|
def product(self, cat_id=0, product_id=0, **post):
|
||||||
|
|
||||||
if 'promo' in post:
|
if 'promo' in post:
|
||||||
self.change_pricelist(post.get('promo'))
|
self.change_pricelist(post.get('promo'))
|
||||||
|
|
||||||
product_id = product_id and int(product_id) or 0
|
|
||||||
product_obj = request.registry.get('product.template')
|
product_obj = request.registry.get('product.template')
|
||||||
category_obj = request.registry.get('product.public.category')
|
category_obj = request.registry.get('product.public.category')
|
||||||
|
|
||||||
category_ids = category_obj.search(request.cr, request.uid, [(1, '=', 1)], context=request.context)
|
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])
|
category_list = sorted(category_list, key=lambda category: category[1])
|
||||||
|
|
||||||
request.context['pricelist'] = self.get_pricelist()
|
|
||||||
|
|
||||||
category = None
|
category = None
|
||||||
if post.get('category_id') and int(post.get('category_id')):
|
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)
|
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)
|
product = product_obj.browse(request.cr, request.uid, product_id, context=request.context)
|
||||||
|
|
||||||
values = {
|
values = {
|
||||||
|
@ -282,7 +280,7 @@ class Ecommerce(http.Controller):
|
||||||
}
|
}
|
||||||
return request.website.render("website_sale.product", values)
|
return request.website.render("website_sale.product", values)
|
||||||
|
|
||||||
@website.route(['/shop/add_product/', '/shop/category/<cat_id>/add_product/'], type='http', auth="public", multilang=True)
|
@website.route(['/shop/add_product/', '/shop/category/<int:cat_id>/add_product/'], type='http', auth="public", multilang=True)
|
||||||
def add_product(self, cat_id=0, **post):
|
def add_product(self, cat_id=0, **post):
|
||||||
product_id = request.registry.get('product.product').create(request.cr, request.uid,
|
product_id = request.registry.get('product.product').create(request.cr, request.uid,
|
||||||
{'name': 'New Product', 'public_categ_id': cat_id}, request.context)
|
{'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):
|
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')
|
order_line_obj = request.registry.get('sale.order.line')
|
||||||
|
|
||||||
product_id = product_id and int(product_id) or 0
|
|
||||||
|
|
||||||
order = get_current_order()
|
order = get_current_order()
|
||||||
if not order:
|
if not order:
|
||||||
order = get_order()
|
order = get_order()
|
||||||
|
|
||||||
context = dict(request.context, pricelist=self.get_pricelist())
|
request.context = dict(request.context, pricelist=self.get_pricelist())
|
||||||
|
|
||||||
quantity = 0
|
quantity = 0
|
||||||
|
|
||||||
|
@ -339,9 +335,9 @@ class Ecommerce(http.Controller):
|
||||||
else:
|
else:
|
||||||
domain += [('product_id', '=', product_id)]
|
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:
|
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:
|
if not product_id:
|
||||||
product_id = order_line['product_id'][0]
|
product_id = order_line['product_id'][0]
|
||||||
if set_number >= 0:
|
if set_number >= 0:
|
||||||
|
@ -352,11 +348,11 @@ class Ecommerce(http.Controller):
|
||||||
quantity = 0
|
quantity = 0
|
||||||
else:
|
else:
|
||||||
fields = [k for k, v in order_line_obj._columns.items()]
|
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
|
quantity = 1
|
||||||
|
|
||||||
# change and record value
|
# 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.update(vals)
|
||||||
|
|
||||||
values['product_uom_qty'] = quantity
|
values['product_uom_qty'] = quantity
|
||||||
|
@ -364,13 +360,13 @@ class Ecommerce(http.Controller):
|
||||||
values['order_id'] = order.id
|
values['order_id'] = order.id
|
||||||
|
|
||||||
if order_line_ids:
|
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:
|
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:
|
else:
|
||||||
#values['name'] = "website order"
|
#values['name'] = "website order"
|
||||||
order_line_id = order_line_obj.create(request.cr, SUPERUSER_ID, values, 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=context)
|
order.write({'order_line': [(4, order_line_id)]}, context=request.context)
|
||||||
|
|
||||||
return [quantity, order.get_total_quantity()]
|
return [quantity, order.get_total_quantity()]
|
||||||
|
|
||||||
|
@ -403,7 +399,7 @@ class Ecommerce(http.Controller):
|
||||||
|
|
||||||
@website.route(['/shop/<path:path>/add_cart/', '/shop/add_cart/'], type='http', auth="public", multilang=True)
|
@website.route(['/shop/<path:path>/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):
|
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/")
|
return request.redirect("/shop/mycart/")
|
||||||
|
|
||||||
@website.route(['/shop/add_cart_json/'], type='json', auth="public")
|
@website.route(['/shop/add_cart_json/'], type='json', auth="public")
|
||||||
|
@ -569,14 +565,14 @@ class Ecommerce(http.Controller):
|
||||||
def change_sequence(self, id, top):
|
def change_sequence(self, id, top):
|
||||||
product_obj = request.registry.get('product.template')
|
product_obj = request.registry.get('product.template')
|
||||||
if top:
|
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:
|
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")
|
@website.route(['/shop/change_styles/'], type='json', auth="public")
|
||||||
def change_styles(self, id, style_id):
|
def change_styles(self, id, style_id):
|
||||||
product_obj = request.registry.get('product.template')
|
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 = []
|
remove = []
|
||||||
active = False
|
active = False
|
||||||
|
@ -586,14 +582,11 @@ class Ecommerce(http.Controller):
|
||||||
active = True
|
active = True
|
||||||
break
|
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:
|
if remove:
|
||||||
print "remove", remove
|
|
||||||
product.write({'website_style_ids': [(3, rid) for rid in remove]})
|
product.write({'website_style_ids': [(3, rid) for rid in remove]})
|
||||||
|
|
||||||
if not active:
|
if not active:
|
||||||
print "add", style.id
|
|
||||||
product.write({'website_style_ids': [(4, style.id)]})
|
product.write({'website_style_ids': [(4, style.id)]})
|
||||||
|
|
||||||
return not active
|
return not active
|
||||||
|
@ -601,7 +594,7 @@ class Ecommerce(http.Controller):
|
||||||
@website.route(['/shop/change_size/'], type='json', auth="public")
|
@website.route(['/shop/change_size/'], type='json', auth="public")
|
||||||
def change_size(self, id, x, y):
|
def change_size(self, id, x, y):
|
||||||
product_obj = request.registry.get('product.template')
|
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})
|
return product.write({'website_size_x': x, 'website_size_y': y})
|
||||||
|
|
||||||
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|
|
@ -36,20 +36,18 @@ $(document).ready(function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
// hack to add and rome from cart with json
|
// 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();
|
ev.preventDefault();
|
||||||
var $link = $(ev.currentTarget);
|
var $link = $(ev.currentTarget);
|
||||||
var product_id = $link.attr("href").match(/product_id=([0-9]+)/)[1];
|
var product = $link.attr("href").match(/product_id=([0-9]+)/);
|
||||||
if (product_id) {
|
var product_id = product ? +product[1] : 0;
|
||||||
product_id = +product_id;
|
|
||||||
}
|
|
||||||
openerp.jsonRpc("/shop/add_cart_json/", 'call', {'product_id': product_id, 'order_line_id': $link.data('id'), 'remove': $link.is('[href*="/remove_cart/"]')})
|
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) {
|
.then(function (data) {
|
||||||
if (!data[0]) {
|
if (!data[0]) {
|
||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
set_my_cart_quantity(data[1]);
|
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;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
|
@ -313,14 +313,16 @@
|
||||||
</label>
|
</label>
|
||||||
<br/>
|
<br/>
|
||||||
</t>
|
</t>
|
||||||
<div>
|
|
||||||
<t t-if="product.product_variant_ids[0].lst_price != product.product_variant_ids[0].price">
|
<div class="product_price">
|
||||||
<h5 class="text-danger" style="text-decoration: line-through;" title="Price without reduction"><span t-field="product.product_variant_ids[0].lst_price" /> €</h5>
|
<b>
|
||||||
<h4><t t-esc="product.product_variant_ids[0].price" /> €</h4>
|
<t t-if="product.product_variant_ids[0].lst_price != product.product_variant_ids[0].price">
|
||||||
</t>
|
<span class="text-danger" style="text-decoration: line-through;">
|
||||||
<h4 t-if="product.product_variant_ids[0].lst_price == product.product_variant_ids[0].price">
|
<t t-esc="product.product_variant_ids[0].lst_price" /> €
|
||||||
<b><span t-field="product.product_variant_ids[0].lst_price" /> €</b>
|
</span>&nbsp;
|
||||||
</h4>
|
</t>
|
||||||
|
<h4><b><t t-esc="product.product_variant_ids[0].price" /> €</b></h4>
|
||||||
|
</b>
|
||||||
</div>
|
</div>
|
||||||
<button class="btn btn-primary btn-lg mt8">Add to Cart</button>
|
<button class="btn btn-primary btn-lg mt8">Add to Cart</button>
|
||||||
<hr t-if="product.description_sale"/>
|
<hr t-if="product.description_sale"/>
|
||||||
|
@ -427,14 +429,14 @@
|
||||||
<td>
|
<td>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<span class="input-group-addon">
|
<span class="input-group-addon">
|
||||||
<a t-href="./add_cart/?order_line_id=#{ line.id }" t-att-data-id="line.id" class="mb8">
|
<a t-href="./remove_cart/?order_line_id=#{ line.id }" t-att-data-id="line.id" class="mb8">
|
||||||
<span class="icon-minus"/>
|
<span class="icon-minus"/>
|
||||||
</a>
|
</a>
|
||||||
</span>
|
</span>
|
||||||
<input type="text" class="js_quantity form-control"
|
<input type="text" class="js_quantity form-control"
|
||||||
t-att-data-id="line.id" t-att-value="int(line.product_uom_qty)"/>
|
t-att-data-id="line.id" t-att-value="int(line.product_uom_qty)"/>
|
||||||
<span class="input-group-addon">
|
<span class="input-group-addon">
|
||||||
<a t-href="./remove_cart/?order_line_id=#{ line.id }" t-att-data-id="line.id" class="mb8 float_left">
|
<a t-href="./add_cart/?order_line_id=#{ line.id }" t-att-data-id="line.id" class="mb8 float_left">
|
||||||
<span class="icon-plus"/>
|
<span class="icon-plus"/>
|
||||||
</a>
|
</a>
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -34,13 +34,15 @@ class sale_order(osv.Model):
|
||||||
class sale_order_line(osv.Model):
|
class sale_order_line(osv.Model):
|
||||||
_inherit = "sale.order.line"
|
_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:
|
if context is None:
|
||||||
context = {}
|
context = {}
|
||||||
user_obj = self.pool.get('res.users')
|
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(
|
return self.product_id_change(
|
||||||
cr, SUPERUSER_ID, [],
|
cr, SUPERUSER_ID, ids,
|
||||||
pricelist=context.pop('pricelist'),
|
pricelist=context.pop('pricelist'),
|
||||||
product=product_id,
|
product=product_id,
|
||||||
partner_id=user_obj.browse(cr, SUPERUSER_ID, uid).partner_id.id,
|
partner_id=user_obj.browse(cr, SUPERUSER_ID, uid).partner_id.id,
|
||||||
|
|
Loading…
Reference in New Issue