diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2023-09-19 13:23:57 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2023-09-19 13:23:57 +0700 |
| commit | 1ea160934c67dd9e4ff2a160385f79cd5ad24946 (patch) | |
| tree | fb8f697f7351f66aa3d092aa9fdc0abb75a1a918 /indoteknik_custom/models/solr/product_template.py | |
| parent | 074a3fef721e3894cef359390281f59b21e8b9c2 (diff) | |
add field email to so and sync email so with email partner_id, add field publish to product
Diffstat (limited to 'indoteknik_custom/models/solr/product_template.py')
| -rw-r--r-- | indoteknik_custom/models/solr/product_template.py | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index ea976359..7d899873 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -23,9 +23,21 @@ class ProductTemplate(models.Model): 'function_name': function_name }) - @api.constrains('active') - def _create_solr_queue_sync_active(self): - self._create_solr_queue('_sync_active_template_solr') + @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') def _create_solr_queue_sync_product_template(self): @@ -42,25 +54,10 @@ class ProductTemplate(models.Model): product._create_solr_queue('_sync_price_to_solr') product.solr_flag = 1 - def _sync_active_template_solr(self): - for template in self: - if not template.active or template.type != 'product': - template._sync_delete_solr() - else: - template._sync_product_template_to_solr() - template._sync_price_to_solr() - - products = self.env['product.product'].search( - [('product_tmpl_id', '=', template.id), ('active', 'in', [True, False])]) - products._sync_variants_to_solr() - def _sync_product_template_to_solr(self): solr_model = self.env['apache.solr'] for template in self: - if not template.active or template.type != 'product': - continue - variant_names = ', '.join([x.display_name or '' for x in template.product_variant_ids]) variant_codes = ', '.join([x.default_code or '' for x in template.product_variant_ids]) @@ -96,10 +93,15 @@ class ProductTemplate(models.Model): "category_name": category_name, "description_t": template.website_description or '', 'has_product_info_b': True, + 'publish_b': template.publish }) self.solr().add(docs=[document], softCommit=True) - template.product_variant_ids._sync_variants_to_solr() + products = self.env['product.product'].search([ + ('product_tmpl_id', '=', template.id), + ('active', 'in', [True, False]) + ]) + products._sync_variants_to_solr() self.change_solr_data('Perubahan pada data product') if not document.get('has_price_info_b'): @@ -158,12 +160,7 @@ class ProductTemplate(models.Model): if not document.get('has_product_info_b'): template._sync_product_template_to_solr() - 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() - + def solr_results(self, detail=False): solr_model = self.env['apache.solr'] pricelist = self.env.user_pricelist |
