summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2024-08-14 08:01:20 +0000
committerIT Fixcomart <it@fixcomart.co.id>2024-08-14 08:01:20 +0000
commitc5e742d609ec379b6d0228f8274b3d97bda9214d (patch)
tree0524cd84c752ca54a5e6b1cfeed949336d1d6083
parent72befb1e3401a4c31dbf2698963ec52c5baba8cd (diff)
parent05fc26b12693250b29606e0eb7fc297f16716099 (diff)
Merged in feature/pickup-service (pull request #193)
Feature/pickup service
-rw-r--r--indoteknik_custom/models/solr/product_template.py14
-rw-r--r--indoteknik_custom/models/website_user_cart.py25
2 files changed, 33 insertions, 6 deletions
diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py
index 892e7334..6ad49af7 100644
--- a/indoteknik_custom/models/solr/product_template.py
+++ b/indoteknik_custom/models/solr/product_template.py
@@ -68,7 +68,17 @@ class ProductTemplate(models.Model):
# Mengumpulkan semua kategori
category_ids = [category.id for category in template.public_categ_ids]
category_names = [category.name for category in template.public_categ_ids]
-
+
+ # 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', 'in', template.product_variant_ids.ids),
+ ('location_id', 'in', target_locations)
+ ])
+
+ is_in_bu = bool(stock_quant)
+ on_hand_qty = sum(stock_quant.mapped('quantity')) if stock_quant else 0
+
document = solr_model.get_doc('product', template.id)
document.update({
"id": template.id,
@@ -99,6 +109,8 @@ class ProductTemplate(models.Model):
'sni_b': template.unpublished,
'tkdn_b': template.unpublished,
"qty_sold_f": template.qty_sold,
+ "is_in_bu_b": is_in_bu,
+ "on_hand_qty_i": on_hand_qty,
"voucher_pastihemat" : {
"min_purchase" : voucher.min_purchase_amount or 0,
"discount_type" : voucher.discount_type or '',
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]