Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
1558 Tampilan

Hi,

I want to set up an automated action which automatically runs the "UPDATE SHIPPING COST" function. For some customers, we want to change them to a Shipping Method which is not published (if published, then all customers can choose that on the website).  I have set the correct Apply On and the Action Update Delivery Method. 

So now I am where I can see that when clicking on Update Shipping Cost, it has changed to the defined shipping method from the action. What I am missing is how to apply/update the value on the sales order. 

I have found out how to call server actions, but I can't seem to find the code/actions that are run when you manually click UPDATE SHIPPING COST - Update.

Any help with be highly appreciated, thanks

Avatar
Buang
I am out of office on paternity leave until mid of April. I will respond to your email as soon as possible. 

Your email will not be forwarded, so please contact sales@purifi-audio.com, thank you

Best regards
Morten Halvorsen
Jawaban Terbai

I also need this....Any luck?

Edit:

I used this answer:

https://www.odoo.com/forum/help-1/odoov13-how-to-assign-a-delivery-carrier-object-to-a-sale-order-object-using-orm-179786#

in combination with ChatGPT and have this so far and it seems OK:

```

    # ID of the desired shipping method

    shipping_method_id = 70

    

    # Check if a delivery line with the specified shipping method exists

    delivery_line_exists = any(

        line.product_id.id == env['delivery.carrier'].browse(shipping_method_id).product_id.id

        for line in record.order_line if line.is_delivery

    )

    

    if not delivery_line_exists:

        # Fetch the delivery carrier by its ID

        delivery_carrier = env['delivery.carrier'].browse(shipping_method_id)

        

        if delivery_carrier:

            # Use the set_delivery_line method to add or update the delivery line

            record.set_delivery_line(delivery_carrier, delivery_carrier.rate_shipment(record)['price']) 
```

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
1
Jul 25
875
1
Jul 25
1331
0
Apr 25
759
3
Feb 25
1631
1
Des 24
1826