summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/solr
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-10-25 08:47:36 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-10-25 08:47:36 +0700
commit9fa80c62cdffec5b91aaf2a2899d70d0f507c2e4 (patch)
tree93ae8d82f774345f650bc8d072dea759c6e33363 /indoteknik_custom/models/solr
parenta21c5fe37529b2d2259d3b86d8e98730b2bc8513 (diff)
parenta7be93f4825967807f12e6bfbebcf090af8500fa (diff)
Merge branch 'production' into iman/switch-account
# Conflicts: # indoteknik_api/controllers/api_v1/user.py # indoteknik_custom/models/user_company_request.py
Diffstat (limited to 'indoteknik_custom/models/solr')
-rw-r--r--indoteknik_custom/models/solr/product_product.py12
-rw-r--r--indoteknik_custom/models/solr/product_template.py16
2 files changed, 21 insertions, 7 deletions
diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py
index 35e3a4b3..7c10a910 100644
--- a/indoteknik_custom/models/solr/product_product.py
+++ b/indoteknik_custom/models/solr/product_product.py
@@ -47,6 +47,15 @@ class ProductProduct(models.Model):
category_id = category.id
category_name = category.name
+ # 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', variant.product_variant_ids.ids),
+ ('location_id', 'in', target_locations),
+ ])
+
+ is_in_bu = any(quant.available_quantity > 0 for quant in stock_quant)
+
document = solr_model.get_doc('variants', variant.id)
document.update({
@@ -76,7 +85,8 @@ class ProductProduct(models.Model):
'publish_b': not variant.unpublished,
'sni_b': variant.sni,
'tkdn_b': variant.tkdn,
- 'qty_sold_f': variant.qty_sold
+ 'qty_sold_f': variant.qty_sold,
+ "is_in_bu_b": is_in_bu,
})
self.solr().add(docs=[document], softCommit=True)
diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py
index 1eb6f31b..1d54cc9b 100644
--- a/indoteknik_custom/models/solr/product_template.py
+++ b/indoteknik_custom/models/solr/product_template.py
@@ -74,10 +74,10 @@ class ProductTemplate(models.Model):
target_locations = [57, 83]
stock_quant = self.env['stock.quant'].search([
('product_id', 'in', template.product_variant_ids.ids),
- ('location_id', 'in', target_locations)
+ ('location_id', 'in', target_locations),
])
- is_in_bu = bool(stock_quant)
+ is_in_bu = any(quant.available_quantity > 0 for quant in stock_quant)
cleaned_desc = BeautifulSoup(template.website_description or '', "html.parser").get_text()
website_description = template.website_description if cleaned_desc else ''
@@ -158,10 +158,14 @@ class ProductTemplate(models.Model):
traverse_category(category.parent_id.id)
# Start traversal from the initial category
- traverse_category(category_id)
-
- # Reverse the list to get the hierarchy from top level to the current level
- return list(reversed(category_ids))
+ if category_id: # Check if category_id is not an empty value
+ traverse_category(category_id)
+
+ # Reverse the list to get the hierarchy from top level to the current level
+ return list(reversed(category_ids))
+ else:
+ # If category_id is empty, return an empty list
+ return []
def _sync_price_to_solr(self):
solr_model = self.env['apache.solr']