summaryrefslogtreecommitdiff
path: root/indoteknik_custom
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-09-13 14:49:13 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-09-13 14:49:13 +0700
commit4cfc5c3214cc6060f978bc9e1f52533899330ee2 (patch)
tree129c9f52f41604675ce3d630e6fe3045cdd15ff6 /indoteknik_custom
parent7c67529ed27e32d32a6ddc4cd3fe296ce0d7bca2 (diff)
Update product and variant sync flashsale data
Diffstat (limited to 'indoteknik_custom')
-rw-r--r--indoteknik_custom/models/solr/__init__.py1
-rw-r--r--indoteknik_custom/models/solr/product_pricelist.py10
-rw-r--r--indoteknik_custom/models/solr/product_product.py14
-rw-r--r--indoteknik_custom/models/solr/product_template.py14
4 files changed, 27 insertions, 12 deletions
diff --git a/indoteknik_custom/models/solr/__init__.py b/indoteknik_custom/models/solr/__init__.py
index 45013d3d..16da73af 100644
--- a/indoteknik_custom/models/solr/__init__.py
+++ b/indoteknik_custom/models/solr/__init__.py
@@ -1,5 +1,6 @@
from . import apache_solr
from . import apache_solr_queue
+from . import product_pricelist
from . import product_pricelist_item
from . import product_product
from . import product_template
diff --git a/indoteknik_custom/models/solr/product_pricelist.py b/indoteknik_custom/models/solr/product_pricelist.py
new file mode 100644
index 00000000..e29baf1d
--- /dev/null
+++ b/indoteknik_custom/models/solr/product_pricelist.py
@@ -0,0 +1,10 @@
+from odoo import models, api
+
+
+class ProductPricelist(models.Model):
+ _inherit = 'product.pricelist'
+
+ @api.constrains('is_flash_sale', 'flashsale_option', 'flashsale_tag', 'banner', 'banner_mobile', 'start_date', 'end_date')
+ def _constrains_related_solr_field(self):
+ for item in self.item_ids:
+ item.product_id.product_tmpl_id._create_solr_queue('_sync_price_to_solr') \ No newline at end of file
diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py
index 7e2a99cc..93e26793 100644
--- a/indoteknik_custom/models/solr/product_product.py
+++ b/indoteknik_custom/models/solr/product_product.py
@@ -62,10 +62,11 @@ class ProductProduct(models.Model):
'category_name_s': category_name,
'category_name': category_name,
'search_rank_i': variant.product_tmpl_id.search_rank,
- 'has_product_info_b': True,
- 'search_rank_weekly_i': variant.product_tmpl_id.search_rank_weekly
+ '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
})
-
+
self.solr().add(docs=[document], softCommit=True)
variant.change_solr_data('Perubahan pada data product')
@@ -92,9 +93,12 @@ class ProductProduct(models.Model):
document = solr_model.get_doc('variants', variant.id)
document.update({
+ "id": variant.id,
"flashsale_id_i": flashsale_data.get('flashsale_id', 0),
"flashsale_tag_s": flashsale_data.get('flashsale_tag', ''),
"flashsale_name_s": flashsale_data.get('flashsale_name', ''),
+ "flashsale_start_date_s": flashsale_data.get('flashsale_start_date', ''),
+ "flashsale_end_date_s": flashsale_data.get('flashsale_end_date', ''),
"flashsale_base_price_f": flashsale_data.get('flashsale_base_price', 0),
"flashsale_discount_f": flashsale_data.get('flashsale_discount', 0),
"flashsale_price_f": flashsale_data.get('flashsale_price', 0),
@@ -102,13 +106,13 @@ class ProductProduct(models.Model):
"discount_f": discount,
"price_discount_f": price_excl_after_disc,
"tax_f": tax,
- "has_price_info_b": True,
"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)
+ "price_tier3_f": tier3.get('price_tier3', 0),
+ "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 3470621e..ea976359 100644
--- a/indoteknik_custom/models/solr/product_template.py
+++ b/indoteknik_custom/models/solr/product_template.py
@@ -91,10 +91,11 @@ class ProductTemplate(models.Model):
"variants_code_t": variant_codes,
"search_rank_i": template.search_rank,
"search_rank_weekly_i": template.search_rank_weekly,
- 'has_product_info_b': True,
"category_id_i": category_id,
"category_name_s": category_name,
- "category_name": category_name
+ "category_name": category_name,
+ "description_t": template.website_description or '',
+ 'has_product_info_b': True,
})
self.solr().add(docs=[document], softCommit=True)
@@ -106,13 +107,8 @@ class ProductTemplate(models.Model):
def _sync_price_to_solr(self):
solr_model = self.env['apache.solr']
- solr = self.solr()
for template in self:
- document = {
- "id": template.id,
- "has_price_info_b": True
- }
flashsale_data = {}
for variant in template.product_variant_ids:
@@ -133,9 +129,12 @@ class ProductTemplate(models.Model):
document = solr_model.get_doc('product', template.id)
document.update({
+ "id": template.id,
"flashsale_id_i": flashsale_data.get('flashsale_id', 0),
"flashsale_tag_s": flashsale_data.get('flashsale_tag', ''),
"flashsale_name_s": flashsale_data.get('flashsale_name', ''),
+ "flashsale_start_date_s": flashsale_data.get('flashsale_start_date', ''),
+ "flashsale_end_date_s": flashsale_data.get('flashsale_end_date', ''),
"flashsale_base_price_f": flashsale_data.get('flashsale_base_price', 0),
"flashsale_discount_f": flashsale_data.get('flashsale_discount', 0),
"flashsale_price_f": flashsale_data.get('flashsale_price', 0),
@@ -149,6 +148,7 @@ class ProductTemplate(models.Model):
"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
})
self.solr().add(docs=[document], softCommit=True)