diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-07-16 17:16:26 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-07-16 17:16:26 +0700 |
| commit | 8c4bf3e27b2491955a3f94fa3f3478da6d23fea2 (patch) | |
| tree | 996f2353884e17ab9ea82d1873af910446f2ea55 /indoteknik_custom/models | |
| parent | be39266e634e750c553fe004a067dd1b8024dfc4 (diff) | |
<iman> update tampilan untuk category management
Diffstat (limited to 'indoteknik_custom/models')
3 files changed, 44 insertions, 11 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)] + + + |
