Ir al contenido
Menú
Se marcó esta pregunta

Hello,

i am using Fedex as Shipping carrier in ODOO14. Fedex has different services and prices are different. I am trying to write a phyton code when you click on Delivery order to check the shipping rates for all Fedex Service set-up and choose the cheapest one.

The same you can do manually if you click on a Sales order the "Add Shipment" button and then "Get Rate".


I have written this phython code. But it does not work at all. I am not sure which function is used when you click on the button 'Get Rate' on the Sales order. So it's more a guess:


def find_cheapest_fedex(self, order):

fedex_carriers = self.env['delivery.carrier'].search([('delivery_type', '=', 'fedex')])

cheapest_rate = float('inf')

cheapest_carrier = None


for carrier in fedex_carriers:

result = carrier.rate_shipment(order)

if result['success']:

price = result['price']

if price < cheapest_rate:

cheapest_rate = price

cheapest_carrier = carrier


if cheapest_carrier:

order.write({

'carrier_id': cheapest_carrier.id,

'delivery_price': cheapest_rate,

})

return True

else:

return False # or handle this case as appropriate for your needs


Thanks for any help,

Dan


Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
nov 20
4281
2
may 25
899
0
feb 24
1067
2
sept 23
1544
1
may 23
1891