summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/solr
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-07-02 10:06:29 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-07-02 10:06:29 +0700
commita10024fec206f68791c87a5a4e56e4c6bce28f5c (patch)
tree627d0ca2443eecbcb44b1b4eeda98f94c9ea3496 /indoteknik_custom/models/solr
parent51c19eca13239fe20ae592f8e9ee0d23f8904c5f (diff)
parentf9c5b3dffcd71bfa9dea74c946d7b4277db66bd6 (diff)
Merge branch 'production' into feature/add_voucher_pastihemat_productsolr
Diffstat (limited to 'indoteknik_custom/models/solr')
-rw-r--r--indoteknik_custom/models/solr/apache_solr.py39
1 files changed, 21 insertions, 18 deletions
diff --git a/indoteknik_custom/models/solr/apache_solr.py b/indoteknik_custom/models/solr/apache_solr.py
index 397db53b..6560c9b5 100644
--- a/indoteknik_custom/models/solr/apache_solr.py
+++ b/indoteknik_custom/models/solr/apache_solr.py
@@ -294,23 +294,26 @@ class ApacheSolr(models.Model):
return False
def _solr_sync_recommendation(self, limit=100):
- solr_model = self.env['apache.solr']
variants = self.env['product.product'].search([('solr_flag', '=', 2)], limit=limit)
- # documents = []
+ documents = []
+ catch = {}
for variant in variants:
- # document = solr_model.get_doc('recommendation', variant.id)
- document = {}
- document.update({
- 'id': variant.id,
- 'display_name_s': variant.display_name,
- 'name_s': variant.name,
- 'default_code_s': variant.default_code or '',
- 'product_rating_f': variant.product_tmpl_id.virtual_rating,
- 'template_id_i': variant.product_tmpl_id.id,
- 'active_s': variant.active,
- })
- # self.solr().add(docs=[document], softCommit=True)
- # documents.append(document)
- variant.solr_flag = 1
- _recommendation_solr.add(document)
- # _recommendation_solr.add(documents)
+ try:
+ document = {
+ 'id': variant.id or 0,
+ 'display_name_s': variant.display_name or '',
+ 'name_s': variant.name or '',
+ 'default_code_s': variant.default_code or '',
+ 'product_rating_f': variant.product_tmpl_id.virtual_rating or 0,
+ 'template_id_i': variant.product_tmpl_id.id or 0,
+ 'active_s': str(variant.active) or 'false',
+ 'type_s': variant.product_tmpl_id.type or '',
+ }
+ variant.write({'solr_flag': 1}) # Ensure the flag is updated correctly
+ documents.append(document)
+ catch = document
+ except Exception as e:
+ _logger.error("Failed to add document to Solr: %s", e)
+ _logger.error("Document data: %s", catch)
+ _recommendation_solr.add(documents)
+ return True