summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/apache_solr.py
diff options
context:
space:
mode:
authorStephan Christianus <stephanchrst@gmail.com>2023-04-11 09:16:13 +0000
committerStephan Christianus <stephanchrst@gmail.com>2023-04-11 09:16:13 +0000
commit4e1b9b2ab230e24e594008340690c69c35b42037 (patch)
tree07b4aba9bc8c61cbbc81ebcace23b4e142c37780 /indoteknik_custom/models/apache_solr.py
parenta854c5cca6e374589449e54a2fb9efb7f2c24955 (diff)
parentd753a2b681dc14e47551e4525fddb23820b841af (diff)
Merged in flashsale-solr (pull request #30)
Flashsale solr
Diffstat (limited to 'indoteknik_custom/models/apache_solr.py')
-rw-r--r--indoteknik_custom/models/apache_solr.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py
index 3ed431ef..fe31906f 100644
--- a/indoteknik_custom/models/apache_solr.py
+++ b/indoteknik_custom/models/apache_solr.py
@@ -13,9 +13,10 @@ class ApacheSolr(models.Model):
_order = 'id desc'
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...')
- solr = pysolr.Solr('http://10.148.0.5:8983/solr/product/', always_commit=True, timeout=30)
query = ["&","&",("type","=","product"),("active","=",True),"|",("solr_flag","=",0),("solr_flag","=",2)]
templates = self.env['product.template'].search(query, limit=limit)
@@ -27,6 +28,7 @@ class ApacheSolr(models.Model):
variants_name = variants_code = ''
if template.product_variant_count > 1:
for variant in template.product_variant_ids:
+ flashsale_data = variant._get_flashsale_price()
if price_excl_after_disc == 0:
price_excl = variant._get_website_price_exclude_tax()
price_excl_after_disc = variant._get_website_price_after_disc_and_tax()
@@ -49,6 +51,7 @@ class ApacheSolr(models.Model):
discount = template.product_variant_id._get_website_disc(0)
price_excl_after_disc = template.product_variant_id._get_website_price_after_disc_and_tax()
tax = template.product_variant_id._get_website_tax()
+ flashsale_data = template.product_variant_id._get_flashsale_price()
category_id = ''
category_name = ''
@@ -82,13 +85,18 @@ class ApacheSolr(models.Model):
'variants_name_t': variants_name,
'variants_code_t': variants_code,
'search_rank_i': template.search_rank,
- 'search_rank_weekly_i': template.search_rank_weekly
+ 'search_rank_weekly_i': template.search_rank_weekly,
+ 'flashsale_id_i': flashsale_data['flashsale_id'] or 0,
+ 'flashsale_name_s': flashsale_data['flashsale_name'] or '',
+ 'flashsale_base_price_f': flashsale_data['flashsale_base_price'] or 0,
+ 'flashsale_discount_f': flashsale_data['flashsale_discount'] or 0,
+ 'flashsale_price_f': flashsale_data['flashsale_price'] or 0,
}
documents.append(document)
template.solr_flag = 1
# add counter for monitoring
_logger.info('[SYNC_PRODUCT_TO_SOLR] %s/%i' % (counter, limit))
_logger.info('[SYNC_PRODUCT_TO_SOLR] Success add to solr product %s' % template.id)
- solr.add(documents)
+ _solr.add(documents)
end_time = time.time()
_logger.info("[SYNC_PRODUCT_TO_SOLR] Finish task add to solr. Time taken: {:.6f} seconds".format(end_time - start_time))