summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2023-11-24 17:07:53 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2023-11-24 17:07:53 +0700
commit1941896aebea3908b1763a4bd4244e5ac7e78bc6 (patch)
treee356fbd2e7d3b37d2230eb6b5b43e05f64b89fb7
parent1a27ae4f9ec137d7af69175afb67a094873738b9 (diff)
add constrains active on template and variant
-rw-r--r--indoteknik_custom/models/solr/product_product.py8
-rw-r--r--indoteknik_custom/models/solr/product_template.py8
2 files changed, 14 insertions, 2 deletions
diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py
index ebfa8e65..fe2a08dc 100644
--- a/indoteknik_custom/models/solr/product_product.py
+++ b/indoteknik_custom/models/solr/product_product.py
@@ -29,6 +29,12 @@ class ProductProduct(models.Model):
product.product_tmpl_id._create_solr_queue('_sync_price_to_solr')
product.solr_flag = 1
+ @api.constrains('active')
+ def _constrains_active(self):
+ for rec in self:
+ if not rec.active:
+ rec.unpublished = True
+
def _sync_variants_to_solr(self):
solr_model = self.env['apache.solr']
@@ -65,7 +71,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': not variant.unpublished or not variant.active,
+ 'publish_b': not variant.unpublished,
'qty_sold_f': variant.qty_sold
})
diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py
index 123a95ac..fd3357fd 100644
--- a/indoteknik_custom/models/solr/product_template.py
+++ b/indoteknik_custom/models/solr/product_template.py
@@ -28,6 +28,12 @@ class ProductTemplate(models.Model):
def _create_solr_queue_sync_product_template(self):
self._create_solr_queue('_sync_product_template_to_solr')
+ @api.constrains('active')
+ def _constrains_active(self):
+ for rec in self:
+ if not rec.active:
+ rec.unpublished = True
+
def action_sync_to_solr(self):
template_ids = self.env.context.get('active_ids', [])
templates = self.search([('id', 'in', template_ids)])
@@ -82,7 +88,7 @@ class ProductTemplate(models.Model):
"category_name": category_name,
"description_t": template.website_description or '',
'has_product_info_b': True,
- 'publish_b': not template.unpublished or not template.active,
+ 'publish_b': not template.unpublished,
"qty_sold_f": template.qty_sold
})