summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFIN-IT_AndriFP <andrifebriyadiputra@gmail.com>2025-12-15 11:06:20 +0700
committerFIN-IT_AndriFP <andrifebriyadiputra@gmail.com>2025-12-15 11:06:20 +0700
commitc8fadfcb646ec86b73d92f199a98000aeabcbfe8 (patch)
tree574532e8b07e45d9e5333f0dddb5667b51fc1532
parent3a131c68a6b72d8477ddff4e42de9fda7ca78b46 (diff)
(andri) comment create & write
-rw-r--r--indoteknik_custom/models/keywords.py122
1 files 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