diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2024-01-04 09:25:14 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2024-01-04 09:25:14 +0700 |
| commit | 717cb3b43c729e265603b3df61234c0b430742a7 (patch) | |
| tree | 96b5547e395fc8cef46d679cbf4afee7d7dd729c /indoteknik_custom/models/website_user_cart.py | |
| parent | ad127a4dc2bfb81d9c99ba78ab41a49eefeb0dd2 (diff) | |
update promotion program feature
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: |
