[FIX] website_sale: update total when the user change a product quantity

bzr revid: chm@openerp.com-20131105132747-figm8j11d6ul1v0k
This commit is contained in:
Christophe Matthieu
2013-11-05 14:27:47 +01:00
parent 15d4a0c1e2
commit 7f5a60f13c
3 changed files with 26 additions and 11 deletions
+6 -3
View File
@@ -451,8 +451,7 @@ class Ecommerce(http.Controller):
else:
order_line_id = order_line_obj.create(request.cr, SUPERUSER_ID, values, context=request.context)
order_obj.write(request.cr, SUPERUSER_ID, [order.id], {'order_line': [(4, order_line_id)]}, context=request.context)
return [quantity, order.get_total_quantity()]
return quantity
@website.route(['/shop/mycart/'], type='http', auth="public", multilang=True)
def mycart(self, **post):
@@ -492,7 +491,11 @@ class Ecommerce(http.Controller):
@website.route(['/shop/add_cart_json/'], type='json', auth="public")
def add_cart_json(self, product_id=None, order_line_id=None, remove=None):
return self.add_product_to_cart(product_id=product_id, order_line_id=order_line_id, number=(remove and -1 or 1))
quantity = self.add_product_to_cart(product_id=product_id, order_line_id=order_line_id, number=(remove and -1 or 1))
order = get_current_order()
return [quantity, order.get_total_quantity(), order.amount_total, request.website.render("website_sale.total", {
'website_sale_order': order
}).strip()]
@website.route(['/shop/set_cart_json/'], type='json', auth="public")
def set_cart_json(self, path=None, product_id=None, order_line_id=None, set_number=0, json=None):
@@ -43,13 +43,21 @@ $(document).ready(function () {
var $link = $(ev.currentTarget);
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/"]')})
if (!product) {
var line = $link.attr("href").match(/order_line_id=([0-9]+)/);
order_line_id = line ? +line[1] : 0;
}
openerp.jsonRpc("/shop/add_cart_json/", 'call', {
'product_id': product_id,
'order_line_id': order_line_id,
'remove': $link.is('[href*="remove"]')})
.then(function (data) {
if (!data[0]) {
location.reload();
}
set_my_cart_quantity(data[1]);
$link.parents(".input-group:first").find(".js_quantity").val(data[0]);
$('[data-oe-model="sale.order"][data-oe-field="amount_total"]').replaceWith(data[3]);
});
return false;
});
+11 -7
View File
@@ -420,14 +420,14 @@
<td>
<div class="input-group">
<span class="input-group-addon">
<a t-href="./remove_cart/?order_line_id=#{ line.id }" t-att-data-id="line.id" class="mb8 js_add_cart_json">
<a t-href="./add_cart/?remove=True&amp;order_line_id=#{ line.id }" class="mb8 js_add_cart_json">
<span class="icon-minus"/>
</a>
</span>
<input type="text" class="js_quantity form-control"
t-att-data-id="line.id" t-att-value="int(line.product_uom_qty)"/>
<span class="input-group-addon">
<a t-href="./add_cart/?order_line_id=#{ line.id }" t-att-data-id="line.id" class="mb8 float_left js_add_cart_json">
<a t-href="./add_cart/?order_line_id=#{ line.id }" class="mb8 float_left js_add_cart_json">
<span class="icon-plus"/>
</a>
</span>
@@ -445,11 +445,8 @@
<thead>
<tr style="border-top: 1px solid #000">
<th><h3>Total:</h3></th>
<th class="text-right"><h3>
<span t-field="website_sale_order.amount_total" t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
}'/></h3>
<th class="text-right">
<h3><t t-call="website_sale.total"/></h3>
</th>
</tr>
<tr class="text-muted">
@@ -878,5 +875,12 @@
</t>
</template>
<template id="total">
<span t-field="website_sale_order.amount_total" t-field-options='{
"widget": "monetary",
"display_currency": "website.pricelist_id.currency_id"
}'/>
</template>
</data>
</openerp>