summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/website_user_cart.py
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-02-07 10:45:51 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-02-07 10:45:51 +0700
commitf6be42d37a363b86f4a9ec71ccb38c78cbe2d887 (patch)
tree9c297e776f67e35671012e94d3c64007bd5090d7 /indoteknik_custom/models/website_user_cart.py
parentedb3c1c80931078d40a8f56149aeca9efdcdc07d (diff)
parent29a9ec94f1ad131f398cf119a03a7b927a4c6cba (diff)
Merge branch 'production' into purchasing-job
# Conflicts: # indoteknik_custom/__manifest__.py # indoteknik_custom/models/__init__.py # indoteknik_custom/models/automatic_purchase.py # indoteknik_custom/models/purchase_order_line.py # indoteknik_custom/security/ir.model.access.csv # indoteknik_custom/views/automatic_purchase.xml # indoteknik_custom/views/purchase_order.xml
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: