summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/solr/product_template.py
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_custom/models/solr/product_template.py')
-rw-r--r--indoteknik_custom/models/solr/product_template.py76
1 files changed, 40 insertions, 36 deletions
diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py
index ea976359..b4782d1c 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'):
@@ -110,6 +112,8 @@ class ProductTemplate(models.Model):
for template in self:
flashsale_data = {}
+ price_excl = price_excl_after_disc = discount = tax = 0
+ tier_data = {}
for variant in template.product_variant_ids:
variant_flashsale = variant._get_flashsale_price()
@@ -123,9 +127,10 @@ class ProductTemplate(models.Model):
price_excl_after_disc = variant._get_website_price_after_disc_and_tax()
discount = variant._get_website_disc(0)
tax = variant._get_website_tax()
- tier1 = variant._get_pricelist_tier1()
- tier2 = variant._get_pricelist_tier2()
- tier3 = variant._get_pricelist_tier3()
+
+ price_excl_v2 = variant._v2_get_website_price_exclude_tax()
+ price_excl_after_disc_v2 = variant._v2_get_website_price_after_disc_and_tax()
+ tax_v2 = variant._v2_get_website_tax()
document = solr_model.get_doc('product', template.id)
document.update({
@@ -142,28 +147,27 @@ class ProductTemplate(models.Model):
"discount_f": discount,
"price_discount_f": price_excl_after_disc,
"tax_f": tax,
- "discount_tier1_f": tier1.get('discount_tier1', 0),
- "price_tier1_f": tier1.get('price_tier1', 0),
- "discount_tier2_f": tier2.get('discount_tier2', 0),
- "price_tier2_f": tier2.get('price_tier2', 0),
- "discount_tier3_f": tier3.get('discount_tier3', 0),
- "price_tier3_f": tier3.get('price_tier3', 0),
- "has_price_info_b": True
+ "price_v2_f": price_excl_v2,
+ "price_discount_v2_f": price_excl_after_disc_v2,
+ "tax_v2_f": tax_v2,
})
+ for tier_number in [1, 2, 3, '1_v2', '2_v2', '3_v2', '4_v2', '5_v2']:
+ tier = variant._get_pricelist_tier(tier_number)
+ document.update({
+ f"discount_tier{tier_number}_f": tier.get(f'discount_tier{tier_number}', 0),
+ f"price_tier{tier_number}_f": tier.get(f'price_tier{tier_number}', 0),
+ })
+
+ document.update({"has_price_info_b": True})
+
self.solr().add(docs=[document], softCommit=True)
template.product_variant_ids._sync_price_to_solr()
template.change_solr_data('Ada perubahan pada harga product')
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