summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--indoteknik_api/controllers/api_v1/cart.py3
-rw-r--r--indoteknik_custom/models/solr/product_template.py36
-rw-r--r--indoteknik_custom/models/website_user_cart.py109
3 files changed, 65 insertions, 83 deletions
diff --git a/indoteknik_api/controllers/api_v1/cart.py b/indoteknik_api/controllers/api_v1/cart.py
index aa47b247..f472a9b0 100644
--- a/indoteknik_api/controllers/api_v1/cart.py
+++ b/indoteknik_api/controllers/api_v1/cart.py
@@ -19,8 +19,7 @@ class Cart(controller.Controller):
carts.write({'source': 'add_to_cart'})
data = {
'product_total': user_cart.search_count(query),
- 'products': carts.with_context(price_for="web").get_products(),
- 'product_inactive': carts.with_context(price_for="web").get_products_inactive()
+ 'products': carts.with_context(price_for="web").get_products()
}
return self.response(data)
diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py
index 6f76c529..b5fed4fa 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": website_description 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']
diff --git a/indoteknik_custom/models/website_user_cart.py b/indoteknik_custom/models/website_user_cart.py
index 0fd8df98..0af22d47 100644
--- a/indoteknik_custom/models/website_user_cart.py
+++ b/indoteknik_custom/models/website_user_cart.py
@@ -23,46 +23,35 @@ class WebsiteUserCart(models.Model):
record.user_other_carts = others
def get_product(self):
+ res = {
+ 'cart_id': self.id,
+ 'quantity': self.qty,
+ 'selected': self.is_selected,
+ 'can_buy': True
+ }
+
if self.product_id:
- base_price = self.product_id._v2_get_website_price_include_tax()
- active = self.product_id.active
- if base_price > 0 and active:
- res = {
- 'cart_id': self.id,
- 'quantity': self.qty,
- 'selected': self.is_selected,
- 'can_buy': True
- }
- res['cart_type'] = 'product'
- res['active'] = True if self.product_id.active else False
- product = self.product_id.v2_api_single_response(self.product_id)
- res.update(product)
-
- # Check if the product's inventory location is in ID 57 or 83
- target_locations = [57, 83]
- stock_quant = self.env['stock.quant'].search([
- ('product_id', '=', self.product_id.id),
- ('location_id', 'in', target_locations)
- ])
-
- if stock_quant:
- res['is_in_bu'] = True
- res['on_hand_qty'] = sum(stock_quant.mapped('quantity'))
- else:
- res['is_in_bu'] = False
- res['on_hand_qty'] = 0
+ res['cart_type'] = 'product'
+ product = self.product_id.v2_api_single_response(self.product_id)
+ res.update(product)
+
+ # Check if the product's inventory location is in ID 57 or 83
+ target_locations = [57, 83]
+ stock_quant = self.env['stock.quant'].search([
+ ('product_id', '=', self.product_id.id),
+ ('location_id', 'in', target_locations)
+ ])
- flashsales = self.product_id._get_active_flash_sale()
- res['has_flashsale'] = True if len(flashsales) > 0 else False
- res['subtotal'] = self.qty * res['price']['price_discount']
- return res
+ if stock_quant:
+ res['is_in_bu'] = True
+ res['on_hand_qty'] = sum(stock_quant.mapped('quantity'))
+ else:
+ res['is_in_bu'] = False
+ res['on_hand_qty'] = 0
+
+ flashsales = self.product_id._get_active_flash_sale()
+ res['has_flashsale'] = True if len(flashsales) > 0 else False
elif self.program_line_id:
- res = {
- 'cart_id': self.id,
- 'quantity': self.qty,
- 'selected': self.is_selected,
- 'can_buy': True
- }
res['cart_type'] = 'promotion'
userdata = {
'partner_id': self.user_id.partner_id.id,
@@ -73,56 +62,14 @@ class WebsiteUserCart(models.Model):
if program['remaining_qty']['transaction'] < self.qty:
res['can_buy'] = False
- res['subtotal'] = self.qty * res['price']['price_discount']
+ res['subtotal'] = self.qty * res['price']['price_discount']
- return res
+ return res
def get_products(self):
products = [x.get_product() for x in self]
return products
-
- def get_product_inactive(self):
- if self.product_id:
- base_price = self.product_id._v2_get_website_price_include_tax()
- active = self.product_id.active
- if base_price == 0 or not active:
- res = {
- 'cart_id': self.id,
- 'quantity': self.qty,
- 'selected': self.is_selected,
- 'can_buy': True
- }
- res['cart_type'] = 'product'
- res['active'] = True if self.product_id.active else False
- product = self.product_id.v2_api_single_response(self.product_id)
- res.update(product)
-
- # Check if the product's inventory location is in ID 57 or 83
- target_locations = [57, 83]
- stock_quant = self.env['stock.quant'].search([
- ('product_id', '=', self.product_id.id),
- ('location_id', 'in', target_locations)
- ])
-
- if stock_quant:
- res['is_in_bu'] = True
- res['on_hand_qty'] = sum(stock_quant.mapped('quantity'))
- else:
- res['is_in_bu'] = False
- res['on_hand_qty'] = 0
-
- flashsales = self.product_id._get_active_flash_sale()
- res['has_flashsale'] = True if len(flashsales) > 0 else False
-
- res['subtotal'] = self.qty * res['price']['price_discount']
-
- return res
-
- def get_products_inactive(self):
- products = [x.get_product_inactive() for x in self]
-
- return products
def get_product_by_user(self, user_id, selected=False, source=False):
user_id = int(user_id)