summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2023-08-22 11:23:56 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2023-08-22 11:23:56 +0700
commitb8356524ab2d381affe438a85e1662a08fcd3026 (patch)
tree957cfbb3baebc525c41bb863c9abf393775aaf98
parentf6876ff69e37169909a40059d2945e1d84be0db3 (diff)
auto sync solr
-rw-r--r--indoteknik_custom/models/apache_solr.py25
-rw-r--r--indoteknik_custom/models/product_pricelist.py4
-rwxr-xr-xindoteknik_custom/models/product_template.py4
3 files changed, 18 insertions, 15 deletions
diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py
index 8dc5dfbe..974718a5 100644
--- a/indoteknik_custom/models/apache_solr.py
+++ b/indoteknik_custom/models/apache_solr.py
@@ -4,10 +4,11 @@ from datetime import datetime, timedelta
import logging
import pysolr
import time
+from odoo.tools.config import config
_logger = logging.getLogger(__name__)
-_solr = pysolr.Solr('http://192.168.23.5:8983/solr/product/', always_commit=True, timeout=30)
-_variants_solr = pysolr.Solr('http://192.168.23.5:8983/solr/variants/', always_commit=True, timeout=30)
+_solr = pysolr.Solr('http://10.148.0.5:8983/solr/product/', always_commit=True, timeout=30)
+_variants_solr = pysolr.Solr('http://10.148.0.5:8983/solr/variants/', always_commit=True, timeout=30)
# _solr = pysolr.Solr('http://34.101.189.218:8983/solr/product/', always_commit=True, timeout=30) # for development only
@@ -20,15 +21,17 @@ class ApacheSolr(models.Model):
return solr.search(f'id:{id}').docs[0]
except:
return {}
- def connect(self, env):
- if env == 'production_template':
- return pysolr.Solr('http://192.168.23.5:8983/solr/product/', always_commit=True, timeout=30)
- elif env == 'production_variant':
- return pysolr.Solr('http://192.168.23.5:8983/solr/variants/', always_commit=True, timeout=30)
- elif env == 'local_template':
- return pysolr.Solr('http://192.168.23.5:8983/solr/product/', always_commit=True, timeout=30)
- elif env == 'local_variant':
- return pysolr.Solr('http://192.168.23.5:8983/solr/variants/', always_commit=True, timeout=30)
+
+ def connect(self, schema):
+ env = config.get('solr_env', 'development')
+
+ url = ''
+ if env == 'development':
+ url = 'http://192.168.23.5:8983/solr/'
+ elif env == 'production':
+ url = 'http://10.148.0.5:8983/solr/'
+
+ return pysolr.Solr(url + schema, always_commit=True, timeout=30)
def _update_stock_product_to_solr(self, limit=10000):
current_time = datetime.now()
diff --git a/indoteknik_custom/models/product_pricelist.py b/indoteknik_custom/models/product_pricelist.py
index 477f6645..9d2bdf82 100644
--- a/indoteknik_custom/models/product_pricelist.py
+++ b/indoteknik_custom/models/product_pricelist.py
@@ -83,7 +83,7 @@ class ProductPricelistItem(models.Model):
tier3 = template.product_variant_id._get_pricelist_tier3()
solr_model = self.env['apache.solr']
- solr = solr_model.connect('local_template')
+ solr = solr_model.connect('product')
document = solr_model.get_single_doc(solr, template.id)
document.update({
'id': template.id,
@@ -138,7 +138,7 @@ class ProductPricelistItem(models.Model):
variants_code += variant.default_code or ''+', '
solr_model = self.env['apache.solr']
- solr = solr_model.connect('local_variant')
+ solr = solr_model.connect('variants')
document = solr_model.get_single_doc(solr, product.id)
document.update({
'id': product.id,
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index 128297f1..1283a5cb 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -294,7 +294,7 @@ class ProductTemplate(models.Model):
category_id = category.id
category_name = category.name
solr_model = self.env['apache.solr']
- solr = solr_model.connect('local_template')
+ solr = solr_model.connect('product')
document = solr_model.get_single_doc(solr, template.id)
document.update({
'id': template.id,
@@ -435,7 +435,7 @@ class ProductProduct(models.Model):
category_id = category.id
category_name = category.name
solr_model = self.env['apache.solr']
- solr = solr_model.connect('local_variant')
+ solr = solr_model.connect('variants')
document = solr_model.get_single_doc(solr, variant.id)
document.update({
'id': variant.id,