diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2023-08-04 03:59:33 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2023-08-04 03:59:33 +0000 |
| commit | 6d17228cd6c789fe4460e28807d5b39fb1bbe9b7 (patch) | |
| tree | a4c961062c026e1005ebdc82547903c3f30c0a06 /indoteknik_api/controllers/api_v1 | |
| parent | cc182dd9963fb8985661ca1b64a53e7f11f095c5 (diff) | |
| parent | bcc35009da39e9ee8b5e181006d3690316b83c59 (diff) | |
Merged in development (pull request #82)
Development
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/flash_sale.py | 5 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/voucher.py | 30 |
2 files changed, 21 insertions, 14 deletions
diff --git a/indoteknik_api/controllers/api_v1/flash_sale.py b/indoteknik_api/controllers/api_v1/flash_sale.py index dc7c3928..dff8bec3 100644 --- a/indoteknik_api/controllers/api_v1/flash_sale.py +++ b/indoteknik_api/controllers/api_v1/flash_sale.py @@ -1,4 +1,3 @@ -from datetime import datetime import logging from .. import controller from odoo import http @@ -28,7 +27,7 @@ class FlashSale(controller.Controller): 'banner': request.env['ir.attachment'].api_image('product.pricelist', 'banner', pricelist.id), 'banner_mobile': request.env['ir.attachment'].api_image('product.pricelist', 'banner_mobile', pricelist.id), 'banner_top': request.env['ir.attachment'].api_image('product.pricelist', 'banner_top', pricelist.id), - 'duration': round((pricelist.end_date - datetime.now()).total_seconds()), + 'duration': pricelist._remaining_time_in_second(), 'product_total': request.env['product.pricelist.item'].search_count(query), }) return self.response(data) @@ -94,7 +93,7 @@ class FlashSale(controller.Controller): 'name': active_flash_sale.name, 'banner': base_url + 'api/image/product.pricelist/banner/' + str(active_flash_sale.id) if active_flash_sale.banner else '', 'banner_mobile': base_url + 'api/image/product.pricelist/banner_mobile/' + str(active_flash_sale.id) if active_flash_sale.banner_mobile else '', - 'duration': round((active_flash_sale.end_date - datetime.now()).total_seconds()), + 'duration': active_flash_sale._remaining_time_in_second(), 'flashsale_option': active_flash_sale.flashsale_option, 'product_total': request.env['product.template'].search_count(query), 'products': [request.env['product.template'].api_single_response(x) for x in product_templates] diff --git a/indoteknik_api/controllers/api_v1/voucher.py b/indoteknik_api/controllers/api_v1/voucher.py index 4baa93b7..f82e1aef 100644 --- a/indoteknik_api/controllers/api_v1/voucher.py +++ b/indoteknik_api/controllers/api_v1/voucher.py @@ -31,9 +31,9 @@ class Voucher(controller.Controller): apply_status = '' products = checkout['products'] min_purchase_amount = voucher['min_purchase_amount'] - can_apply = True + can_apply = False difference_to_apply = 0 - + manufacture_ids = voucher['manufacture_ids'] subtotal = 0 has_match_manufacture = False @@ -43,18 +43,25 @@ class Voucher(controller.Controller): quantity = product['quantity'] manufacture_id = product['manufacture']['id'] or False - if len(manufacture_ids) == 0 or manufacture_id in manufacture_ids: - purchase_amt = price * quantity - discount_amt = (price - price_discount) * quantity - subtotal += purchase_amt - discount_amt + if len(manufacture_ids) == 0 or (not product['has_flashsale'] and manufacture_id in manufacture_ids): has_match_manufacture = True - + + if product['has_flashsale']: + continue + + purchase_amt = price * quantity + discount_amt = (price - price_discount) * quantity + subtotal += purchase_amt - discount_amt + + has_flashsale_products = any(product['has_flashsale'] for product in products) if not has_match_manufacture: - can_apply = False - apply_status = 'UM' + apply_status = 'UM' # Unqualified Manufacture elif subtotal < min_purchase_amount: - can_apply = False - apply_status = 'MPA' + apply_status = 'MPA' # Minimum Purchase Amount + else: + can_apply = True + + if subtotal < min_purchase_amount: difference_to_apply = min_purchase_amount - subtotal obj_voucher = request.env['voucher'].browse(voucher['id']) @@ -62,6 +69,7 @@ class Voucher(controller.Controller): voucher['can_apply'] = can_apply voucher['apply_status'] = apply_status + voucher['has_flashsale_products'] = has_flashsale_products voucher['discount_voucher'] = discount_voucher voucher['difference_to_apply'] = difference_to_apply |
