diff --git a/models/customer_purchase_order_importer.py b/models/customer_purchase_order_importer.py
index d605fd509a5f77cb33d0d9b5364ef25dde5f66e5..d7381375e5d0489c9e7304c996ec23252391224c 100644
--- a/models/customer_purchase_order_importer.py
+++ b/models/customer_purchase_order_importer.py
@@ -381,11 +381,18 @@ class CustomerPurchaseOrderImporter(models.Model):
 
     def get_config_units_as_boxes_vals(self, vals):
         for line in vals['pre_order_line_ids']:
+            box_kg = line[2]['box_kg']
             product_uom = line[2]['product_uom']
-            units_per_box = line[2]['units_per_box']['original']
+            ordered_qty = line[2]['ordered_qty']['original']
 
-            if product_uom and product_uom == self.env.ref('uom.product_uom_kgm').id and units_per_box:
-                line[2]['box_qty']['modified'] = units_per_box
+            if (
+                product_uom
+                and product_uom == self.env.ref('uom.product_uom_kgm').id
+                and ordered_qty
+                and box_kg
+            ):
+                box_qty = int(ordered_qty / box_kg)
+                line[2]['box_qty']['modified'] = box_qty if box_qty >= 0 else 0
 
         return vals
 
@@ -452,7 +459,6 @@ class CustomerPurchaseOrderImporter(models.Model):
 
     def get_full_file_data(self, lines):
         msg_list = []
-        address = None
         config_lines = None
         partner = None
         branch = None
@@ -489,8 +495,6 @@ class CustomerPurchaseOrderImporter(models.Model):
                     if product_type_errors:
                         msg_list.extend(product_type_errors)
 
-                    address = partner.address_get(['invoice'])
-
         # Branch
         branch_ean_code = header_data['branch_ean_code']
         if not branch_ean_code:
@@ -751,7 +755,7 @@ class CustomerPurchaseOrderImporter(models.Model):
     def _get_product(self, data, description=''):
         errors = []
 
-        code = list(data.keys())[0]
+        code = sorted(list(data.keys()))[0]
 
         product = data[code]['product']
         if not product: