summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/apache_solr.py
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-05-04 12:12:17 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-05-04 12:12:17 +0700
commit39883f829f246f06d981e61431d12c3ef812e202 (patch)
tree72c127935933a149bee42d936d1ca499dfd6aa4e /indoteknik_custom/models/apache_solr.py
parent17ec32faaa55f9fd1457622f14cab0b770f64afc (diff)
parent1d2a045da635445f5331132b1713c392ecb905fa (diff)
Merge branch 'release' of bitbucket.org:altafixco/indoteknik-addons into release
Diffstat (limited to 'indoteknik_custom/models/apache_solr.py')
-rw-r--r--indoteknik_custom/models/apache_solr.py32
1 files changed, 29 insertions, 3 deletions
diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py
index ebe516a0..b59f95cc 100644
--- a/indoteknik_custom/models/apache_solr.py
+++ b/indoteknik_custom/models/apache_solr.py
@@ -1,19 +1,45 @@
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:
+ rating = {"set":template.virtual_rating}
+ document = {
+ "id": template.id,
+ "product_rating_f": 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...')
@@ -73,7 +99,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,