diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-07-20 10:42:32 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-07-20 10:42:32 +0700 |
| commit | 7b76facc6b7fdbff83a98a1b3251f1d3dad48937 (patch) | |
| tree | cca89faa184b6b1162e418fc08b39448c6a40176 /indoteknik_custom | |
| parent | c7389ec4ab18ee7ad993f1ec4d29da9d677ee431 (diff) | |
Add get_user_checkout on user cart
Diffstat (limited to 'indoteknik_custom')
| -rw-r--r-- | indoteknik_custom/models/website_user_cart.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index a8cde228..802dbd37 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -43,4 +43,27 @@ class WebsiteUserCart(models.Model): parameters.append(('is_selected', '=', True)) carts = self.search(parameters) products = carts.get_products() - return products
\ No newline at end of file + return products + + def get_user_checkout(self, user_id): + 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 + 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, + 'subtotal': subtotal, + 'tax': tax, + 'grand_total': round(grand_total), + 'total_weight': { + 'kg': total_weight, + 'g': total_weight * 1000 + }, + 'has_product_without_weight': any(not product.get('weight') or product.get('weight') == 0 for product in products), + 'products': products + } + return result
\ No newline at end of file |
