콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

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


아바타
취소
관련 게시물 답글 화면 활동
1
11월 20
4423
2
5월 25
1087
0
2월 24
1206
2
9월 23
1732
1
5월 23
2044