From 515addbceca9df25b3aaf440e8687286620d603a Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 3 May 2023 15:09:11 +0700 Subject: update virtual product rating to solr --- indoteknik_custom/models/apache_solr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models/apache_solr.py') diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py index ebe516a0..72584a8f 100644 --- a/indoteknik_custom/models/apache_solr.py +++ b/indoteknik_custom/models/apache_solr.py @@ -73,7 +73,7 @@ class ApacheSolr(models.Model): 'display_name_s': template.display_name, 'name_s': template.name, 'default_code_s': template.default_code or '', - 'product_rating_f': template.product_rating, + 'product_rating_f': template.virtual_rating, 'product_id_i': template.id, 'image_s': self.env['ir.attachment'].api_image('product.template', 'image_512', template.id), 'price_f': price_excl, -- cgit v1.2.3 From 1b31655209df1642d5c6c5e1106c14debddaddfc Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 3 May 2023 15:52:28 +0700 Subject: add update product rating to solr --- indoteknik_custom/models/apache_solr.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models/apache_solr.py') diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py index 72584a8f..04f83532 100644 --- a/indoteknik_custom/models/apache_solr.py +++ b/indoteknik_custom/models/apache_solr.py @@ -1,19 +1,44 @@ from odoo import models, api, fields from odoo.exceptions import UserError -from datetime import datetime +from datetime import datetime, timedelta import logging import pysolr import time _logger = logging.getLogger(__name__) +_solr = pysolr.Solr('http://10.148.0.5:8983/solr/product/', always_commit=True, timeout=30) class ApacheSolr(models.Model): _name = 'apache.solr' _order = 'id desc' + def _update_rating_product_to_solr(self, limit=1000): + current_time = datetime.now() + delta_time = current_time - timedelta(days=30) + + current_time = current_time.strftime('%Y-%m-%d %H:%M:%S') + delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') + templates = self.env['product.template'].search([ + '&','&', + ('type', '=', 'product'), + ('active', '=', True), + '|', + ('last_calculate_rating', '=', False), + ('last_calculate_rating', '<', delta_time), + ], limit=limit) + documents=[] + for template in templates: + document = { + 'id': template.id, + 'product_rating_f': {'set':template.virtual_rating}, + } + documents.append(document) + template.last_calculate_rating = current_time + _logger.info("[SYNC_PRODUCT_RATING_TO_SOLR] Success Set to solr product %s" % template.id) + _solr.add(documents) + def _sync_product_to_solr(self, limit=500): - _solr = pysolr.Solr('http://10.148.0.5:8983/solr/product/', always_commit=True, timeout=30) # _solr = pysolr.Solr('http://192.168.23.5:8983/solr/product/', always_commit=True, timeout=30) start_time = time.time() _logger.info('run sync to solr...') -- cgit v1.2.3 From afad42a0a2c19339158499a259bef5bb7062f387 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 3 May 2023 17:37:04 +0700 Subject: bug fix update rating to solr --- indoteknik_custom/models/apache_solr.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models/apache_solr.py') diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py index 04f83532..ce6a4180 100644 --- a/indoteknik_custom/models/apache_solr.py +++ b/indoteknik_custom/models/apache_solr.py @@ -30,8 +30,8 @@ class ApacheSolr(models.Model): documents=[] for template in templates: document = { - 'id': template.id, - 'product_rating_f': {'set':template.virtual_rating}, + "id": template.id, + "product_rating_f": {"set":template.virtual_rating} } documents.append(document) template.last_calculate_rating = current_time -- cgit v1.2.3 From 1d2a045da635445f5331132b1713c392ecb905fa Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 4 May 2023 08:57:48 +0700 Subject: change virtual rating to dict from string --- indoteknik_custom/models/apache_solr.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models/apache_solr.py') diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py index ce6a4180..b59f95cc 100644 --- a/indoteknik_custom/models/apache_solr.py +++ b/indoteknik_custom/models/apache_solr.py @@ -29,9 +29,10 @@ class ApacheSolr(models.Model): ], limit=limit) documents=[] for template in templates: + rating = {"set":template.virtual_rating} document = { "id": template.id, - "product_rating_f": {"set":template.virtual_rating} + "product_rating_f": rating } documents.append(document) template.last_calculate_rating = current_time -- cgit v1.2.3