From 8c4bf3e27b2491955a3f94fa3f3478da6d23fea2 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 16 Jul 2024 17:16:26 +0700 Subject: update tampilan untuk category management --- .../models/product_public_category.py | 7 +++--- .../models/solr/website_categories_homepage.py | 22 ++++++++++++++---- .../models/website_categories_homepage.py | 26 ++++++++++++++++++---- .../views/product_public_category.xml | 1 + .../views/website_categories_homepage.xml | 26 +++++++++++----------- 5 files changed, 58 insertions(+), 24 deletions(-) diff --git a/indoteknik_custom/models/product_public_category.py b/indoteknik_custom/models/product_public_category.py index 91028ae0..a6390f56 100755 --- a/indoteknik_custom/models/product_public_category.py +++ b/indoteknik_custom/models/product_public_category.py @@ -1,17 +1,18 @@ -from odoo import fields, models +from odoo import fields, models, api class ProductPublicCategory(models.Model): _inherit = "product.public.category" x_studio_field_4qhoN = fields.Boolean(string="Tampil di Index") - # x_studio_field_5RdHI = fields.Many2many("product.template", string="Product Template") x_studio_field_7bVEO = fields.Many2many("x_banner.banner", string="Banner Index") x_studio_field_BfNp2 = fields.Char(string="Nama Alias") x_studio_field_d1HS4 = fields.Char(string="Name 2") x_studio_field_f54P2 = fields.Char(string="Name 3") english_name = fields.Char(string="English Name") + image = fields.Binary(string='Image') parent_frontend_id = fields.Many2one('product.public.category', string='Parent Frontend Category', index=True) child_frontend_id = fields.One2many('product.public.category', 'parent_frontend_id', string='Children Frontend Categories') + child_frontend_id2 = fields.Many2many('product.public.category', relation='website_categories_child_frontend_rel', string='Category Level 3', help="Cari manual Category level 3") sequence_frontend = fields.Integer(help="Gives the sequence order when displaying a list of product categories.", index=True) -# check + diff --git a/indoteknik_custom/models/solr/website_categories_homepage.py b/indoteknik_custom/models/solr/website_categories_homepage.py index 75d84e73..70c7860d 100644 --- a/indoteknik_custom/models/solr/website_categories_homepage.py +++ b/indoteknik_custom/models/solr/website_categories_homepage.py @@ -2,6 +2,10 @@ from odoo import models, fields, api from datetime import datetime import json +import logging + +_logger = logging.getLogger(__name__) + class WebsiteCategoriesHomepage(models.Model): _inherit = 'website.categories.homepage' @@ -56,6 +60,15 @@ class WebsiteCategoriesHomepage(models.Model): for category in self: if category.status == 'tidak_tayang': continue + + category_id2_data = [ + { + x.id: { + 'child_frontend_id_i': [child.id for child in x.child_frontend_id] + } + } + for x in category.category_id2 + ] document = solr_model.get_doc('product_category_homepage', category.id) document.update({ @@ -65,12 +78,13 @@ class WebsiteCategoriesHomepage(models.Model): 'image_s': self.env['ir.attachment'].api_image('website.categories.homepage', 'image', category.id), 'sequence_i': category.sequence or '', 'url_s': category.url or '', - 'product_ids': [x.id for x in category.product_ids] + 'category_id2': category_id2_data, }) - self.solr().add([document]) - category.update_last_update_solr() + _logger.info('Category %s synchronized to Solr with document: %s', category.id, json.dumps(document)) + # self.solr().add([document]) + # category.update_last_update_solr() - self.solr().commit() + # self.solr().commit() # def _sync_delete_solr(self): # for rec in self: diff --git a/indoteknik_custom/models/website_categories_homepage.py b/indoteknik_custom/models/website_categories_homepage.py index a0fc1011..b7e18694 100644 --- a/indoteknik_custom/models/website_categories_homepage.py +++ b/indoteknik_custom/models/website_categories_homepage.py @@ -1,11 +1,11 @@ -from odoo import fields, models - +from odoo import fields, models, api class WebsiteCategoriesHomepage(models.Model): _name = 'website.categories.homepage' _rec_name = 'category_id' - category_id = fields.Many2one('product.public.category', string='Category', help='table ecommerce category') + category_id = fields.Many2one('product.public.category', string='Category Level 1', help='table ecommerce category',domain=lambda self: self._get_default_category_domain()) + category_id2 = fields.Many2many(comodel_name='product.public.category', relation='website_categories_category_id2_rel', string='Category Level 2', copy=False) image = fields.Binary(string='Image') url = fields.Char(string='URL') sequence = fields.Integer(string='Sequence') @@ -13,4 +13,22 @@ class WebsiteCategoriesHomepage(models.Model): ('tayang', 'Tayang'), ('tidak_tayang', 'Tidak Tayang') ], string='Status') - product_ids = fields.Many2many('product.template', string='Product Template') + + @api.onchange('category_id') + def _onchange_category_id(self): + domain = {} + self.category_id2 = [(5, 0, 0)] + if self.category_id: + domain['category_id2'] = [('parent_frontend_id', '=', self.category_id.id)] + else: + domain['category_id2'] = [] + + return {'domain': domain} + + + @api.model + def _get_default_category_domain(self): + return [('parent_id', '=', False)] + + + diff --git a/indoteknik_custom/views/product_public_category.xml b/indoteknik_custom/views/product_public_category.xml index e0161acf..a45e0a2e 100755 --- a/indoteknik_custom/views/product_public_category.xml +++ b/indoteknik_custom/views/product_public_category.xml @@ -19,6 +19,7 @@ + diff --git a/indoteknik_custom/views/website_categories_homepage.xml b/indoteknik_custom/views/website_categories_homepage.xml index aa54ca7a..f9c896bf 100644 --- a/indoteknik_custom/views/website_categories_homepage.xml +++ b/indoteknik_custom/views/website_categories_homepage.xml @@ -16,7 +16,6 @@ - @@ -31,17 +30,18 @@ - + + - - - - - + + + + + @@ -60,11 +60,11 @@ - \ No newline at end of file + -- cgit v1.2.3