From aec3028acc08c573b68a71b0144558f8fc091607 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 26 Feb 2024 13:20:54 +0700 Subject: Add solr flag and add to queue on program line --- .../models/promotion/promotion_program_line.py | 3 ++- indoteknik_custom/models/solr/promotion_program_line.py | 12 ++++++++++-- indoteknik_custom/views/apache_solr_queue.xml | 7 +++++-- .../views/promotion/promotion_program_line.xml | 15 +++++++++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/indoteknik_custom/models/promotion/promotion_program_line.py b/indoteknik_custom/models/promotion/promotion_program_line.py index ce46d2e7..cb231889 100644 --- a/indoteknik_custom/models/promotion/promotion_program_line.py +++ b/indoteknik_custom/models/promotion/promotion_program_line.py @@ -30,7 +30,8 @@ class PromotionProgramLine(models.Model): discount_amount = fields.Float('Discount Amount') order_promotion_ids = fields.One2many('sale.order.promotion', 'program_line_id', 'Promotions') - active = fields.Boolean(default=True) + active = fields.Boolean(string="Active", default=True) + solr_flag = fields.Integer(string="Solr Flag", default=1) def get_active_promotions(self, product_id): current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') diff --git a/indoteknik_custom/models/solr/promotion_program_line.py b/indoteknik_custom/models/solr/promotion_program_line.py index 30ce16c9..b241b248 100644 --- a/indoteknik_custom/models/solr/promotion_program_line.py +++ b/indoteknik_custom/models/solr/promotion_program_line.py @@ -54,9 +54,7 @@ class PromotionProgramLine(models.Model): 'total_qty_i': sum([x.qty for x in rec.product_ids] + [x.qty for x in rec.free_product_ids]), 'active': 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 diff --git a/indoteknik_custom/views/apache_solr_queue.xml b/indoteknik_custom/views/apache_solr_queue.xml index 7577e569..4c145b9f 100644 --- a/indoteknik_custom/views/apache_solr_queue.xml +++ b/indoteknik_custom/views/apache_solr_queue.xml @@ -4,13 +4,16 @@ apache.solr.queue -