From d1b86303b0934c9f6348e7016822d449349540d3 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 6 Apr 2023 13:27:48 +0700 Subject: integrate flashsale to solr for new website --- indoteknik_custom/models/apache_solr.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models/apache_solr.py') diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py index 3ed431ef..0a403b6b 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)) -- cgit v1.2.3 From d753a2b681dc14e47551e4525fddb23820b841af Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 11 Apr 2023 14:02:31 +0700 Subject: change to solr production --- indoteknik_custom/models/apache_solr.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models/apache_solr.py') diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py index 0a403b6b..fe31906f 100644 --- a/indoteknik_custom/models/apache_solr.py +++ b/indoteknik_custom/models/apache_solr.py @@ -13,8 +13,8 @@ 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) + _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...') query = ["&","&",("type","=","product"),("active","=",True),"|",("solr_flag","=",0),("solr_flag","=",2)] -- cgit v1.2.3 From fe8f1c997224aa2c6cdd01e14562668d7cbffaf5 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 12 Apr 2023 15:33:33 +0700 Subject: prepare for tiering price api solr --- indoteknik_custom/models/apache_solr.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'indoteknik_custom/models/apache_solr.py') diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py index fe31906f..ee166002 100644 --- a/indoteknik_custom/models/apache_solr.py +++ b/indoteknik_custom/models/apache_solr.py @@ -13,8 +13,8 @@ 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) + # _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...') query = ["&","&",("type","=","product"),("active","=",True),"|",("solr_flag","=",0),("solr_flag","=",2)] @@ -26,24 +26,28 @@ class ApacheSolr(models.Model): counter += 1 price_excl_after_disc = price_excl = discount = tax = 0 variants_name = variants_code = '' + flashsale_data = tier1 = tier2 = tier3 = {} 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: + if price_excl_after_disc == 0 or variant._get_website_price_after_disc_and_tax() < price_excl_after_disc: price_excl = variant._get_website_price_exclude_tax() price_excl_after_disc = variant._get_website_price_after_disc_and_tax() discount = variant._get_website_disc(0) tax = variant._get_website_tax() - elif variant._get_website_price_after_disc_and_tax() < price_excl_after_disc: - price_excl_after_disc = variant._get_website_price_after_disc_and_tax() - price_excl = variant._get_website_price_exclude_tax() - discount = variant._get_website_disc(0) - tax = variant._get_website_tax() + flashsale_data = variant._get_flashsale_price() + # add price tiering for base price, discount, and price after discount (tier 1 - 3) + tier1 = variant._get_pricelist_tier1() + tier2 = variant._get_pricelist_tier2() + tier3 = variant._get_pricelist_tier3() else: price_excl_after_disc = price_excl_after_disc price_excl = price_excl discount = discount tax = tax + flashsale_data = flashsale_data + tier1 = tier1 + tier2 = tier2 + tier3 = tier3 variants_name += variant.display_name or ''+', ' variants_code += variant.default_code or ''+', ' else: @@ -52,6 +56,9 @@ class ApacheSolr(models.Model): 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() + tier1 = template.product_variant_id._get_pricelist_tier1() + tier2 = template.product_variant_id._get_pricelist_tier2() + tier3 = template.product_variant_id._get_pricelist_tier3() category_id = '' category_name = '' @@ -91,6 +98,12 @@ class ApacheSolr(models.Model): '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, + 'discount_tier1_f': tier1['discount_tier1'] or 0, + 'price_tier1_f': tier1['price_tier1'] or 0, + 'discount_tier2_f': tier2['discount_tier2'] or 0, + 'price_tier2_f': tier2['price_tier2'] or 0, + 'discount_tier3_f': tier3['discount_tier3'] or 0, + 'price_tier3_f': tier3['price_tier3'] or 0 } documents.append(document) template.solr_flag = 1 -- cgit v1.2.3