summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/apache_solr.py
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-05-09 14:47:45 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-05-09 14:47:45 +0700
commit2262f57b0b56b7aa1535600de20b1a1dd611a991 (patch)
tree0de5a4c64b6877c801de5e95e6caa6f89e806889 /indoteknik_custom/models/apache_solr.py
parentc50611bce3b2a57a7436f3f8b921207e36ff7f27 (diff)
parentd97277a0847bc57c0bc704c5ea62f75fadb461dc (diff)
Merge branch 'release' into staging
Diffstat (limited to 'indoteknik_custom/models/apache_solr.py')
-rw-r--r--indoteknik_custom/models/apache_solr.py35
1 files changed, 31 insertions, 4 deletions
diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py
index 3709e88a..b59f95cc 100644
--- a/indoteknik_custom/models/apache_solr.py
+++ b/indoteknik_custom/models/apache_solr.py
@@ -1,20 +1,46 @@
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)
+ # _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...')
query = ["&","&",("type","=","product"),("active","=",True),"|",("solr_flag","=",0),("solr_flag","=",2)]
@@ -52,6 +78,7 @@ class ApacheSolr(models.Model):
variants_name += variant.display_name or ''+', '
variants_code += variant.default_code or ''+', '
else:
+ variants_name = template.display_name
price_excl = template.product_variant_id._get_website_price_exclude_tax()
discount = template.product_variant_id._get_website_disc(0)
price_excl_after_disc = template.product_variant_id._get_website_price_after_disc_and_tax()
@@ -72,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,