summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/website_user_cart.py
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-07-20 11:20:21 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-07-20 11:20:21 +0700
commit3c9ef63acb42298d948ee86407d9a5ca67004246 (patch)
tree87dfe77c6ebf6b3aaf8e3f336432947e502487e8 /indoteknik_custom/models/website_user_cart.py
parented231d1cfa4e78b8f98c5406f88c1f985c0225a7 (diff)
Add discount_voucher on get checkout data API
Diffstat (limited to 'indoteknik_custom/models/website_user_cart.py')
-rw-r--r--indoteknik_custom/models/website_user_cart.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py
index 802dbd37..29bf4291 100644
--- a/indoteknik_custom/models/website_user_cart.py
+++ b/indoteknik_custom/models/website_user_cart.py
@@ -45,17 +45,22 @@ class WebsiteUserCart(models.Model):
products = carts.get_products()
return products
- def get_user_checkout(self, user_id):
+ def get_user_checkout(self, user_id, voucher=False):
products = self.get_product_by_user(user_id=user_id, selected=True)
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
+ discount_voucher = 0
+ if voucher:
+ discount_voucher = voucher.calculate_discount(subtotal)
+ subtotal -= discount_voucher
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,
+ 'discount_voucher': discount_voucher,
'subtotal': subtotal,
'tax': tax,
'grand_total': round(grand_total),