From 1bd871f852e2a5d09c1529d10699fb5d235e956b Mon Sep 17 00:00:00 2001
From: Ahmad Khanalizadeh <khah@odoo.com>
Date: Thu, 11 May 2023 09:31:45 +0000
Subject: [PATCH] [FIX] delivery: exclude service lines from commodities

Steps to reproduce:
configure easypost for international shipping (e.g. using USPS)
Make a sale order for a customer in another country
Add a discount program (e.g. 10% off)
Attempt to add shipping and get the rates
Get traceback:
`Easypost returned an error: Wrong parameter type.
- value: must be greater than or equal to 0`

To fix this we need to exclude service type products when creating
commodities from order lines (similar to creating commodities from
stock move lines)

opw-3269467

closes odoo/odoo#121123

Signed-off-by: Tiffany Chang <tic@odoo.com>
---
 addons/delivery/models/delivery_carrier.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/addons/delivery/models/delivery_carrier.py b/addons/delivery/models/delivery_carrier.py
index 2bd68d4564d3..a11450ed9933 100644
--- a/addons/delivery/models/delivery_carrier.py
+++ b/addons/delivery/models/delivery_carrier.py
@@ -386,7 +386,7 @@ class DeliveryCarrier(models.Model):
     def _get_commodities_from_order(self, order):
         commodities = []
 
-        for line in order.order_line.filtered(lambda line: not line.is_delivery and not line.display_type):
+        for line in order.order_line.filtered(lambda line: not line.is_delivery and not line.display_type and line.product_id.type in ['product', 'consu']):
             unit_quantity = line.product_uom._compute_quantity(line.product_uom_qty, line.product_id.uom_id)
             rounded_qty = max(1, float_round(unit_quantity, precision_digits=0))
             country_of_origin = line.product_id.country_of_origin.code or order.warehouse_id.partner_id.country_id.code
-- 
GitLab