summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-05-09 10:53:45 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-05-09 10:53:45 +0700
commit1dd7e48bfd5e72a90481d5302d6b0a3d90b11e65 (patch)
tree33750633428a4b43b51a2850513e3f74d198d7dd
parentd97277a0847bc57c0bc704c5ea62f75fadb461dc (diff)
set product rating and stock only for solr
-rw-r--r--indoteknik_custom/models/apache_solr.py36
1 files changed, 31 insertions, 5 deletions
diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py
index b59f95cc..bea9b0c5 100644
--- a/indoteknik_custom/models/apache_solr.py
+++ b/indoteknik_custom/models/apache_solr.py
@@ -7,32 +7,58 @@ import time
_logger = logging.getLogger(__name__)
_solr = pysolr.Solr('http://10.148.0.5:8983/solr/product/', always_commit=True, timeout=30)
+# _solr = pysolr.Solr('http://34.101.189.218:8983/solr/products/', always_commit=True, timeout=30) # for development only
class ApacheSolr(models.Model):
_name = 'apache.solr'
_order = 'id desc'
+ def _update_stock_product_to_solr(self, limit=10000):
+ current_time = datetime.now()
+ delta_time = current_time - timedelta(days=3)
+
+ current_time = current_time.strftime('%Y-%m-%d %H:%M:%S')
+ delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S')
+
+ query = [('__last_update', '<', delta_time),]
+ # query = [('product_variant_id.id', '=', 204903)]
+ stocks = self.env['stock.vendor'].search(query, limit=limit)
+ documents = []
+ for stock in stocks:
+ stock_total = float(stock.product_variant_id.product_tmpl_id.qty_stock_vendor)
+ dict_stock = dict({"set": stock_total})
+ document = {
+ "id": int(stock.product_variant_id.product_tmpl_id.id),
+ "stock_total_f": dict_stock
+ }
+ documents.append(document)
+ _logger.info("[SYNC_PRODUCT_STOCK_TO_SOLR] Success Set to solr product %s" % stock.product_variant_id.product_tmpl_id.id)
+ _solr.add(documents)
+
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([
+ query = [
'&','&',
('type', '=', 'product'),
('active', '=', True),
'|',
('last_calculate_rating', '=', False),
('last_calculate_rating', '<', delta_time),
- ], limit=limit)
+ ]
+ # query = [('id', '=', 97942)]
+ templates = self.env['product.template'].search(query, limit=limit)
documents=[]
for template in templates:
- rating = {"set":template.virtual_rating}
+ rating = float(template.virtual_rating)
+ dict_rating = dict({"set":rating})
document = {
"id": template.id,
- "product_rating_f": rating
+ "product_rating_f": dict_rating
}
documents.append(document)
template.last_calculate_rating = current_time
@@ -40,10 +66,10 @@ class ApacheSolr(models.Model):
_solr.add(documents)
def _sync_product_to_solr(self, limit=500):
- # _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)]
+ # query = [('id', '=', 97942)]
templates = self.env['product.template'].search(query, limit=limit)
documents = []