From 1563299905b3e0cf97129739c0ee0a6269ce4bc8 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 28 Jul 2023 16:53:32 +0700 Subject: Add flash sale remaining time API response --- indoteknik_api/controllers/api_v1/flash_sale.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'indoteknik_api/controllers/api_v1') 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] -- cgit v1.2.3 From f8e0259289c728b11a373601e569f6e64ca803f8 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Tue, 1 Aug 2023 11:32:11 +0700 Subject: Update voucher can't combined with other promotions --- indoteknik_api/controllers/api_v1/voucher.py | 30 ++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'indoteknik_api/controllers/api_v1') diff --git a/indoteknik_api/controllers/api_v1/voucher.py b/indoteknik_api/controllers/api_v1/voucher.py index 4baa93b7..e6fdca68 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 @@ -44,17 +44,26 @@ class Voucher(controller.Controller): 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 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 + elif has_flashsale_products: + apply_status = 'HF' # Has Flashsale + 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 +71,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 -- cgit v1.2.3 From 59806fddc84133717fc78b2a50a09d7638a8e79b Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 3 Aug 2023 14:01:34 +0700 Subject: Update get voucher API --- indoteknik_api/controllers/api_v1/voucher.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'indoteknik_api/controllers/api_v1') diff --git a/indoteknik_api/controllers/api_v1/voucher.py b/indoteknik_api/controllers/api_v1/voucher.py index e6fdca68..6dbf8c32 100644 --- a/indoteknik_api/controllers/api_v1/voucher.py +++ b/indoteknik_api/controllers/api_v1/voucher.py @@ -58,8 +58,6 @@ class Voucher(controller.Controller): apply_status = 'UM' # Unqualified Manufacture elif subtotal < min_purchase_amount: apply_status = 'MPA' # Minimum Purchase Amount - elif has_flashsale_products: - apply_status = 'HF' # Has Flashsale else: can_apply = True -- cgit v1.2.3 From 769ce2949ad4a3f03e0a05c6298d7299bc5b0d67 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 3 Aug 2023 14:11:01 +0700 Subject: Fix get voucher API logic --- indoteknik_api/controllers/api_v1/voucher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_api/controllers/api_v1') diff --git a/indoteknik_api/controllers/api_v1/voucher.py b/indoteknik_api/controllers/api_v1/voucher.py index 6dbf8c32..f82e1aef 100644 --- a/indoteknik_api/controllers/api_v1/voucher.py +++ b/indoteknik_api/controllers/api_v1/voucher.py @@ -43,7 +43,7 @@ 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: + if len(manufacture_ids) == 0 or (not product['has_flashsale'] and manufacture_id in manufacture_ids): has_match_manufacture = True if product['has_flashsale']: -- cgit v1.2.3