diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-09-06 09:31:28 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-09-06 09:31:28 +0700 |
| commit | 94be2756aa2ab4c5a403877e9085eab344468f1a (patch) | |
| tree | 5d68224e1a496c5020e1632ab2ca5794bd762c49 | |
| parent | 1b55d65464b9789164ba45bdef03c56428e026f2 (diff) | |
<iman> update category management
4 files changed, 52 insertions, 47 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')]) diff --git a/indoteknik_custom/models/solr/website_categories_management.py b/indoteknik_custom/models/solr/website_categories_management.py index fe85f8e7..1f4caac3 100644 --- a/indoteknik_custom/models/solr/website_categories_management.py +++ b/indoteknik_custom/models/solr/website_categories_management.py @@ -65,41 +65,44 @@ class WebsiteCategoriesHomepage(models.Model): continue # Prepare Level 1 document - document = solr_model.get_doc('category_management', category.id) - document.update({ + document = { 'id': category.id, + 'sequence': category.sequence or '', 'category_id_i': category.category_id.id, - 'name_s': category.category_id.name, - 'image_s': self.env['ir.attachment'].api_image('product.public.category', 'image_1920', category.category_id.id), - 'sequence_i': category.sequence or '', - 'numFound_i': len(category.category_id.product_tmpl_ids), - }) + 'name': category.category_id.name, + 'numFound': len(category.category_id.product_tmpl_ids), + 'image': self.env['ir.attachment'].api_image( + 'product.public.category', 'image_1920', category.category_id.id + ), + 'categories': [] + } # Prepare Level 2 documents - level_2_docs = [] for category_level_2 in category.line_ids.mapped('category_id2'): level_2_doc = { 'id_level_2': category_level_2.id, - 'name_level_2': category_level_2.name, - 'numFound_level_2': len(category_level_2.product_tmpl_ids), - 'image_level_2': self.env['ir.attachment'].api_image('product.public.category', 'image_1920', category_level_2.id), - 'categories_level_3': [] + 'name': category_level_2.name, + 'numFound': len(category_level_2.product_tmpl_ids), + 'image': self.env['ir.attachment'].api_image( + 'product.public.category', 'image_1920', category_level_2.id + ), + 'child_frontend_id_i': [] } # Prepare Level 3 documents for category_level_3 in category_level_2.child_frontend_id2: level_3_doc = { 'id_level_3': category_level_3.id, - 'name_level_3': category_level_3.name, - 'numFound_level_3': len(category_level_3.product_tmpl_ids), - 'image_level_3': self.env['ir.attachment'].api_image('product.public.category', 'image_1920', category_level_3.id), + 'name': category_level_3.name, + 'numFound': len(category_level_3.product_tmpl_ids), + 'image': self.env['ir.attachment'].api_image( + 'product.public.category', 'image_1920', category_level_3.id + ), } - level_2_doc['categories_level_3'].append(level_3_doc) - - level_2_docs.append(level_2_doc) + level_2_doc['child_frontend_id_i'].append(level_3_doc) - # Add Level 2 documents to Level 1 document - document['categories_level_2'] = level_2_docs + # Add Level 2 document to Level 1 + document['categories'].append(level_2_doc) # Sync document with Solr self.solr().add([document]) @@ -108,3 +111,4 @@ class WebsiteCategoriesHomepage(models.Model): # Commit and optimize Solr changes self.solr().commit() self.solr().optimize() + diff --git a/indoteknik_custom/models/website_categories_management.py b/indoteknik_custom/models/website_categories_management.py index e430ef5f..3b1db7dd 100644 --- a/indoteknik_custom/models/website_categories_management.py +++ b/indoteknik_custom/models/website_categories_management.py @@ -7,6 +7,10 @@ class WebsiteCategoriesManagement(models.Model): category_id = fields.Many2one('product.public.category', string='Category Level 1', help='table ecommerce category', domain=lambda self: self._get_default_category_domain()) sequence = fields.Integer(string='Sequence') + category_id2 = fields.Many2many(comodel_name='product.public.category', + relation='website_categories_category_id2_rel', + column1='website_categories_homepage_id', column2='product_public_category_id', + string='Category Level 2', copy=False) line_ids = fields.One2many('website.categories.management.line', 'management_id', string='Category Level 2 Lines', auto_join=True) status = fields.Selection([ ('tayang', 'Tayang'), diff --git a/indoteknik_custom/views/website_categories_management.xml b/indoteknik_custom/views/website_categories_management.xml index 6ad85944..6e01e923 100644 --- a/indoteknik_custom/views/website_categories_management.xml +++ b/indoteknik_custom/views/website_categories_management.xml @@ -29,6 +29,7 @@ <group> <field name="sequence"/> <field name="category_id"/> + <field name="category_id2" widget="many2many_tags"/> <field name="status"/> </group> </group> @@ -42,6 +43,14 @@ </tree> </field> </page> + <page string="Detail category"> + <field name="category_id2"> + <tree editable="bottom"> + <field name="name"/> + <field name="child_frontend_id2" widget="many2many_tags"/> + </tree> + </field> + </page> </notebook> </sheet> </form> |
