[FIX] website_sale_delivery: avoid displaying or choosing non available delivery methods for torder

bzr revid: dle@openerp.com-20140402114815-b42pvgk914r0at1d
This commit is contained in:
Denis Ledoux
2014-04-02 13:48:15 +02:00
parent f22169ebfb
commit 166c4d2751
3 changed files with 18 additions and 2 deletions
@@ -10,10 +10,11 @@ class Ecommerce(Ecommerce):
@http.route(['/shop/payment/'], type='http', auth="public", website=True, multilang=True)
def payment(self, **post):
cr, uid, context = request.cr, request.uid, request.context
carrier_obj = request.registry.get('delivery.carrier')
order = self.get_order()
carrier_id = post.get('carrier_id')
if order and carrier_id:
if order and carrier_id or not carrier_obj.grid_get(cr, uid, [order.carrier_id.id], order.partner_shipping_id.id):
# recompute delivery costs
request.registry['website']._check_carrier_quotation(cr,uid,order,carrier_id,context=context)
return request.redirect("/shop/payment/")
@@ -69,6 +69,14 @@ class SaleOrder(orm.Model):
delivery_ctx = dict(context, order_id=order.id)
DeliveryCarrier = self.pool.get('delivery.carrier')
carrier_obj = self.pool.get('delivery.carrier')
delivery_ids = DeliveryCarrier.search(cr, uid, [('website_published','=',True)], context=context)
# Following loop is done to avoid displaying delivery methods who are not available for this order
# This can surely be done in a more efficient way, but at the moment, it mimics the way it's
# done in delivery_set method of sale.py, from delivery module
for delivery_id in delivery_ids:
grid_id = carrier_obj.grid_get(cr, uid, [delivery_id], order.partner_shipping_id.id)
if not grid_id:
delivery_ids.remove(delivery_id)
values['deliveries'] = DeliveryCarrier.browse(cr, SUPERUSER_ID, delivery_ids, context=delivery_ctx)
return values
@@ -21,6 +21,7 @@ class Website(orm.Model):
def _check_carrier_quotation(self, cr, uid, order, force_carrier_id=None, context=None):
# check to add or remove carrier_id
carrier_obj = self.pool.get('delivery.carrier')
carrier_id = False
for line in order.website_order_line:
if line.product_id.type != "service":
@@ -36,7 +37,13 @@ class Website(orm.Model):
self.pool['sale.order']._delivery_unset(cr, SUPERUSER_ID, order, context=context)
carrier_ids = self.pool.get('delivery.carrier').search(cr, uid, [('website_published','=',True)], context=context)
carrier_id = force_carrier_id or (carrier_ids and carrier_ids[0])
if force_carrier_id:
carrier_ids.insert(0, force_carrier_id)
for delivery_id in set(carrier_ids):
grid_id = carrier_obj.grid_get(cr, uid, [delivery_id], order.partner_shipping_id.id)
if grid_id:
carrier_id = delivery_id
break
order.write({'carrier_id': carrier_id}, context=context)
#If carrier_id have no grid, we don't have delivery !
if carrier_id: