From 271ab796664a09c86acba4f0ce7c5f64fad11274 Mon Sep 17 00:00:00 2001 From: Richard Mathot Date: Mon, 27 Jul 2015 10:36:44 +0200 Subject: [PATCH] [FIX] delivery: do not always recompute estimated shipping price When a SO is not in draft AND uses an external shipping provider, it does not make sens to re-poll the provider for the price (and this is quite slow) --- addons/delivery/models/sale_order.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/addons/delivery/models/sale_order.py b/addons/delivery/models/sale_order.py index b635ec7d801..753223647e9 100644 --- a/addons/delivery/models/sale_order.py +++ b/addons/delivery/models/sale_order.py @@ -31,7 +31,14 @@ class SaleOrder(models.Model): @api.depends('carrier_id', 'partner_id', 'order_line') def _compute_delivery_price(self): for order in self: - order.delivery_price = order.carrier_id.with_context(order_id=order.id).price + if order.state != 'draft': + # we do not want to recompute the shipping price of an already validated/done SO + continue + elif order.carrier_id.delivery_type != 'grid' and not order.order_line: + # prevent SOAP call to external shipping provider when SO has no lines yet + continue + else: + order.delivery_price = order.carrier_id.with_context(order_id=order.id).price @api.multi def delivery_set(self):