diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2024-07-01 07:50:42 +0000 |
|---|---|---|
| committer | trisusilo <tri.susilo@altama.co.id> | 2024-07-01 07:50:42 +0000 |
| commit | 2ad59ce416a79bdd12f74f4fd491d30443e9ebdf (patch) | |
| tree | 88b7a32216b4a9a2967dc580d6c841d73b7f0354 /indoteknik_api/controllers | |
| parent | 424e8a227f73ae528812c9baaa6ee6e09a181bb7 (diff) | |
| parent | f134865c1e61aa7b808dbe46c2d7d33eb34c5183 (diff) | |
Merged in feature/iman_flash_sale (pull request #150)
<iman> add flash sale to sales order
Approved-by: trisusilo
Diffstat (limited to 'indoteknik_api/controllers')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/sale_order.py | 2 | ||||
| -rw-r--r-- | indoteknik_api/controllers/controller.py | 11 |
2 files changed, 10 insertions, 3 deletions
diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index f17e736f..ea2d381c 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': ['boolean'], '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 diff --git a/indoteknik_api/controllers/controller.py b/indoteknik_api/controllers/controller.py index 017e5c12..a34a2688 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) @@ -92,8 +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 and value.lower() not in ['true', 'false', '1', '0']: + result['reason'].append(f"{key} must be a boolean") result['query'][key] = value @@ -101,6 +104,8 @@ class Controller(http.Controller): value = default if is_number and value.isdigit(): value = int(value) + if is_boolean: + value = value.lower() in ['true', '1'] if not value and is_exclude_if_null: continue @@ -108,7 +113,7 @@ class Controller(http.Controller): result['value'][alias] = value result['valid'] = not result['reason'] - + return result def time_to_str(self, object, format): |
