[IMP] website_sale: website_sequence with push to top, push up, push down, push to bottom

bzr revid: chm@openerp.com-20140110112442-kmjx97tk6zz5zpwa
This commit is contained in:
Christophe Matthieu 2014-01-10 12:24:42 +01:00
parent 8749e13a75
commit 4998764d40
4 changed files with 51 additions and 7 deletions

View File

@ -780,12 +780,16 @@ class Ecommerce(http.Controller):
return request.website.render("website_sale.confirmation", {'order': order})
@website.route(['/shop/change_sequence/'], type='json', auth="public")
def change_sequence(self, id, top):
def change_sequence(self, id, sequence):
product_obj = request.registry.get('product.template')
if top:
if sequence == "top":
product_obj.set_sequence_top(request.cr, request.uid, [id], context=request.context)
else:
elif sequence == "bottom":
product_obj.set_sequence_bottom(request.cr, request.uid, [id], context=request.context)
elif sequence == "up":
product_obj.set_sequence_up(request.cr, request.uid, [id], context=request.context)
elif sequence == "down":
product_obj.set_sequence_down(request.cr, request.uid, [id], context=request.context)
@website.route(['/shop/change_styles/'], type='json', auth="public")
def change_styles(self, id, style_id):

View File

@ -61,10 +61,16 @@ class product_template(osv.Model):
'website_sequence': fields.integer('Sequence', help="Determine the display order in the Website E-commerce"),
'website_url': fields.function(_website_url, string="Website url", type="char"),
}
def __defaults_website_sequence(self, cr, uid, *kwargs):
cr.execute('SELECT MAX(website_sequence) FROM product_template')
max_sequence = cr.fetchone()[0] or 0
return max_sequence + 1
_defaults = {
'website_size_x': 1,
'website_size_y': 1,
'website_sequence': 1,
'website_sequence': __defaults_website_sequence,
'website_published': False,
}
@ -74,7 +80,31 @@ class product_template(osv.Model):
return self.write(cr, uid, ids, {'website_sequence': max_sequence + 1}, context=context)
def set_sequence_bottom(self, cr, uid, ids, context=None):
return self.write(cr, uid, ids, {'website_sequence': 0}, context=context)
cr.execute('SELECT MIN(website_sequence) FROM product_template')
min_sequence = cr.fetchone()[0] or 0
return self.write(cr, uid, ids, {'website_sequence': min_sequence -1}, context=context)
def set_sequence_up(self, cr, uid, ids, context=None):
product = self.browse(cr, uid, ids[0], context=context)
cr.execute(""" SELECT id, website_sequence FROM product_template
WHERE website_sequence > %s AND website_published = %s ORDER BY website_sequence ASC LIMIT 1""" % (product.website_sequence, product.website_published))
prev = cr.fetchone()
if prev:
self.write(cr, uid, [prev[0]], {'website_sequence': product.website_sequence}, context=context)
return self.write(cr, uid, [ids[0]], {'website_sequence': prev[1]}, context=context)
else:
return self.set_sequence_top(cr, uid, ids, context=context)
def set_sequence_down(self, cr, uid, ids, context=None):
product = self.browse(cr, uid, ids[0], context=context)
cr.execute(""" SELECT id, website_sequence FROM product_template
WHERE website_sequence < %s AND website_published = %s ORDER BY website_sequence DESC LIMIT 1""" % (product.website_sequence, product.website_published))
next = cr.fetchone()
if next:
self.write(cr, uid, [next[0]], {'website_sequence': product.website_sequence}, context=context)
return self.write(cr, uid, [ids[0]], {'website_sequence': next[1]}, context=context)
else:
return self.set_sequence_bottom(cr, uid, ids, context=context)
def recommended_products(self, cr, uid, ids, context=None):
id = ids[0]

View File

@ -25,10 +25,17 @@
location.href = location.href.replace(/(\?|#|$).*/, search + location.hash);
}
$(document).on('click', '.js_options .js_go_to_top,.js_options .js_go_to_bottom', function (event) {
$(document).on('click', '.js_options .js_go_to_top,.js_options .js_go_to_bottom,.js_options .js_go_up,.js_options .js_go_down', function (event) {
var $a = $(event.currentTarget);
var $data = $a.parents(".js_options:first");
openerp.jsonRpc('/shop/change_sequence/', 'call', {'id': $data.data('id'), 'top': $a.hasClass('js_go_to_top')})
var sequence = "top";
if ($a.hasClass('js_go_to_bottom'))
sequence = "bottom";
else if ($a.hasClass('js_go_up'))
sequence = "up";
else if ($a.hasClass('js_go_down'))
sequence = "down";
openerp.jsonRpc('/shop/change_sequence/', 'call', {'id': $data.data('id'), 'sequence': sequence})
.then(reload_enable_editor);
});

View File

@ -166,6 +166,9 @@
<a tabindex="-1" href="#">Promote</a>
<ul class="dropdown-menu" name="sequence">
<li><a href="#" class="js_go_to_top">Push to top</a></li>
<li><a href="#" class="js_go_up">Push up</a>
</li>
<li><a href="#" class="js_go_down">Push down</a></li>
<li><a href="#" class="js_go_to_bottom">Push to bottom</a></li>
</ul>
</li>