# How to specify a custom shipping cost from sale

**URL:** https://discuss.tryton.org/t/how-to-specify-a-custom-shipping-cost-from-sale/8632
**Category:** User
**Tags:** stock, sales
**Created:** [June 4, 2025, 4:47am UTC](https://discuss.tryton.org/t/how-to-specify-a-custom-shipping-cost-from-sale/8632 "2025-06-04T04:47:22Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![dotbit](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/dotbit/32/2093_2.png) [@dotbit](https://discuss.tryton.org/u/dotbit)
#### Post date: [June 4, 2025, 4:47am UTC](https://discuss.tryton.org/t/how-to-specify-a-custom-shipping-cost-from-sale/8632/1 "2025-06-04T04:47:22Z")

</div>

Sometimes I need to use a custom shipping cost for a sale.  
When I manually add the shipping product line and quote the sale,  
then a second line is added with the shipping product.

How I do it at the moment:

1. Quote the sale
2. Get the shipping cost line added automatically with the wrong price or 0
3. Go back to draft
4. Edit the shipping cost line added automatically
5. Quote again
6. Now the shipping cost is right.

But as I have sale amendments added, I get all the sales with a useless revision.

I think there must be a better way.

---

<div class="post-metadata">

### Author: ![maxx](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/maxx/32/2320_2.png) [@maxx](https://discuss.tryton.org/u/maxx)
#### Post date: [June 4, 2025, 6:51am UTC](https://discuss.tryton.org/t/how-to-specify-a-custom-shipping-cost-from-sale/8632/2 "2025-06-04T06:51:58Z")

</div>

We had also such problem. So we defined a new field shipment\_cost on sale.

 ![image](https://discuss-cdn.tryton.org/uploads/default/original/2X/0/0b8850102ec3e90806844c5d3f71f088d53c387d.png)

and we customize method “compute\_shipment\_cost”:

```auto
    def compute_shipment_cost(self, carrier):
        cost = super().compute_shipment_cost(carrier)
        if self.shipment_cost_method is None:
            cost = None
        if self.shipment_cost_method == 'shipment':
            cost = 0
        if self.shipment_cost_method == 'order':
            if carrier == self.carrier:
                cost = self.shipment_cost
        if self.carriages:
            for carriage in self.carriages:
                if carriage.carrier == carrier:
                    if carriage.cost_method is None:
                        cost = None
                    if carriage.cost_method == 'shipment':
                        cost = 0
                    if carriage.cost_method == 'order':
                        cost = carriage.shipment_cost
        return cost

```

---

<div class="post-metadata">

### Author: ![dotbit](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/dotbit/32/2093_2.png) [@dotbit](https://discuss.tryton.org/u/dotbit)
#### Post date: [June 5, 2025, 6:01am UTC](https://discuss.tryton.org/t/how-to-specify-a-custom-shipping-cost-from-sale/8632/3 "2025-06-05T06:01:35Z")

</div>

Thank you @maxx, I will use your solution.  
Then again maybe my question is wrong: maybe the right solution is to use shipment\_cost\_method = None and add the shipping product manually…

---

<div class="post-metadata">

### Author: ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)
#### Post date: [June 6, 2025, 6:02am UTC](https://discuss.tryton.org/t/how-to-specify-a-custom-shipping-cost-from-sale/8632/4 "2025-06-06T06:02:16Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
