From aa60fbca555f1ed654909ed11e87add53676f625 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 2 Sep 2024 13:52:59 +0700 Subject: add auto sync to solr when end date h+1 --- indoteknik_custom/models/product_pricelist.py | 14 +++++++++++++- indoteknik_custom/views/product_pricelist.xml | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/product_pricelist.py b/indoteknik_custom/models/product_pricelist.py index 2b17cf6e..c299ff2f 100644 --- a/indoteknik_custom/models/product_pricelist.py +++ b/indoteknik_custom/models/product_pricelist.py @@ -1,5 +1,5 @@ from odoo import models, fields -from datetime import datetime +from datetime import datetime, timedelta class ProductPricelist(models.Model): @@ -18,6 +18,18 @@ class ProductPricelist(models.Model): banner_top = fields.Binary(string='Banner Top') flashsale_tag = fields.Char(string='Flash Sale Tag') + def _check_end_date_and_update_solr(self): + today = datetime.utcnow().date() + one_day_ago = today - timedelta(days=1) + + pricelists = self.search([ + ('is_flash_sale', '=', True) + ]) + + for pricelist in pricelists: + if fields.Date.to_date(pricelist.end_date) == one_day_ago: + pricelist._constrains_related_solr_field() + def _remaining_time_in_second(self): if not self.end_date: return 0 diff --git a/indoteknik_custom/views/product_pricelist.xml b/indoteknik_custom/views/product_pricelist.xml index 0dfb69db..6eff0153 100644 --- a/indoteknik_custom/views/product_pricelist.xml +++ b/indoteknik_custom/views/product_pricelist.xml @@ -26,4 +26,18 @@ + + + + Pricelist: Check End Date and Update Solr + 1 + days + -1 + + + model._check_end_date_and_update_solr() + code + 55 + + \ No newline at end of file -- cgit v1.2.3