summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-07-20 10:42:32 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-07-20 10:42:32 +0700
commit7b76facc6b7fdbff83a98a1b3251f1d3dad48937 (patch)
treecca89faa184b6b1162e418fc08b39448c6a40176
parentc7389ec4ab18ee7ad993f1ec4d29da9d677ee431 (diff)
Add get_user_checkout on user cart
-rw-r--r--indoteknik_api/controllers/api_v1/sale_order.py21
-rw-r--r--indoteknik_custom/models/website_user_cart.py25
2 files changed, 25 insertions, 21 deletions
diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py
index 8135da33..29649315 100644
--- a/indoteknik_api/controllers/api_v1/sale_order.py
+++ b/indoteknik_api/controllers/api_v1/sale_order.py
@@ -236,26 +236,7 @@ class SaleOrder(controller.Controller):
@controller.Controller.must_authorized(private=True, private_key='user_id')
def get_user_checkout_so(self, user_id):
cart = request.env['website.user.cart']
- products = cart.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
- }
+ result = cart.get_user_checkout(user_id)
return self.response(result)
@http.route(PREFIX_PARTNER + 'sale_order/checkout', auth='public', method=['POST', 'OPTIONS'], csrf=False)
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