summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-08-13 17:05:22 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-08-13 17:05:22 +0700
commit89f27a69415d8ffbadbfbab0e23af9cada86d163 (patch)
treecdb38e3a69cdbc21231c16c3431e9da2841d30a9
parent8eaffe2f3590e52b90835fada67460e119032dee (diff)
<iman> add api pickup-service
-rw-r--r--indoteknik_custom/models/website_user_cart.py25
1 files changed, 20 insertions, 5 deletions
diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py
index dd3f87e6..10821cd3 100644
--- a/indoteknik_custom/models/website_user_cart.py
+++ b/indoteknik_custom/models/website_user_cart.py
@@ -24,16 +24,31 @@ class WebsiteUserCart(models.Model):
def get_product(self):
res = {
- 'cart_id': self.id,
- 'quantity': self.qty,
+ 'cart_id': self.id,
+ 'quantity': self.qty,
'selected': self.is_selected,
'can_buy': True
}
-
+
if self.product_id:
res['cart_type'] = 'product'
product = self.product_id.v2_api_single_response(self.product_id)
res.update(product)
+
+ # Check if the product's inventory location is in ID 57 or 83
+ target_locations = [57, 83]
+ stock_quant = self.env['stock.quant'].search([
+ ('product_id', '=', self.product_id.id),
+ ('location_id', 'in', target_locations)
+ ])
+
+ if stock_quant:
+ res['is_in_bu'] = True
+ res['on_hand_qty'] = sum(stock_quant.mapped('quantity'))
+ else:
+ res['is_in_bu'] = False
+ res['on_hand_qty'] = 0
+
flashsales = self.product_id._get_active_flash_sale()
res['has_flashsale'] = True if len(flashsales) > 0 else False
elif self.program_line_id:
@@ -48,9 +63,9 @@ class WebsiteUserCart(models.Model):
res['can_buy'] = False
res['subtotal'] = self.qty * res['price']['price_discount']
-
+
return res
-
+
def get_products(self):
products = [x.get_product() for x in self]