diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2024-06-18 16:47:30 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2024-06-18 16:47:30 +0700 |
| commit | 4b75a370a2b16d21eeb3c71007885eae4dd4112c (patch) | |
| tree | 13e80e98a14c600a156638e6137fba4fca7263db | |
| parent | 2ca257f21bd5087604e3d0110eff16e40b0d8f83 (diff) | |
bf
| -rw-r--r-- | indoteknik_custom/models/solr/apache_solr.py | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/indoteknik_custom/models/solr/apache_solr.py b/indoteknik_custom/models/solr/apache_solr.py index 0b1bd821..1c4b7114 100644 --- a/indoteknik_custom/models/solr/apache_solr.py +++ b/indoteknik_custom/models/solr/apache_solr.py @@ -296,24 +296,24 @@ class ApacheSolr(models.Model): def _solr_sync_recommendation(self, limit=100): variants = self.env['product.product'].search([('solr_flag', '=', 2)], limit=limit) documents = [] - document = {} + catch = {} for variant in variants: - if variant.product_tmpl_id: # Check if product_tmpl_id exists - 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': variant.active, - 'type_s': variant.product_tmpl_id.type or '' - } - variant.write({'solr_flag': 1}) # Ensure the flag is updated correctly - documents.append(document) - except Exception as e: - _logger.error("Failed to add document to Solr: %s", e) - _logger.error("Document data: %s", document) + 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': 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 |
