From 53e3cacd7d32df44ce8637284c3ec16050e07e5b Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 1 Jul 2024 09:20:09 +0700 Subject: add flash sale to sales order --- indoteknik_api/controllers/api_v1/sale_order.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indoteknik_api/controllers') diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index f17e736f..5dc0f6aa 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -331,6 +331,7 @@ class SaleOrder(controller.Controller): 'delivery_amount': ['number', 'default:0'], 'carrier_id': [], 'delivery_service_type': [], + 'flash_sale': [], 'voucher': [], 'source': [], 'estimated_arrival_days': ['number', 'default:0'] @@ -364,6 +365,7 @@ class SaleOrder(controller.Controller): 'shipping_paid_by': 'customer', 'carrier_id': params['value']['carrier_id'], 'delivery_service_type': params['value']['delivery_service_type'], + 'flash_sale': params['value']['flash_sale'], 'customer_type': 'nonpkp', 'npwp': '0', 'user_id': 1180 # User ID: Ima Nurhikmah -- cgit v1.2.3 From a54492e34db2a43d9aae2d575b2b3c073669631c Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 1 Jul 2024 11:19:19 +0700 Subject: update flash sale & get_request_params untuk boolean --- indoteknik_api/controllers/api_v1/sale_order.py | 2 +- indoteknik_api/controllers/controller.py | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'indoteknik_api/controllers') diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index 5dc0f6aa..ea2d381c 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -331,7 +331,7 @@ class SaleOrder(controller.Controller): 'delivery_amount': ['number', 'default:0'], 'carrier_id': [], 'delivery_service_type': [], - 'flash_sale': [], + 'flash_sale': ['boolean'], 'voucher': [], 'source': [], 'estimated_arrival_days': ['number', 'default:0'] diff --git a/indoteknik_api/controllers/controller.py b/indoteknik_api/controllers/controller.py index 017e5c12..a5a05c1b 100644 --- a/indoteknik_api/controllers/controller.py +++ b/indoteknik_api/controllers/controller.py @@ -80,9 +80,10 @@ class Controller(http.Controller): 'value': {}, 'query': {} } - + for key, rules in queries.items(): is_number = 'number' in rules + is_boolean = 'boolean' in rules is_exclude_if_null = 'exclude_if_null' in rules alias = next((r.replace('alias:', '') for r in rules if r.startswith('alias:')), key) default = next((r.replace('default:', '') for r in rules if r.startswith('default:')), None) @@ -94,6 +95,13 @@ class Controller(http.Controller): result['reason'].append(f"{key} is required") if 'number' in rules and value and not value.isdigit(): result['reason'].append(f"{key} must be a number") + if is_boolean and value: + if value.lower() in ['true', '1']: + value = True + elif value.lower() in ['false', '0']: + value = False + else: + result['reason'].append(f"{key} must be a boolean") result['query'][key] = value @@ -102,13 +110,20 @@ class Controller(http.Controller): if is_number and value.isdigit(): value = int(value) + # Assign the boolean value + if is_boolean: + if value.lower() in ['true', '1']: + value = True + elif value.lower() in ['false', '0']: + value = False + if not value and is_exclude_if_null: continue result['value'][alias] = value result['valid'] = not result['reason'] - + return result def time_to_str(self, object, format): -- cgit v1.2.3 From f134865c1e61aa7b808dbe46c2d7d33eb34c5183 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 1 Jul 2024 11:32:59 +0700 Subject: update get params for boolean flash sale --- indoteknik_api/controllers/controller.py | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'indoteknik_api/controllers') diff --git a/indoteknik_api/controllers/controller.py b/indoteknik_api/controllers/controller.py index a5a05c1b..a34a2688 100644 --- a/indoteknik_api/controllers/controller.py +++ b/indoteknik_api/controllers/controller.py @@ -93,15 +93,10 @@ class Controller(http.Controller): value = '' if 'required' in rules and not value: result['reason'].append(f"{key} is required") - if 'number' in rules and value and not value.isdigit(): + if is_number and value and not value.isdigit(): result['reason'].append(f"{key} must be a number") - if is_boolean and value: - if value.lower() in ['true', '1']: - value = True - elif value.lower() in ['false', '0']: - value = False - else: - result['reason'].append(f"{key} must be a boolean") + if is_boolean and value and value.lower() not in ['true', 'false', '1', '0']: + result['reason'].append(f"{key} must be a boolean") result['query'][key] = value @@ -109,13 +104,8 @@ class Controller(http.Controller): value = default if is_number and value.isdigit(): value = int(value) - - # Assign the boolean value if is_boolean: - if value.lower() in ['true', '1']: - value = True - elif value.lower() in ['false', '0']: - value = False + value = value.lower() in ['true', '1'] if not value and is_exclude_if_null: continue -- cgit v1.2.3