summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-09-06 09:31:28 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-09-06 09:31:28 +0700
commit94be2756aa2ab4c5a403877e9085eab344468f1a (patch)
tree5d68224e1a496c5020e1632ab2ca5794bd762c49 /indoteknik_api/controllers/api_v1
parent1b55d65464b9789164ba45bdef03c56428e026f2 (diff)
<iman> update category management
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
-rw-r--r--indoteknik_api/controllers/api_v1/category_management.py42
1 files changed, 15 insertions, 27 deletions
diff --git a/indoteknik_api/controllers/api_v1/category_management.py b/indoteknik_api/controllers/api_v1/category_management.py
index 8015bffc..c7c4651d 100644
--- a/indoteknik_api/controllers/api_v1/category_management.py
+++ b/indoteknik_api/controllers/api_v1/category_management.py
@@ -7,7 +7,6 @@ class CategoryManagement(controller.Controller):
prefix = '/api/v1/'
@http.route(prefix + 'categories_management', auth='public', methods=['GET', 'OPTIONS'], csrf=False)
- # @controller.Controller.must_authorized()
def get_categories_management(self, **kw):
base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url')
@@ -15,42 +14,31 @@ class CategoryManagement(controller.Controller):
categories = request.env['website.categories.management'].search(query, order='sequence')
data = []
-
for category in categories:
category_id2_data = []
-
- # Loop through each line to get Category Level 2 and Level 3
- for line in category.line_ids:
- category_id3_data = [
- {
- 'id_level_3': child.id,
- 'name': child.name,
- 'numFound': len(child.product_tmpl_ids.ids),
- 'image': request.env['ir.attachment'].api_image('product.public.category', 'image_1920',
- child.id)
- }
- for child in line.category_id3_ids # Loop through Many2many Category Level 3
+ for x in category.category_id2:
+ child_data = [
+ {'id_level_3': child.id,
+ 'name': child.name,
+ 'numFound': len(child.product_tmpl_ids.ids),
+ 'image': request.env['ir.attachment'].api_image('product.public.category', 'image_1920', child.id)}
+ for child in x.child_frontend_id2
]
-
category_id2_data.append({
- 'id_level_2': line.category_id2.id,
- 'name': line.category_id2.name,
- 'numFound': len(line.category_id2.product_tmpl_ids.ids),
- 'image': request.env['ir.attachment'].api_image('product.public.category', 'image_1920',
- line.category_id2.id),
- 'child_frontend_id_i': category_id3_data # Add Category Level 3 data
+ 'id_level_2': x.id,
+ 'name': x.name,
+ 'numFound': len(x.product_tmpl_ids.ids),
+ 'image': request.env['ir.attachment'].api_image('product.public.category', 'image_1920', x.id),
+ 'child_frontend_id_i': child_data
})
- # Add data for Category Level 1 along with its lines (Category Level 2)
data.append({
'id': category.id,
'sequence': category.sequence,
'category_id_i': category.category_id.id,
'name': category.category_id.name,
- 'numFound': len(category.category_id.product_tmpl_ids.ids),
- 'image': request.env['ir.attachment'].api_image('product.public.category', 'image_1920',
- category.category_id.id),
- 'categories': category_id2_data, # Category Level 2 with Level 3 nested inside
+ 'numFound': len(category.category_id.product_tmpl_ids.ids) ,
+ 'image': request.env['ir.attachment'].api_image('product.public.category', 'image_1920', category.category_id.id),
+ 'categories': category_id2_data,
})
-
return self.response(data, headers=[('Cache-Control', 'max-age=3600, public')])