summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/solr
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-02-28 14:07:47 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-02-28 14:07:47 +0700
commit00b6739e4f4228c1cc66de0ef63312bc633ae21f (patch)
tree85f8fc83d4030878893599abb2a949e5d478e3e7 /indoteknik_custom/models/solr
parent0738a192409687790c16c757f85fe440cb1f377d (diff)
parent46a7cc5601ceab2a7a6cdf4d74e0fa26ce13ab8a (diff)
Merge branch 'production' into purchasing-job
Diffstat (limited to 'indoteknik_custom/models/solr')
-rw-r--r--indoteknik_custom/models/solr/apache_solr_queue.py17
-rw-r--r--indoteknik_custom/models/solr/product_product.py10
-rw-r--r--indoteknik_custom/models/solr/promotion_program_line.py16
3 files changed, 29 insertions, 14 deletions
diff --git a/indoteknik_custom/models/solr/apache_solr_queue.py b/indoteknik_custom/models/solr/apache_solr_queue.py
index 07274295..1b51538f 100644
--- a/indoteknik_custom/models/solr/apache_solr_queue.py
+++ b/indoteknik_custom/models/solr/apache_solr_queue.py
@@ -18,6 +18,7 @@ class ApacheSolrQueue(models.Model):
('not_found', 'Record not found')
], 'Execute Status')
execute_date = fields.Datetime('Execute Date')
+ description = fields.Text('Description')
def _compute_display_name(self):
for rec in self:
@@ -38,6 +39,16 @@ class ApacheSolrQueue(models.Model):
if elapsed_time > max_exec_time:
break
rec.execute_queue()
+
+ def open_target_record(self):
+ return {
+ 'name': '',
+ 'view_mode': 'form',
+ 'res_model': self.res_model,
+ 'target': 'current',
+ 'type': 'ir.actions.act_window',
+ 'res_id': self.res_id
+ }
def execute_queue(self):
for rec in self:
@@ -48,7 +59,8 @@ class ApacheSolrQueue(models.Model):
_logger.info(f'Execute Queue: {res_model}.{function_name}() -> {res_id}')
domain = [('id', '=', res_id)]
- if res_model in ['product.template']:
+ model_incl_archive = ['product.template', 'promotion.program.line']
+ if res_model in model_incl_archive:
domain.append(('active', 'in', [True, False]))
model_instance = self.env[res_model].search(domain)
@@ -57,7 +69,8 @@ class ApacheSolrQueue(models.Model):
rec.execute_status = 'success'
else:
rec.execute_status = 'not_found'
- except:
+ except Exception as e:
+ rec.description = e
rec.execute_status = 'failed'
rec.execute_date = datetime.utcnow()
self.env.cr.commit()
diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py
index ac41dbff..c14f6b98 100644
--- a/indoteknik_custom/models/solr/product_product.py
+++ b/indoteknik_custom/models/solr/product_product.py
@@ -49,12 +49,6 @@ class ProductProduct(models.Model):
document = solr_model.get_doc('variants', variant.id)
- image = ''
- if variant.image_256:
- image = ir_attachment.api_image('product.product', 'image_256', variant.id)
- else:
- image = ir_attachment.api_image('product.template', 'image_256', variant.product_tmpl_id.id)
-
document.update({
'id': variant.id,
'display_name_s': variant.display_name,
@@ -63,9 +57,9 @@ class ProductProduct(models.Model):
'product_rating_f': variant.product_tmpl_id.virtual_rating,
'product_id_i': variant.id,
'template_id_i': variant.product_tmpl_id.id,
- "image_s": image,
+ 'image_s': ir_attachment.api_image('product.template', 'image_256', variant.product_tmpl_id.id),
'stock_total_f': variant.qty_stock_vendor,
- 'weight_f': variant.product_tmpl_id.weight,
+ 'weight_f': variant.weight,
'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/promotion_program_line.py b/indoteknik_custom/models/solr/promotion_program_line.py
index 6e182324..9cd226fb 100644
--- a/indoteknik_custom/models/solr/promotion_program_line.py
+++ b/indoteknik_custom/models/solr/promotion_program_line.py
@@ -39,9 +39,8 @@ class PromotionProgramLine(models.Model):
document.update({
'id': rec.id,
- 'program_id_i': rec.program_id.id,
+ 'program_id_i': rec.program_id.id or 0,
'name_s': rec.name,
- 'image_s': self.env['ir.attachment'].api_image(self._name, 'image', rec.id) if rec.image else '',
'type_value_s': promotion_type['value'],
'type_label_s': promotion_type['label'],
'package_limit_i': rec.package_limit,
@@ -53,10 +52,9 @@ class PromotionProgramLine(models.Model):
'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]),
+ 'active_b': rec.active
})
-
self.solr().add([document])
-
self.solr().commit()
@api.model
@@ -67,3 +65,13 @@ class PromotionProgramLine(models.Model):
def write(self, vals):
self._create_solr_queue('_sync_to_solr')
return super(PromotionProgramLine, self).write(vals)
+
+ def solr_flag_to_queue(self, limit=500):
+ domain = [
+ ('solr_flag', '=', 2),
+ ('active', 'in', [True, False])
+ ]
+ records = self.search(domain, limit=limit)
+ for record in records:
+ record._create_solr_queue('_sync_to_solr')
+ record.solr_flag = 1