summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/website_user_cart.py
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-08-14 16:12:14 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-08-14 16:12:14 +0700
commitd47eb069978ce67bce1a19b6c824a53ca3d68801 (patch)
tree2427f680d68c8b136531d392eb36cf4262c7d35b /indoteknik_custom/models/website_user_cart.py
parent2513b765773fca587dbd298e77732d2d005949c8 (diff)
parentd4df708e5195e1c0c3b8e0ad90b7518e5d4d48c2 (diff)
<iman> Merge branch 'production' of https://bitbucket.org/altafixco/indoteknik-addons into feature/tracking-order
# Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
Diffstat (limited to 'indoteknik_custom/models/website_user_cart.py')
-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]