summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/solr/product_template.py
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-08-26 12:13:28 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-08-26 12:13:28 +0700
commit315b832420eb8314e809b1c0f549304d423b45f3 (patch)
treebf31b1f24ffa511308bec829b7e57ff09eabd294 /indoteknik_custom/models/solr/product_template.py
parent52f4b12c0b211f958c2704346d7da24d1d4767c6 (diff)
Create apache solr queue and implement to product.template and website.categories.homepage
Diffstat (limited to 'indoteknik_custom/models/solr/product_template.py')
-rw-r--r--indoteknik_custom/models/solr/product_template.py48
1 files changed, 28 insertions, 20 deletions
diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py
index 6089adda..ba670a81 100644
--- a/indoteknik_custom/models/solr/product_template.py
+++ b/indoteknik_custom/models/solr/product_template.py
@@ -15,16 +15,31 @@ class ProductTemplate(models.Model):
def solr(self):
return self.env['apache.solr'].connect('product')
+ def _create_solr_queue(self, function_name):
+ for rec in self:
+ self.env['apache.solr.queue'].create_unique({
+ 'res_model': self._name,
+ 'res_id': rec.id,
+ 'function_name': function_name
+ })
+
@api.constrains('active')
+ def _create_solr_queue_sync_active(self):
+ self._create_solr_queue('_sync_active_template_solr')
+
+ @api.constrains('name', 'default_code', 'weight', 'x_manufacture', 'public_categ_ids', 'search_rank', 'search_rank_weekly', 'image_1920')
+ def _create_solr_queue_sync_product_template(self):
+ self._create_solr_queue('_sync_product_template_to_solr')
+
+ def action_sync_to_solr(self):
+ template_ids = self.env.context.get('active_ids', [])
+ templates = self.search([('id', 'in', template_ids)])
+ templates._create_solr_queue('_sync_product_template_to_solr')
+
def _sync_active_template_solr(self):
for template in self:
if not template.active or template.type != 'product':
- self.solr().delete(template.id)
-
- variant_ids = [x.id for x in template.product_variant_ids]
- template.product_variant_ids.solr().delete(variant_ids)
-
- self.solr().commit()
+ template._sync_delete_solr()
else:
template._sync_product_template_to_solr()
template._sync_price_to_solr()
@@ -32,16 +47,6 @@ class ProductTemplate(models.Model):
products = self.env['product.product'].search([('product_tmpl_id', '=', template.id), ('active', 'in', [True, False])])
products._sync_variants_to_solr()
- @api.constrains(
- 'name',
- 'default_code',
- 'weight',
- 'x_manufacture',
- 'public_categ_ids',
- 'search_rank',
- 'search_rank_weekly',
- 'image_1920'
- )
def _sync_product_template_to_solr(self):
solr_model = self.env['apache.solr']
@@ -152,7 +157,10 @@ class ProductTemplate(models.Model):
self.solr().commit()
- def sync_to_solr(self):
- template_ids = self.env.context.get('active_ids', [])
- templates = self.search([('id', 'in', template_ids)])
- templates._sync_product_template_to_solr() \ No newline at end of file
+ def _sync_delete_solr(self):
+ for rec in self:
+ self.solr().delete(rec.id)
+ for variant in rec.product_variant_ids:
+ variant._sync_delete_solr()
+ self.solr().optimize()
+ self.solr().commit() \ No newline at end of file