summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2025-08-27 15:49:37 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2025-08-27 15:49:37 +0700
commit97c13d37545bf30a39c4e2ba96928daa441acf51 (patch)
tree773311330f6a9fdc0b45095b8b48ae4e1b5667b0
parent1788dc7a4142f69e076891267d6e0567edd02d2f (diff)
fix bug
-rw-r--r--indoteknik_custom/models/solr/promotion_program_line.py118
1 files changed, 59 insertions, 59 deletions
diff --git a/indoteknik_custom/models/solr/promotion_program_line.py b/indoteknik_custom/models/solr/promotion_program_line.py
index a7459521..b4e82a36 100644
--- a/indoteknik_custom/models/solr/promotion_program_line.py
+++ b/indoteknik_custom/models/solr/promotion_program_line.py
@@ -22,65 +22,65 @@ class PromotionProgramLine(models.Model):
})
def _sync_to_solr(self):
- solr_model = self.env['apache.solr']
- for rec in self:
- try:
- document = solr_model.get_doc(self._solr_schema, rec.id)
-
- products = [{
- 'product_id': x.product_id.id,
- 'qty': x.qty,
- 'qty_sold': x.product_id.qty_sold
- } for x in rec.product_ids]
-
- free_products = [{
- 'product_id': x.product_id.id,
- 'qty': x.qty
- } for x in rec.free_product_ids]
-
- promotion_type = rec._res_promotion_type()
-
- category_names = [category.name for category in rec.product_ids.product_id.public_categ_ids]
- sequence_value = None if rec.sequence == 0 else rec.sequence
-
- document.update({
- 'id': rec.id,
- 'program_id_i': rec.program_id.id or 0,
- 'name_s': rec.name,
- 'type_value_s': promotion_type['value'],
- 'type_label_s': promotion_type['label'],
- 'package_limit_i': rec.package_limit,
- 'package_limit_user_i': rec.package_limit_user,
- 'package_limit_trx_i': rec.package_limit_trx,
- 'price_f': rec.price,
- 'price_tier_1_f': rec.price_tier_1,
- 'price_tier_2_f': rec.price_tier_2,
- 'price_tier_3_f': rec.price_tier_3,
- 'price_tier_4_f': rec.price_tier_4,
- 'price_tier_5_f': rec.price_tier_5,
- 'sequence_i': sequence_value,
- 'product_ids': [x.product_id.id for x in rec.product_ids],
- 'products_s': json.dumps(products),
- 'free_product_ids': [x.product_id.id for x in rec.free_product_ids],
- 'free_products_s': json.dumps(free_products),
- 'total_qty_i': sum([x.qty for x in rec.product_ids] + [x.qty for x in rec.free_product_ids]),
- 'total_qty_sold_f': [x.product_id.qty_sold for x in rec.product_ids],
- 'active_b': rec.active,
- "manufacture_name_s": rec.product_ids.product_id.x_manufacture.x_name or '',
- "category_name": category_names,
- })
-
- self.solr().add([document])
- self.solr().commit()
-
- except Exception as e:
- _logger.error(
- "Failed to sync record %s (ID: %s) to Solr. Error: %s",
- rec._name, rec.id, str(e),
- exc_info=True # biar stack trace keluar
- )
- # opsional -> kalau mau hard fail:
- # raise UserError(_("Sync to Solr failed for record %s: %s") % (rec.name, str(e)))
+ solr_model = self.env['apache.solr']
+ for rec in self:
+ try:
+ document = solr_model.get_doc(self._solr_schema, rec.id)
+
+ products = [{
+ 'product_id': x.product_id.id,
+ 'qty': x.qty,
+ 'qty_sold': x.product_id.qty_sold
+ } for x in rec.product_ids]
+
+ free_products = [{
+ 'product_id': x.product_id.id,
+ 'qty': x.qty
+ } for x in rec.free_product_ids]
+
+ promotion_type = rec._res_promotion_type()
+
+ category_names = [category.name for category in rec.product_ids.product_id.public_categ_ids]
+ sequence_value = None if rec.sequence == 0 else rec.sequence
+
+ document.update({
+ 'id': rec.id,
+ 'program_id_i': rec.program_id.id or 0,
+ 'name_s': rec.name,
+ 'type_value_s': promotion_type['value'],
+ 'type_label_s': promotion_type['label'],
+ 'package_limit_i': rec.package_limit,
+ 'package_limit_user_i': rec.package_limit_user,
+ 'package_limit_trx_i': rec.package_limit_trx,
+ 'price_f': rec.price,
+ 'price_tier_1_f': rec.price_tier_1,
+ 'price_tier_2_f': rec.price_tier_2,
+ 'price_tier_3_f': rec.price_tier_3,
+ 'price_tier_4_f': rec.price_tier_4,
+ 'price_tier_5_f': rec.price_tier_5,
+ 'sequence_i': sequence_value,
+ 'product_ids': [x.product_id.id for x in rec.product_ids],
+ 'products_s': json.dumps(products),
+ 'free_product_ids': [x.product_id.id for x in rec.free_product_ids],
+ 'free_products_s': json.dumps(free_products),
+ 'total_qty_i': sum([x.qty for x in rec.product_ids] + [x.qty for x in rec.free_product_ids]),
+ 'total_qty_sold_f': [x.product_id.qty_sold for x in rec.product_ids],
+ 'active_b': rec.active,
+ "manufacture_name_s": rec.product_ids.product_id.x_manufacture.x_name or '',
+ "category_name": category_names,
+ })
+
+ self.solr().add([document])
+ self.solr().commit()
+
+ except Exception as e:
+ _logger.error(
+ "Failed to sync record %s (ID: %s) to Solr. Error: %s",
+ rec._name, rec.id, str(e),
+ exc_info=True # biar stack trace keluar
+ )
+ # opsional -> kalau mau hard fail:
+ # raise UserError(_("Sync to Solr failed for record %s: %s") % (rec.name, str(e)))
@api.model
def create(self, vals):