summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-12-22 11:20:45 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-12-22 11:20:45 +0700
commitad127a4dc2bfb81d9c99ba78ab41a49eefeb0dd2 (patch)
tree218343dfe94a59e0651f880e9c291225c179f9a2
parentde6039ab7675d91bcfcb67747d3c72be95a379e6 (diff)
update promotion program feature
-rw-r--r--indoteknik_api/controllers/api_v1/cart.py21
-rw-r--r--indoteknik_custom/models/promotion/promotion_program_line.py7
2 files changed, 21 insertions, 7 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_custom/models/promotion/promotion_program_line.py b/indoteknik_custom/models/promotion/promotion_program_line.py
index 34a0fbb2..d9095c75 100644
--- a/indoteknik_custom/models/promotion/promotion_program_line.py
+++ b/indoteknik_custom/models/promotion/promotion_program_line.py
@@ -96,7 +96,11 @@ class PromotionProgramLine(models.Model):
weight = 0
if not any(x['package_weight'] == 0 for x in merged_products):
weight = sum(x['package_weight'] for x in merged_products)
-
+
+ products_total = sum(x['price']['price_discount'] * x['qty'] for x in products)
+ free_products_total = sum(x['price']['price_discount'] * x['qty'] for x in free_products)
+ package_price = products_total + free_products_total
+
response = {
'id': self.id,
'name': self.name,
@@ -106,6 +110,7 @@ class PromotionProgramLine(models.Model):
'limit_qty': limit_qty,
'remaining_qty': remaining_qty,
'used_percentage': percent_remaining,
+ 'package_price': package_price,
'price': {
'price': self.price,
'price_discount': self.price,