@@ -262,9 +262,48 @@ def available_carriers(self, partner):
262262 sendcloud_carriers = without_service_point + enabled_service_point
263263
264264 return (sendcloud_carriers + other_carriers ).sorted (
265- key = lambda carrier : carrier . name
265+ key = lambda avl_carrier : ( avl_carrier . sequence , avl_carrier . id )
266266 )
267267
268+ def _is_available_for_order (self , order ):
269+ res = super ()._is_available_for_order (order )
270+ if self .delivery_type == "sendcloud" :
271+ if self .sendcloud_is_return :
272+ return False
273+ weight = order .sendcloud_order_weight
274+ if not (self .sendcloud_min_weight <= weight <= self .sendcloud_max_weight ):
275+ return False
276+ if (
277+ self .sendcloud_service_point_input == "required"
278+ and self .sendcloud_integration_id .service_point_enabled
279+ ):
280+ carrier_names = self .sendcloud_integration_id .service_point_carriers
281+ current_carrier = self .sendcloud_carrier
282+ if not (
283+ current_carrier
284+ and current_carrier in safe_eval (carrier_names )
285+ or False
286+ ):
287+ return False
288+ warehouse = order .warehouse_id
289+ if not warehouse .sencloud_sender_address_id :
290+ # use standard server address
291+ sender_address = self ._get_default_sender_address_per_company (
292+ warehouse .company_id .id
293+ )
294+ else :
295+ sender_address = warehouse .sencloud_sender_address_id
296+ countries = self .env ["sendcloud.shipping.method.country" ].search (
297+ [
298+ ("company_id" , "=" , order .company_id .id ),
299+ ("from_iso_2" , "=" , sender_address .country ),
300+ ("iso_2" , "=" , order .partner_shipping_id .country_id .code ),
301+ ]
302+ )
303+ if self .sendcloud_code not in countries .mapped ("method_code" ):
304+ return False
305+ return res
306+
268307 # ----------------- #
269308 # Sendcloud methods #
270309 # ----------------- #
@@ -292,9 +331,12 @@ def _sendcloud_get_price_per_country(self, country_code):
292331 if force_update :
293332 integration = self .company_id .sendcloud_default_integration_id
294333 self ._update_sendcloud_delivery_carrier (integration )
334+ sendcloud_shipping_method_country_obj = self .env [
335+ "sendcloud.shipping.method.country"
336+ ]
295337 if self .sendcloud_price :
296- return self .sendcloud_price
297- shipping_method_country = self . env [ "sendcloud.shipping.method.country" ] .search (
338+ return self .sendcloud_price , sendcloud_shipping_method_country_obj
339+ shipping_method_country = sendcloud_shipping_method_country_obj .search (
298340 [
299341 ("iso_2" , "=" , country_code ),
300342 ("company_id" , "=" , self .company_id .id ),
0 commit comments