diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-08-29 13:09:54 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-08-29 13:09:54 +0700 |
| commit | 0e9e58da406e62a72ce2ba18c6317e3de57963a1 (patch) | |
| tree | e71748bf819c9760400183029aaede2a00772a3a /indoteknik_custom | |
| parent | f4c67f4f8ef9ffc9da3e0406cb08fffb6ba44fd4 (diff) | |
cr api voucher
Diffstat (limited to 'indoteknik_custom')
| -rw-r--r-- | indoteknik_custom/models/website_user_cart.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py index d9352abb..c233dfd7 100644 --- a/indoteknik_custom/models/website_user_cart.py +++ b/indoteknik_custom/models/website_user_cart.py @@ -91,7 +91,7 @@ class WebsiteUserCart(models.Model): products = carts.get_products() return products - def get_user_checkout(self, user_id, voucher=False, source=False): + def get_user_checkout(self, user_id, voucher=False, voucher_shipping=False, source=False): products = self.get_product_by_user(user_id=user_id, selected=True, source=source) total_purchase = 0 @@ -109,12 +109,12 @@ class WebsiteUserCart(models.Model): subtotal = total_purchase - total_discount discount_voucher = 0 - if voucher: - order_line = [] + discount_voucher_shipping = 0 + order_line = [] + + if voucher or voucher_shipping: for product in products: - if product['cart_type'] == 'promotion': - continue - + if product['cart_type'] == 'promotion': continue order_line.append({ 'product_id': self.env['product.product'].browse(product['id']), 'price': product['price']['price'], @@ -122,9 +122,16 @@ class WebsiteUserCart(models.Model): 'qty': product['quantity'], 'subtotal': product['subtotal'] }) + + if voucher: voucher_info = voucher.apply(order_line) discount_voucher = voucher_info['discount']['all'] subtotal -= discount_voucher + + if voucher_shipping: + voucher_shipping_info = voucher_shipping.apply(order_line) + discount_voucher_shipping = voucher_shipping_info['discount']['all'] + tax = round(subtotal * 0.11) grand_total = subtotal + tax total_weight = sum(x['weight'] * x['quantity'] for x in products) @@ -133,6 +140,7 @@ class WebsiteUserCart(models.Model): 'total_purchase': total_purchase, 'total_discount': total_discount, 'discount_voucher': discount_voucher, + 'discount_voucher_shipping': discount_voucher_shipping, 'subtotal': subtotal, 'tax': tax, 'grand_total': round(grand_total), |
