summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/solr
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-09-06 13:59:28 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-09-06 13:59:28 +0700
commit4986c63d2a6bd8e2feadbd2403a211b0b0cf405f (patch)
treeb80d2d415b887a7ab66c9d55d5a4857d34142bea /indoteknik_custom/models/solr
parentea48748650d1abe7b9c09f961eaa3762750e21be (diff)
parente07379886024a313695a56ebdd072bfd87b6626a (diff)
Merge branch 'production' into feature/voucher-group
Diffstat (limited to 'indoteknik_custom/models/solr')
-rw-r--r--indoteknik_custom/models/solr/product_pricelist_item.py32
-rw-r--r--indoteknik_custom/models/solr/product_template.py42
2 files changed, 29 insertions, 45 deletions
diff --git a/indoteknik_custom/models/solr/product_pricelist_item.py b/indoteknik_custom/models/solr/product_pricelist_item.py
index 6ab2f588..3be8c4c0 100644
--- a/indoteknik_custom/models/solr/product_pricelist_item.py
+++ b/indoteknik_custom/models/solr/product_pricelist_item.py
@@ -6,25 +6,15 @@ class ProductPricelistItem(models.Model):
@api.constrains('applied_on', 'product_id', 'base', 'base_pricelist_id', 'price_discount')
def _constrains_related_solr_field(self):
- self.update_template_solr()
- self.update_variant_solr()
+ for rec in self:
+ rec.product_id.product_tmpl_id._create_solr_queue('_sync_price_to_solr')
- def update_template_solr(self):
- updated_template_ids = []
- for rec in self:
- template = rec.product_id.product_tmpl_id
- if template.id in updated_template_ids:
- continue
-
- template._sync_price_to_solr()
- updated_template_ids.append(template.id)
-
- def update_variant_solr(self):
- updated_product_ids = []
- for rec in self:
- product = rec.product_id
- if product.id in updated_product_ids:
- continue
-
- product._sync_price_to_solr()
- updated_product_ids.append(product.id) \ No newline at end of file
+ def action_sync_to_solr(self):
+ active_ids = self.env.context.get('active_ids', [])
+
+ for pricelist_item_id in active_ids:
+ pricelist = self.env['product.pricelist.item'].browse(pricelist_item_id)
+
+ templates = self.env['product.template'].search([('id', 'in', [pricelist.product_id.product_tmpl_id.id])])
+
+ templates._create_solr_queue('_sync_price_to_solr')
diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py
index 6ae0bec2..9950c93a 100644
--- a/indoteknik_custom/models/solr/product_template.py
+++ b/indoteknik_custom/models/solr/product_template.py
@@ -104,32 +104,25 @@ class ProductTemplate(models.Model):
solr = self.solr()
for template in self:
- price_excl_after_disc = price_excl = discount = tax = 0
- flashsale_data = tier1 = tier2 = tier3 = {}
-
+ document = solr_model.get_doc('product', template.id)
+ flashsale_data = {}
+
for variant in template.product_variant_ids:
- if price_excl_after_disc == 0 or variant._get_website_price_after_disc_and_tax() < price_excl_after_disc:
- price_excl = variant._get_website_price_exclude_tax()
- price_excl_after_disc = variant._get_website_price_after_disc_and_tax()
- discount = variant._get_website_disc(0)
- tax = variant._get_website_tax()
- flashsale_data = variant._get_flashsale_price()
- # add price tiering for base price, discount, and price after discount (tier 1 - 3)
- tier1 = variant._get_pricelist_tier1()
- tier2 = variant._get_pricelist_tier2()
- tier3 = variant._get_pricelist_tier3()
-
- if template.product_variant_count == 1:
- price_excl = template.product_variant_id._get_website_price_exclude_tax()
- discount = template.product_variant_id._get_website_disc(0)
- price_excl_after_disc = template.product_variant_id._get_website_price_after_disc_and_tax()
- tax = template.product_variant_id._get_website_tax()
- flashsale_data = template.product_variant_id._get_flashsale_price()
- tier1 = template.product_variant_id._get_pricelist_tier1()
- tier2 = template.product_variant_id._get_pricelist_tier2()
- tier3 = template.product_variant_id._get_pricelist_tier3()
+ variant_flashsale = variant._get_flashsale_price()
+ variant_flashsale_price = variant_flashsale.get('flashsale_price', 0)
+ flashsale_data_price = flashsale_data.get('flashsale_price', 0)
+
+ if flashsale_data_price == 0 or (variant_flashsale_price != 0 and variant_flashsale_price < flashsale_data_price):
+ flashsale_data = variant_flashsale
+
+ price_excl = variant._get_website_price_exclude_tax()
+ 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()
- document = solr_model.get_doc('product', template.id)
document.update({
'id': template.id,
'flashsale_id_i': flashsale_data.get('flashsale_id', 0),
@@ -151,6 +144,7 @@ class ProductTemplate(models.Model):
'has_price_info_b': True
})
self.solr().add([document])
+ 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'):