summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2024-01-04 02:27:45 +0000
committerIT Fixcomart <it@fixcomart.co.id>2024-01-04 02:27:45 +0000
commit63abd2dc32f952af7234f3d6a7774cbb8c7bcb47 (patch)
treeb4cee127fc7d467b33cef4ffae9218f8acb9aeaa /indoteknik_api/controllers
parent13b31fc3d89957d23582efb2c51ab143ca1d425a (diff)
parent717cb3b43c729e265603b3df61234c0b430742a7 (diff)
Merged in change/feature/promotion-program (pull request #133)
Change/feature/promotion program
Diffstat (limited to 'indoteknik_api/controllers')
-rw-r--r--indoteknik_api/controllers/api_v1/cart.py21
-rw-r--r--indoteknik_api/controllers/api_v1/promotion.py22
2 files changed, 37 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)
diff --git a/indoteknik_api/controllers/api_v1/promotion.py b/indoteknik_api/controllers/api_v1/promotion.py
index f84b8c1c..221f6e10 100644
--- a/indoteknik_api/controllers/api_v1/promotion.py
+++ b/indoteknik_api/controllers/api_v1/promotion.py
@@ -6,6 +6,28 @@ from datetime import datetime
class Promotion(controller.Controller):
prefix = '/api/v1/'
+
+ @http.route(prefix + 'program-line/<id>/stock', auth='public', methods=['GET', 'OPTIONS'])
+ @controller.Controller.must_authorized()
+ def get_promotion_stock(self, id):
+ program_line = request.env['promotion.program.line'].browse(int(id))
+ if not program_line.id:
+ return self.response(code=400, description='program not found')
+
+ user_data = self.verify_user_token()
+
+ limit_qty = program_line._res_limit_qty()
+ remaining_qty = program_line._get_remaining_qty(user_data)
+
+ percent_remaining = 0
+ if limit_qty['all'] > 0:
+ percent_remaining = (limit_qty['all'] - remaining_qty['all']) / limit_qty['all'] * 100
+
+ return self.response({
+ 'limit_qty': limit_qty,
+ 'remaining_qty': remaining_qty,
+ 'used_percentage': percent_remaining,
+ })
@http.route(prefix + 'promotion/<id>', auth='public', methods=['GET'])