summaryrefslogtreecommitdiff
path: root/indoteknik_custom
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2023-09-22 14:27:49 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2023-09-22 14:27:49 +0700
commitdd98194d70b878040169e87d3959e526f20213df (patch)
tree770700bc1490dd5fc04f581fb67904400794a642 /indoteknik_custom
parent9bb5dc696324e21fc55c2452fb8cffd557b3ed95 (diff)
add code for new pricelist and refactor code solr and pricelist
Diffstat (limited to 'indoteknik_custom')
-rw-r--r--indoteknik_custom/models/solr/product_product.py35
-rw-r--r--indoteknik_custom/models/solr/product_template.py29
2 files changed, 40 insertions, 24 deletions
diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py
index d6418ede..41af2d0e 100644
--- a/indoteknik_custom/models/solr/product_product.py
+++ b/indoteknik_custom/models/solr/product_product.py
@@ -77,18 +77,18 @@ class ProductProduct(models.Model):
for variant in self:
price_excl_after_disc = price_excl = discount = tax = 0
- flashsale_data = tier1 = tier2 = tier3 = {}
+ flashsale_data = {}
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()
+ discount = variant._get_website_disc(0)
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()
+
+ 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('variants', variant.id)
document.update({
@@ -105,14 +105,23 @@ class ProductProduct(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),
+ })
+
+ # for tier_number in [1, 2, 3, '1_v2', '2_v2', '3_v2', '4_v2', '5_v2']:
+ # tier = tier_data[tier_number]
+
+ document.update({"has_price_info_b": True})
+
self.solr().add(docs=[document], softCommit=True)
variant.change_solr_data('Ada perubahan pada harga product')
diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py
index 7d899873..b4782d1c 100644
--- a/indoteknik_custom/models/solr/product_template.py
+++ b/indoteknik_custom/models/solr/product_template.py
@@ -112,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()
@@ -125,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({
@@ -144,22 +147,26 @@ 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 solr_results(self, detail=False):
solr_model = self.env['apache.solr']