diff options
Diffstat (limited to 'indoteknik_custom/models/website_user_cart.py')
| -rw-r--r-- | indoteknik_custom/models/website_user_cart.py | 20 |
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: |
