summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/solr
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2023-10-03 07:05:14 +0000
committerIT Fixcomart <it@fixcomart.co.id>2023-10-03 07:05:14 +0000
commit19e0be70679ed862453fedeba14fb4cdf02232e9 (patch)
tree69b578c47cc17ae477c58d8bda718d823b998b20 /indoteknik_custom/models/solr
parent78f205302c35cab2512971d64c8152aab2dcfa95 (diff)
parentd238f43442cc27db0d0c05bba99b42b41eaadf54 (diff)
Merged in production (pull request #128)
Production
Diffstat (limited to 'indoteknik_custom/models/solr')
-rw-r--r--indoteknik_custom/models/solr/apache_solr_queue.py11
-rw-r--r--indoteknik_custom/models/solr/product_product.py2
-rw-r--r--indoteknik_custom/models/solr/product_template.py23
3 files changed, 16 insertions, 20 deletions
diff --git a/indoteknik_custom/models/solr/apache_solr_queue.py b/indoteknik_custom/models/solr/apache_solr_queue.py
index 6a5b480f..8dd7c273 100644
--- a/indoteknik_custom/models/solr/apache_solr_queue.py
+++ b/indoteknik_custom/models/solr/apache_solr_queue.py
@@ -1,5 +1,5 @@
from odoo import models, fields
-from datetime import datetime
+from datetime import datetime, timedelta
import logging, time
@@ -72,3 +72,12 @@ class ApacheSolrQueue(models.Model):
if count == 0:
self.create(payload)
+ def delete_weekly_solr(self, limit=500):
+ solr = self.search([
+ ('execute_status', '=', 'success'),
+ ('execute_date', '>=', (datetime.utcnow() - timedelta(days=7))),
+ ], limit=limit)
+ for rec in solr:
+ rec.unlink()
+
+
diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py
index 41af2d0e..16135e5e 100644
--- a/indoteknik_custom/models/solr/product_product.py
+++ b/indoteknik_custom/models/solr/product_product.py
@@ -63,7 +63,7 @@ class ProductProduct(models.Model):
'search_rank_weekly_i': variant.product_tmpl_id.search_rank_weekly,
'attributes': [x.name for x in variant.product_template_attribute_value_ids],
'has_product_info_b': True,
- 'publish_b': variant.product_tmpl_id.publish,
+ 'publish_b': variant.product_tmpl_id.active and variant.product_tmpl_id.type == 'product',
})
self.solr().add(docs=[document], softCommit=True)
diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py
index b4782d1c..e39530a7 100644
--- a/indoteknik_custom/models/solr/product_template.py
+++ b/indoteknik_custom/models/solr/product_template.py
@@ -23,23 +23,7 @@ class ProductTemplate(models.Model):
'function_name': function_name
})
- @api.constrains('active', 'type')
- def constrains_active(self):
- for template in self:
- template.publish = template.active and template.type == 'product'
- self._create_solr_queue('_sync_product_template_to_solr')
-
- @api.constrains('publish')
- def constrains_publish(self):
- for template in self:
- if template.active and template.type == 'product':
- continue
- template.product_variant_ids.publish = template.publish
- self._create_solr_queue('_sync_product_template_to_solr')
-
- constrains_active._priority = 1
-
- @api.constrains('name', 'default_code', 'weight', 'x_manufacture', 'public_categ_ids', 'search_rank', 'search_rank_weekly', 'image_1920')
+ @api.constrains('name', 'default_code', 'weight', 'x_manufacture', 'public_categ_ids', 'search_rank', 'search_rank_weekly', 'image_1920', 'active')
def _create_solr_queue_sync_product_template(self):
self._create_solr_queue('_sync_product_template_to_solr')
@@ -54,6 +38,9 @@ class ProductTemplate(models.Model):
product._create_solr_queue('_sync_price_to_solr')
product.solr_flag = 1
+ def _sync_product_stock_to_solr(self):
+ self._sync_product_template_to_solr()
+
def _sync_product_template_to_solr(self):
solr_model = self.env['apache.solr']
@@ -93,7 +80,7 @@ class ProductTemplate(models.Model):
"category_name": category_name,
"description_t": template.website_description or '',
'has_product_info_b': True,
- 'publish_b': template.publish
+ 'publish_b': template.active and template.type == 'product'
})
self.solr().add(docs=[document], softCommit=True)