[FIX] Recompute price at each updates of cart, Fix bug with carrier at payment.
bzr revid: jke@openerp.com-20140130173705-wevz607c5djid9ux
This commit is contained in:
parent
76b74e16c2
commit
420e819b1f
|
@ -110,11 +110,11 @@ class delivery_carrier(osv.osv):
|
|||
|
||||
# not using advanced pricing per destination: override grid
|
||||
grid_id = grid_pool.search(cr, uid, [('carrier_id', '=', record.id)], context=context)
|
||||
|
||||
if grid_id and not (record.normal_price or record.free_if_more_than):
|
||||
grid_pool.unlink(cr, uid, grid_id, context=context)
|
||||
|
||||
if not (record.normal_price or record.free_if_more_than):
|
||||
# Check that float, else 0.0 is False
|
||||
if not (isinstance(record.normal_price,float) or record.free_if_more_than):
|
||||
continue
|
||||
|
||||
if not grid_id:
|
||||
|
@ -141,7 +141,7 @@ class delivery_carrier(osv.osv):
|
|||
'list_price': 0.0,
|
||||
}
|
||||
grid_line_pool.create(cr, uid, line_data, context=context)
|
||||
if record.normal_price:
|
||||
if isinstance(record.normal_price,float):
|
||||
line_data = {
|
||||
'grid_id': grid_id and grid_id[0],
|
||||
'name': _('Default price'),
|
||||
|
@ -204,10 +204,9 @@ class delivery_grid(osv.osv):
|
|||
def get_price_from_picking(self, cr, uid, id, total, weight, volume, context=None):
|
||||
grid = self.browse(cr, uid, id, context=context)
|
||||
price = 0.0
|
||||
ok = False
|
||||
|
||||
ok = False
|
||||
price_dict = {'price': total, 'volume':volume, 'weight': weight, 'wv':volume*weight}
|
||||
for line in grid.line_ids:
|
||||
price_dict = {'price': total, 'volume':volume, 'weight': weight, 'wv':volume*weight}
|
||||
test = eval(line.type+line.operator+str(line.max_value), price_dict)
|
||||
if test:
|
||||
if line.price_type=='variable':
|
||||
|
@ -216,7 +215,7 @@ class delivery_grid(osv.osv):
|
|||
price = line.list_price
|
||||
ok = True
|
||||
break
|
||||
if not ok:
|
||||
if not ok:
|
||||
raise osv.except_osv(_('No price available!'), _('No line matched this product or order in the chosen delivery grid.'))
|
||||
|
||||
return price
|
||||
|
|
|
@ -13,11 +13,10 @@ class Ecommerce(Ecommerce):
|
|||
order = self.get_order()
|
||||
|
||||
carrier_id = post.get('carrier_id')
|
||||
|
||||
if order and carrier_id:
|
||||
# recompute delivery costs
|
||||
SaleOrder = request.registry['sale.order']
|
||||
SaleOrder.write(cr, SUPERUSER_ID, [order.id], {'carrier_id': carrier_id}, context=context)
|
||||
SaleOrder.delivery_set(cr, SUPERUSER_ID, [order.id], context=context)
|
||||
# recompute delivery costs
|
||||
request.registry['website']._check_carrier_quotation(cr,uid,order,carrier_id,context=context)
|
||||
return request.redirect("/shop/payment/")
|
||||
|
||||
res = super(Ecommerce, self).payment(**post)
|
||||
|
|
|
@ -19,17 +19,17 @@ class delivery_carrier(orm.Model):
|
|||
class SaleOrder(orm.Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
def _amount_all_wrapper(self, cr, uid, ids, field_name, arg, context=None):
|
||||
def _amount_all_wrapper(self, cr, uid, ids, field_name, arg, context=None):
|
||||
""" Wrapper because of direct method passing as parameter for function fields """
|
||||
return self._amount_all(cr, uid, ids, field_name, arg, context=context)
|
||||
|
||||
def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = super(SaleOrder, self)._amount_all(cr, uid, ids, field_name, arg, context=context)
|
||||
Currency = self.pool.get('res.currency')
|
||||
currency_pool = self.pool.get('res.currency')
|
||||
for order in self.browse(cr, uid, ids, context=context):
|
||||
line_amount = sum([line.price_subtotal for line in order.order_line if line.is_delivery])
|
||||
currency = order.pricelist_id.currency_id
|
||||
res[order.id]['amount_delivery'] = Currency.round(cr, uid, currency, line_amount)
|
||||
res[order.id]['amount_delivery'] = currency_pool.round(cr, uid, currency, line_amount)
|
||||
return res
|
||||
|
||||
def _get_order(self, cr, uid, ids, context=None):
|
||||
|
@ -62,7 +62,6 @@ class SaleOrder(orm.Model):
|
|||
def _get_website_data(self, cr, uid, order, context=None):
|
||||
""" Override to add delivery-related website data. """
|
||||
values = super(SaleOrder, self)._get_website_data(cr, uid, order, context=context)
|
||||
|
||||
# We need a delivery only if we have stockable products
|
||||
has_stockable_products = False
|
||||
for line in order.order_line:
|
||||
|
|
|
@ -9,7 +9,7 @@ class Website(orm.Model):
|
|||
def _ecommerce_create_quotation(self, cr, uid, context=None):
|
||||
order_id = super(Website, self)._ecommerce_create_quotation(cr, uid, context=context)
|
||||
order = self.pool['sale.order'].browse(cr, SUPERUSER_ID, order_id, context=context)
|
||||
self._check_carrier_quotation(cr, uid, order, context=context)
|
||||
self._check_carrier_quotation(cr, uid, order, force_carrier_id=None, context=context)
|
||||
return order_id
|
||||
|
||||
def _ecommerce_add_product_to_cart(self, cr, uid, product_id=0, order_line_id=0, number=1, set_number=-1, context=None):
|
||||
|
@ -17,9 +17,9 @@ class Website(orm.Model):
|
|||
product_id=product_id, order_line_id=order_line_id, number=number, set_number=set_number,
|
||||
context=context)
|
||||
order = self.ecommerce_get_current_order(cr, uid, context=context)
|
||||
return self._check_carrier_quotation(cr, uid, order, context=context) and quantity or None
|
||||
|
||||
def _check_carrier_quotation(self, cr, uid, order, context=None):
|
||||
return self._check_carrier_quotation(cr, uid, order, force_carrier_id=None, context=context) and quantity or None
|
||||
|
||||
def _check_carrier_quotation(self, cr, uid, order, force_carrier_id=None, context=None):
|
||||
# check to add or remove carrier_id
|
||||
carrier_id = False
|
||||
for line in order.website_order_line:
|
||||
|
@ -31,10 +31,14 @@ class Website(orm.Model):
|
|||
order.write({'carrier_id': None}, context=context)
|
||||
self.pool['sale.order']._delivery_unset(cr, SUPERUSER_ID, order, context=context)
|
||||
return True
|
||||
elif not order.carrier_id:
|
||||
else:
|
||||
if order.carrier_id:
|
||||
self.pool['sale.order']._delivery_unset(cr, SUPERUSER_ID, order, context=context)
|
||||
|
||||
carrier_ids = self.pool.get('delivery.carrier').search(cr, uid, [], context=context)
|
||||
carrier_id = carrier_ids and carrier_ids[0]
|
||||
carrier_id = force_carrier_id or (carrier_ids and carrier_ids[0])
|
||||
order.write({'carrier_id': carrier_id}, context=context)
|
||||
#If carrier_id have no grid, we don't have delivery !
|
||||
if carrier_id:
|
||||
order.delivery_set(context=context)
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue