summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-06-19 15:13:55 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-06-19 15:13:55 +0700
commit4e9a5a025012afe63133524eeea8987b9af9e050 (patch)
tree4b1d416d416d84e25c340a5777f7ff134569922b /indoteknik_api/controllers/api_v1
parent09458dba5519f01eadf5f9ca4f22a30dad98d5c7 (diff)
Add response on get user checkout data API
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
-rw-r--r--indoteknik_api/controllers/api_v1/sale_order.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py
index 89e96206..406ab577 100644
--- a/indoteknik_api/controllers/api_v1/sale_order.py
+++ b/indoteknik_api/controllers/api_v1/sale_order.py
@@ -223,17 +223,23 @@ class SaleOrder(controller.Controller):
def get_user_checkout_so(self, user_id):
cart = request.env['website.user.cart']
products = cart.get_product_by_user(user_id=user_id, selected=True)
- total_purchase = sum(x['price']['price'] for x in products)
- total_discount = sum((x['price']['price'] - x['price']['price_discount']) for x in products)
+ total_purchase = sum(x['price']['price'] * x['quantity'] for x in products)
+ total_discount = sum((x['price']['price'] - x['price']['price_discount']) * x['quantity'] for x in products)
subtotal = total_purchase - total_discount
tax = round(subtotal * 0.11)
grand_total = subtotal + tax
+ total_weight = sum(x['weight'] * x['quantity'] for x in products)
result = {
'total_purchase': total_purchase,
'total_discount': total_discount,
'subtotal': subtotal,
'tax': tax,
'grand_total': round(grand_total),
+ 'total_weight': {
+ 'kg': total_weight,
+ 'g': total_weight * 1000
+ },
+ 'has_product_without_weight': any(not product.get('weight') or product.get('weight') == 0 for product in products),
'products': products
}
return self.response(result)