diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-09-06 10:33:34 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-09-06 10:33:34 +0700 |
| commit | ea48748650d1abe7b9c09f961eaa3762750e21be (patch) | |
| tree | 6fabd4d2aff8d88fb76aa3fb4a10478975bd3c47 /indoteknik_api/controllers/api_v1/voucher.py | |
| parent | a8404a3ed4423dd7d86f8637ecbf35b7cc18a14c (diff) | |
Add voucher terms and conditions
Add voucher to sale order API
Diffstat (limited to 'indoteknik_api/controllers/api_v1/voucher.py')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/voucher.py | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/indoteknik_api/controllers/api_v1/voucher.py b/indoteknik_api/controllers/api_v1/voucher.py index e19ae583..2ad61feb 100644 --- a/indoteknik_api/controllers/api_v1/voucher.py +++ b/indoteknik_api/controllers/api_v1/voucher.py @@ -26,34 +26,35 @@ class Voucher(controller.Controller): parameter += [('visibility', 'in', visibility)] vouchers = request.env['voucher'].get_active_voucher(parameter) checkout = cart.get_user_checkout(user_id, source=source) - + products = checkout['products'] + + order_line = [] + for product in products: + order_line.append({ + 'product_id': request.env['product.product'].browse(product['id']), + 'price': product['price']['price'], + 'discount': product['price']['discount_percentage'], + 'qty': product['quantity'], + 'subtotal': product['subtotal'] + }) + results = [] for voucher in vouchers: - products = checkout['products'] - - order_line = [] - for product in products: - order_line.append({ - 'product_id': request.env['product.product'].browse(product['id']), - 'price': product['price']['price'], - 'discount': product['price']['discount_percentage'], - 'qty': product['quantity'], - 'subtotal': product['subtotal'] - }) + if not voucher.can_used: + continue + voucher_info = voucher.apply(order_line) + voucher_tnc = voucher.terms_conditions or voucher.generate_tnc() voucher_discount = voucher_info['discount']['all'] valid_order = voucher_info['valid_order'] - has_flashsale_products = any(product['has_flashsale'] for product in products) can_apply = True if valid_order and voucher_discount > 0 else False voucher_res = voucher.format() voucher_res['can_apply'] = can_apply - voucher_res['apply_status'] = '' - voucher_res['has_flashsale_products'] = has_flashsale_products - voucher_res['difference_to_apply'] = 0 voucher_res['discount_voucher'] = voucher_discount + voucher_res['terms_conditions'] = voucher_tnc results.append(voucher_res) sorted_results = sorted(results, key=lambda x: x['can_apply'], reverse=True) |
