summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/website_user_cart.py
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2024-01-04 02:27:45 +0000
committerIT Fixcomart <it@fixcomart.co.id>2024-01-04 02:27:45 +0000
commit63abd2dc32f952af7234f3d6a7774cbb8c7bcb47 (patch)
treeb4cee127fc7d467b33cef4ffae9218f8acb9aeaa /indoteknik_custom/models/website_user_cart.py
parent13b31fc3d89957d23582efb2c51ab143ca1d425a (diff)
parent717cb3b43c729e265603b3df61234c0b430742a7 (diff)
Merged in change/feature/promotion-program (pull request #133)
Change/feature/promotion program
Diffstat (limited to 'indoteknik_custom/models/website_user_cart.py')
-rw-r--r--indoteknik_custom/models/website_user_cart.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py
index bbc14c88..eaa5f009 100644
--- a/indoteknik_custom/models/website_user_cart.py
+++ b/indoteknik_custom/models/website_user_cart.py
@@ -51,7 +51,9 @@ class WebsiteUserCart(models.Model):
return res
def get_products(self):
- return [x.get_product() for x in self]
+ products = [x.get_product() for x in self]
+
+ return products
def get_product_by_user(self, user_id, selected=False, source=False):
user_id = int(user_id)
@@ -75,8 +77,20 @@ class WebsiteUserCart(models.Model):
def get_user_checkout(self, user_id, voucher=False, source=False):
products = self.get_product_by_user(user_id=user_id, selected=True, source=source)
- 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)
+
+ total_purchase = 0
+ total_discount = 0
+ for product in products:
+ if product['cart_type'] == 'promotion':
+ price = product['package_price'] * product['quantity']
+ else:
+ price = product['price']['price'] * product['quantity']
+
+ discount_price = price - product['price']['price_discount'] * product['quantity']
+
+ total_purchase += price
+ total_discount += discount_price
+
subtotal = total_purchase - total_discount
discount_voucher = 0
if voucher: