diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-09-02 13:52:59 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-09-02 13:52:59 +0700 |
| commit | aa60fbca555f1ed654909ed11e87add53676f625 (patch) | |
| tree | d45662b66fdf898c5d7ffdec7b5ca57103f15098 | |
| parent | 51e939b217a6ea0050cef2f5335b0dd310379b2d (diff) | |
add auto sync to solr when end date h+1
| -rw-r--r-- | indoteknik_custom/models/product_pricelist.py | 14 | ||||
| -rw-r--r-- | indoteknik_custom/views/product_pricelist.xml | 14 |
2 files changed, 27 insertions, 1 deletions
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 @@ </page> </field> </record> + + <data noupdate="1"> + <record id="ir_cron_check_end_date" model="ir.cron"> + <field name="name">Pricelist: Check End Date and Update Solr</field> + <field name="interval_number">1</field> + <field name="interval_type">days</field> + <field name="numbercall">-1</field> + <field name="doall" eval="False"/> + <field name="model_id" ref="model_product_pricelist"/> + <field name="code">model._check_end_date_and_update_solr()</field> + <field name="state">code</field> + <field name="priority">55</field> + </record> + </data> </odoo>
\ No newline at end of file |
