[FIX] website_sale_delivery: avoid selecting unavailable delivery method
If somebody selects a delivery method not matching any criteria, the server would crash (500 for the user). This is due to error raised in get_price_from_picking which is triggered by the function field 'price' on the 'delivery.carrier' object. To avoid this, add field 'available' on the carrier that will be False when no delivery gird is found or when the error is raised. In this case, the delivery choice is disabled. opw 610210
This commit is contained in:
parent
005282014a
commit
36fcfc66c4
|
@ -19,11 +19,14 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
import logging
|
||||
import time
|
||||
from openerp.osv import fields,osv
|
||||
from openerp.tools.translate import _
|
||||
import openerp.addons.decimal_precision as dp
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
class delivery_carrier(osv.osv):
|
||||
_name = "delivery.carrier"
|
||||
_description = "Carrier"
|
||||
|
@ -51,14 +54,24 @@ class delivery_carrier(osv.osv):
|
|||
for carrier in self.browse(cr, uid, ids, context=context):
|
||||
order_id=context.get('order_id',False)
|
||||
price=False
|
||||
available = False
|
||||
if order_id:
|
||||
order = sale_obj.browse(cr, uid, order_id, context=context)
|
||||
carrier_grid=self.grid_get(cr,uid,[carrier.id],order.partner_shipping_id.id,context)
|
||||
if carrier_grid:
|
||||
price=grid_obj.get_price(cr, uid, carrier_grid, order, time.strftime('%Y-%m-%d'), context)
|
||||
try:
|
||||
price=grid_obj.get_price(cr, uid, carrier_grid, order, time.strftime('%Y-%m-%d'), context)
|
||||
available = True
|
||||
except osv.except_osv, e:
|
||||
# no suitable delivery method found, probably configuration error
|
||||
_logger.error("Carrier %s: %s\n%s" % (carrier.name, e.name, e.value))
|
||||
price = 0.0
|
||||
else:
|
||||
price = 0.0
|
||||
res[carrier.id]=price
|
||||
res[carrier.id] = {
|
||||
'price': price,
|
||||
'available': available
|
||||
}
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
|
@ -66,7 +79,9 @@ class delivery_carrier(osv.osv):
|
|||
'partner_id': fields.many2one('res.partner', 'Transport Company', required=True, help="The partner that is doing the delivery service."),
|
||||
'product_id': fields.many2one('product.product', 'Delivery Product', required=True),
|
||||
'grids_id': fields.one2many('delivery.grid', 'carrier_id', 'Delivery Grids'),
|
||||
'price' : fields.function(get_price, string='Price'),
|
||||
'available' : fields.function(get_price, string='Available',type='boolean', multi='price',
|
||||
help="Is the carrier method possible with the current order."),
|
||||
'price' : fields.function(get_price, string='Price', multi='price'),
|
||||
'active': fields.boolean('Active', help="If the active field is set to False, it will allow you to hide the delivery carrier without removing it."),
|
||||
'normal_price': fields.float('Normal Price', help="Keep empty if the pricing depends on the advanced pricing per destination"),
|
||||
'free_if_more_than': fields.boolean('Free If Order Total Amount Is More Than', help="If the order is more expensive than a certain amount, the customer can benefit from a free shipping"),
|
||||
|
|
|
@ -29,13 +29,16 @@
|
|||
<li t-foreach="deliveries" t-as="delivery">
|
||||
<label>
|
||||
<input t-att-value="delivery.id" type="radio" name="delivery_type"
|
||||
t-att-checked="order.carrier_id and order.carrier_id.id == delivery.id and 'checked' or False"/>
|
||||
t-att-checked="order.carrier_id and order.carrier_id.id == delivery.id and 'checked' or False"
|
||||
t-att-disabled="delivery.available and '0' or '1'"/>
|
||||
<span t-field="delivery.name"/>
|
||||
<span class="badge" t-field="delivery.price"
|
||||
t-field-options='{
|
||||
"widget": "monetary",
|
||||
"display_currency": "website.pricelist_id.currency_id"
|
||||
}'/>
|
||||
<t t-if="delivery.available">
|
||||
<span class="badge" t-field="delivery.price"
|
||||
t-field-options='{
|
||||
"widget": "monetary",
|
||||
"display_currency": "website.pricelist_id.currency_id"
|
||||
}'/>
|
||||
</t>
|
||||
</label>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
Loading…
Reference in New Issue