diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-09-20 15:06:17 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-09-20 15:06:17 +0700 |
| commit | 79bf9729d10c8fb37ef9071ab6df2b6644ddea49 (patch) | |
| tree | 6226da5e38ad44673a1bb5d7d4e2b0fd5df1fada /indoteknik_custom/models/solr/product_template.py | |
| parent | eb7661705303a64c97e84061b53d48d5c46f6293 (diff) | |
| parent | d2bb21ae878db2a3b77dbb3341046c9d12ba1de5 (diff) | |
Merge branch 'production' into iman/new-register
# Conflicts:
# indoteknik_custom/models/res_users.py
Diffstat (limited to 'indoteknik_custom/models/solr/product_template.py')
| -rw-r--r-- | indoteknik_custom/models/solr/product_template.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index 6f76c529..d8dec47c 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -1,4 +1,5 @@ from datetime import datetime +from bs4 import BeautifulSoup from odoo import api, fields, models @@ -78,6 +79,9 @@ class ProductTemplate(models.Model): is_in_bu = bool(stock_quant) + cleaned_desc = BeautifulSoup(template.website_description or '', "html.parser").get_text() + website_description = template.website_description if cleaned_desc else '' + document = solr_model.get_doc('product', template.id) document.update({ "id": template.id, @@ -101,9 +105,11 @@ class ProductTemplate(models.Model): "search_rank_i": template.search_rank, "search_rank_weekly_i": template.search_rank_weekly, "category_id_ids": category_ids, # ID kategori sebagai string yang dipisahkan koma + "category_parent_ids": self.get_category_hierarchy_ids(category_ids), # ID kategori sebagai string yang dipisahkan koma "category_name_s": ', '.join(category_names), # Nama kategori sebagai string yang dipisahkan koma "category_name": category_names, # Nama kategori sebagai list "description_t": template.website_description or '', + "description_clean_t": cleaned_desc or '', 'has_product_info_b': True, 'publish_b': not template.unpublished, 'sni_b': template.unpublished, @@ -127,6 +133,36 @@ class ProductTemplate(models.Model): if not document.get('has_price_info_b'): template._sync_price_to_solr() + def get_category_hierarchy_ids(self, category_id): + """ + Function to get category hierarchy IDs including the category itself and its parents. + + Args: + category_id (int): The ID of the category you want to retrieve. + env (Environment): The Odoo environment. + + Returns: + list: A list of IDs for the category and its parents. + """ + category_ids = [] + + def traverse_category(cat_id): + # Retrieve category object based on ID + category = self.env['product.public.category'].browse(cat_id) + + # Add the current category ID to the list + category_ids.append(category.id) + + # If there is a parent category, traverse upwards + if category.parent_id: + traverse_category(category.parent_id.id) + + # Start traversal from the initial category + traverse_category(category_id) + + # Reverse the list to get the hierarchy from top level to the current level + return list(reversed(category_ids)) + def _sync_price_to_solr(self): solr_model = self.env['apache.solr'] TIER_NUMBERS = ['1_v2', '2_v2', '3_v2', '4_v2', '5_v2'] |
