summaryrefslogtreecommitdiff
path: root/fixco_custom/models
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2026-02-12 18:16:23 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2026-02-12 18:16:23 +0700
commit23df914163b59d27c32e319f43ca8539a3e456cc (patch)
tree35536304107dc4a175d3cdb3c70a9978a3ed2835 /fixco_custom/models
parentf83e31153f08ae97ceaf4b29b7b83ebac6b891c0 (diff)
push
Diffstat (limited to 'fixco_custom/models')
-rwxr-xr-xfixco_custom/models/detail_order.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/fixco_custom/models/detail_order.py b/fixco_custom/models/detail_order.py
index 8ed85ba..2309e30 100755
--- a/fixco_custom/models/detail_order.py
+++ b/fixco_custom/models/detail_order.py
@@ -234,34 +234,47 @@ class DetailOrder(models.Model):
}
return data
- def _combine_order_items(self, items):
+ def _combine_order_items(self, items, lazada_id):
"""Combine quantities of the same products from multiple orders"""
product_quantities = {}
+
for item in items:
key = item.get('masterSku')
- # key = item.get('sku')
+ qty = item.get('quantity', 0)
+ price = item.get('actualPrice', 0)
+
if key in product_quantities:
- product_quantities[key]['quantity'] += item.get('quantity', 0)
- product_quantities[key]['actualPrice'] += item.get('actualPrice', 0)
+ if not lazada_id:
+ # Normal mode → digabung
+ product_quantities[key]['quantity'] += qty
+ product_quantities[key]['actualPrice'] += price
+ else:
+ # Lazada mode → overwrite, bukan akumulasi
+ product_quantities[key]['quantity'] += qty
+ product_quantities[key]['actualPrice'] = price
+ product_quantities[key]['item_data'] = item
else:
product_quantities[key] = {
- 'quantity': item.get('quantity', 0),
- 'actualPrice': item.get('actualPrice', 0),
+ 'quantity': qty,
+ 'actualPrice': price,
'productName': item.get('productName'),
'masterSkuType': item.get('masterSkuType'),
- 'item_data': item # Keep original item data
+ 'item_data': item
}
+
return product_quantities
+
def prepare_data_so_line(self, json_data):
order_lines = []
product_not_found = False
# Get all items (already combined if grouped)
items = json_data.get('data', [{}])[0].get('items', [])
+ lazada_id = json_data.get('data', [{}])[0].get('channel')
# Combine quantities of the same products
- product_quantities = self._combine_order_items(items)
+ product_quantities = self._combine_order_items(items, lazada_id=True if lazada_id == 'LAZADA_ID' else False)
# Process the combined items
for sku, combined_item in product_quantities.items():