diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-12-22 11:20:45 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-12-22 11:20:45 +0700 |
| commit | ad127a4dc2bfb81d9c99ba78ab41a49eefeb0dd2 (patch) | |
| tree | 218343dfe94a59e0651f880e9c291225c179f9a2 /indoteknik_api | |
| parent | de6039ab7675d91bcfcb67747d3c72be95a379e6 (diff) | |
update promotion program feature
Diffstat (limited to 'indoteknik_api')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/cart.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/indoteknik_api/controllers/api_v1/cart.py b/indoteknik_api/controllers/api_v1/cart.py index 8ef2c1c1..907c8288 100644 --- a/indoteknik_api/controllers/api_v1/cart.py +++ b/indoteknik_api/controllers/api_v1/cart.py @@ -36,18 +36,21 @@ class Cart(controller.Controller): def create_or_update_cart(self, user_id, **kw): # Convert input values to appropriate types user_id = int(user_id) - product_id = int(kw.get('product_id', 0)) - qty = int(kw.get('qty', 0)) - source = kw.get('source') - is_selected = kw.get('selected', False) + product_id = kw.get('product_id', 0) + product_id = False if product_id == 'null' or not product_id else int(product_id) + program_line_id = kw.get('program_line_id', False) program_line_id = False if program_line_id == 'null' or not program_line_id else int(program_line_id) + qty = int(kw.get('qty', 0)) + source = kw.get('source') + + is_selected = kw.get('selected', False) is_selected = is_selected in ('true', True) # Check required fields - if not user_id or not product_id or not qty: - return self.response(code=400, description='user_id, product_id and qty is required') + if not user_id: + return self.response(code=400, description='user_id is required') website_user_cart = request.env['website.user.cart'] @@ -97,9 +100,15 @@ class Cart(controller.Controller): def delete_cart_by_user_id(self, user_id, **kw): user_id = int(user_id) query = [('user_id', '=', user_id)] + + ids = kw.get('ids') + if ids: + query += [('id', 'in', [int(x) for x in ids.split(',')])] + product_ids = kw.get('product_ids') if product_ids: query += [('product_id', 'in', [int(x) for x in product_ids.split(',')])] + cart = request.env['website.user.cart'].search(query).unlink() return self.response(cart) |
