From b603e5eca682c7d42d259d3432316ed28b41737f Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 14 Aug 2023 09:41:18 +0700 Subject: product pricelist solr --- indoteknik_custom/models/product_pricelist.py | 18 ++++++++++++------ indoteknik_custom/views/product_pricelist.xml | 8 ++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/indoteknik_custom/models/product_pricelist.py b/indoteknik_custom/models/product_pricelist.py index 95e63cf0..2053accc 100644 --- a/indoteknik_custom/models/product_pricelist.py +++ b/indoteknik_custom/models/product_pricelist.py @@ -24,16 +24,22 @@ class ProductPricelist(models.Model): remaining_time = (self.end_date - datetime.now()).total_seconds() remaining_time = round(remaining_time) return max(remaining_time, 0) - + + def update_product_solr_flag(self): + for item in self.item_ids: + item.product_id.product_tmpl_id.solr_flag = 2 + return { + 'type': 'ir.actions.client', + 'tag': 'display_notification', + 'params': { 'title': 'Notification', 'message': f'{len(self.item_ids)} produk akan diupdate ke SOLR' } + } class ProductPricelistItem(models.Model): _inherit = 'product.pricelist.item' manufacture_id = fields.Many2one('x_manufactures', string='Manufacture') - @api.onchange('fixed_price','price_discount') - def update_solr_flag(self): + @api.constrains('fixed_price','price_discount') + def update_product_solr_flag(self): for item in self: - if item.product_id.product_tmpl_id.solr_flag == 1: - item.product_id.product_tmpl_id.solr_flag = 2 - \ No newline at end of file + item.product_id.product_tmpl_id.solr_flag = 2 \ No newline at end of file diff --git a/indoteknik_custom/views/product_pricelist.xml b/indoteknik_custom/views/product_pricelist.xml index 55139a24..34876cc4 100644 --- a/indoteknik_custom/views/product_pricelist.xml +++ b/indoteknik_custom/views/product_pricelist.xml @@ -25,4 +25,12 @@ + + + Sync Product to SOLR + + + code + action = records.update_product_solr_flag() + \ No newline at end of file -- cgit v1.2.3