From 5310e60574e29a53232f0bb8286660c1d9813b76 Mon Sep 17 00:00:00 2001 From: FIN-IT_AndriFP Date: Fri, 12 Dec 2025 09:18:12 +0700 Subject: (andri) add attribute set di solr mapping --- indoteknik_custom/models/product_template.py | 12 +++++++++++- indoteknik_custom/models/solr/apache_solr.py | 13 +++++++++---- indoteknik_custom/models/solr/product_product.py | 2 ++ indoteknik_custom/models/solr/product_template.py | 2 ++ indoteknik_custom/views/product_template.xml | 2 ++ 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index ee33a185..2eed0f0d 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -15,7 +15,17 @@ _logger = logging.getLogger(__name__) class ProductTemplate(models.Model): _inherit = "product.template" - + x_attribute_set_id = fields.Integer( + string="Magento Attribute Set ID", + default=0, + index=True, + help="Attribute Set ID dari Magento" + ) + x_attribute_set_name = fields.Char( + string="Magento Attribute Set Name", + help="Attribute Set Name dari Magento" + ) + image_carousel_lines = fields.One2many( comodel_name="image.carousel", inverse_name="product_id", diff --git a/indoteknik_custom/models/solr/apache_solr.py b/indoteknik_custom/models/solr/apache_solr.py index d111c1c1..c2283421 100644 --- a/indoteknik_custom/models/solr/apache_solr.py +++ b/indoteknik_custom/models/solr/apache_solr.py @@ -7,9 +7,12 @@ import time from odoo.tools.config import config _logger = logging.getLogger(__name__) -_solr = pysolr.Solr('http://10.148.0.5:8983/solr/product/', always_commit=True, timeout=30) -_variants_solr = pysolr.Solr('http://10.148.0.5:8983/solr/variants/', always_commit=True, timeout=30) -_recommendation_solr = pysolr.Solr('http://10.148.0.5:8983/solr/recommendation/', always_commit=True, timeout=30) +# _solr = pysolr.Solr('http://10.148.0.5:8983/solr/product/', always_commit=True, timeout=30) +# _variants_solr = pysolr.Solr('http://10.148.0.5:8983/solr/variants/', always_commit=True, timeout=30) +# _recommendation_solr = pysolr.Solr('http://10.148.0.5:8983/solr/recommendation/', always_commit=True, timeout=30) +_solr = pysolr.Solr('http://localhost:8983/solr/product/', always_commit=True, timeout=30) +_variants_solr = pysolr.Solr('http://localhost:8983/solr/variants/', always_commit=True, timeout=30) +_recommendation_solr = pysolr.Solr('http://localhost:8983/solr/recommendation/', always_commit=True, timeout=30) # _solr = pysolr.Solr('http://34.101.189.218:8983/solr/product/', always_commit=True, timeout=30) # for development only @@ -24,7 +27,7 @@ class ApacheSolr(models.Model): if env == 'development': url = 'http://localhost:8983/solr/' elif env == 'production': - url = 'http://34.101.189.218:8983/solr/' + url = 'http://locahost:8983/solr/' return pysolr.Solr(url + schema, always_commit=False, timeout=10) @@ -266,6 +269,8 @@ class ApacheSolr(models.Model): 'tax_f': tax, 'stock_total_f': variant.qty_stock_vendor, 'weight_f': variant.product_tmpl_id.weight, + 'attribute_set_id_i': variant.product_tmpl_id.x_attribute_set_id or 0, + 'attribute_set_name_s': variant.product_tmpl_id.x_attribute_set_name or '', 'manufacture_id_i': variant.product_tmpl_id.x_manufacture.id or 0, 'manufacture_name_s': variant.product_tmpl_id.x_manufacture.x_name or '', 'manufacture_name': variant.product_tmpl_id.x_manufacture.x_name or '', diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py index 7260c3ca..7df56e57 100644 --- a/indoteknik_custom/models/solr/product_product.py +++ b/indoteknik_custom/models/solr/product_product.py @@ -73,6 +73,8 @@ class ProductProduct(models.Model): 'image_mobile_s': ir_attachment.api_image('product.template', 'image_256', variant.product_tmpl_id.id), 'stock_total_f': variant.qty_free_bandengan, 'weight_f': variant.weight, + 'attribute_set_id_i': variant.product_tmpl_id.x_attribute_set_id or 0, + 'attribute_set_name_s': variant.product_tmpl_id.x_attribute_set_name or '', 'manufacture_id_i': variant.product_tmpl_id.x_manufacture.id or 0, 'manufacture_name_s': variant.product_tmpl_id.x_manufacture.x_name or '', 'manufacture_name': variant.product_tmpl_id.x_manufacture.x_name or '', diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index a7beca12..d6ca9097 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -105,6 +105,8 @@ class ProductTemplate(models.Model): "variant_total_i": template.product_variant_count, "stock_total_f": template.qty_stock_vendor, "weight_f": template.weight, + # "attribute_set_id_i": template.x_attribute_set_id or 0, + # "attribute_set_name_s": template.x_attribute_set_name or '', "manufacture_id_i": template.x_manufacture.id or 0, "manufacture_name_s": template.x_manufacture.x_name or '', "manufacture_name": template.x_manufacture.x_name or '', diff --git a/indoteknik_custom/views/product_template.xml b/indoteknik_custom/views/product_template.xml index 177449f4..1933a5d1 100755 --- a/indoteknik_custom/views/product_template.xml +++ b/indoteknik_custom/views/product_template.xml @@ -112,6 +112,8 @@ + + -- cgit v1.2.3 From c8fadfcb646ec86b73d92f199a98000aeabcbfe8 Mon Sep 17 00:00:00 2001 From: FIN-IT_AndriFP Date: Mon, 15 Dec 2025 11:06:20 +0700 Subject: (andri) comment create & write --- indoteknik_custom/models/keywords.py | 122 +++++++++++++++++------------------ 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/indoteknik_custom/models/keywords.py b/indoteknik_custom/models/keywords.py index 5faa94a6..28dfa09e 100644 --- a/indoteknik_custom/models/keywords.py +++ b/indoteknik_custom/models/keywords.py @@ -64,56 +64,56 @@ class Keywords(models.Model): # raise UserError("Tidak bisa create/write/duplicate karena keywords sudah dipakai") - def generate_products(self): - for record in self: - if not record.keywords: - continue - - keyword = "%" + record.keywords.strip() + "%" - - # Query dasar - sql = """ - SELECT pp.id - FROM product_product pp - JOIN product_template pt ON pt.id = pp.product_tmpl_id - LEFT JOIN product_public_category_product_template_rel rel - ON rel.product_template_id = pt.id - WHERE ( - pt.name ILIKE %s - OR pt.website_description ILIKE %s - AND pt.unpublished = False - AND pt.product_rating >= 8 - ) - """ - - params = [keyword, keyword] - - # Filter kategori ke child - if record.category_id: - child_categs = self.env['product.public.category'].search([ - ('id', 'child_of', record.category_id.id) - ]) - sql += " AND rel.product_public_category_id = ANY(%s)" - params.append(child_categs.ids) - - # Exec SQL - self.env.cr.execute(sql, params) - rows = self.env.cr.fetchall() - - product_ids = [r[0] for r in rows] - - if not product_ids: - raise UserError("Tidak berhasil menemukan barang") - - record.with_context(skip_generate=True).write({ - 'product_ids': [(6, 0, product_ids)] - }) - - _logger.info( - "Product Found: Found %s products for keyword '%s'", - len(product_ids), - record.keywords - ) + # def generate_products(self): + # for record in self: + # if not record.keywords: + # continue + + # keyword = "%" + record.keywords.strip() + "%" + + # # Query dasar + # sql = """ + # SELECT pp.id + # FROM product_product pp + # JOIN product_template pt ON pt.id = pp.product_tmpl_id + # LEFT JOIN product_public_category_product_template_rel rel + # ON rel.product_template_id = pt.id + # WHERE ( + # pt.name ILIKE %s + # OR pt.website_description ILIKE %s + # AND pt.unpublished = False + # AND pt.product_rating >= 8 + # ) + # """ + + # params = [keyword, keyword] + + # # Filter kategori ke child + # if record.category_id: + # child_categs = self.env['product.public.category'].search([ + # ('id', 'child_of', record.category_id.id) + # ]) + # sql += " AND rel.product_public_category_id = ANY(%s)" + # params.append(child_categs.ids) + + # # Exec SQL + # self.env.cr.execute(sql, params) + # rows = self.env.cr.fetchall() + + # product_ids = [r[0] for r in rows] + + # if not product_ids: + # raise UserError("Tidak berhasil menemukan barang") + + # record.with_context(skip_generate=True).write({ + # 'product_ids': [(6, 0, product_ids)] + # }) + + # _logger.info( + # "Product Found: Found %s products for keyword '%s'", + # len(product_ids), + # record.keywords + # ) def sync_solr(self): # solr_model = self.env['apache.solr'] @@ -138,14 +138,14 @@ class Keywords(models.Model): solr.add(documents) return True - @api.model - def create(self, vals): - record = super().create(vals) - record.generate_products() - return record - - def write(self, vals): - result = super().write(vals) - # if not self.env.context.get("skip_generate") and not self.skip: - # self.generate_products() - return result + # @api.model + # def create(self, vals): + # record = super().create(vals) + # # record.generate_products() + # return record + + # def write(self, vals): + # result = super().write(vals) + # # if not self.env.context.get("skip_generate") and not self.skip: + # # self.generate_products() + # return result -- cgit v1.2.3