summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-05-03 15:52:28 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-05-03 15:52:28 +0700
commit1b31655209df1642d5c6c5e1106c14debddaddfc (patch)
treee8dbd350c73cfdd6334e7122fa1aed2ffd7e9f67
parent58395396f83290cd36b7faf693c0efafc726ad61 (diff)
add update product rating to solr
-rw-r--r--indoteknik_custom/models/apache_solr.py29
1 files changed, 27 insertions, 2 deletions
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...')