diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2024-02-26 14:46:52 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2024-02-26 14:46:52 +0700 |
| commit | fc998d7f567b0391de99145ae310f8af19a52f90 (patch) | |
| tree | da26d645ece1fa568196609a3578fdb976e0f671 | |
| parent | 11309b5a62dfa0e75ca7a4bd0266816140465ba6 (diff) | |
Refactor promotion monitoring
| -rw-r--r-- | indoteknik_custom/models/promotion/promotion_monitoring.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/indoteknik_custom/models/promotion/promotion_monitoring.py b/indoteknik_custom/models/promotion/promotion_monitoring.py index d8a6dd43..9df0825d 100644 --- a/indoteknik_custom/models/promotion/promotion_monitoring.py +++ b/indoteknik_custom/models/promotion/promotion_monitoring.py @@ -15,17 +15,19 @@ class PromotionMonitoring(models.Model): def init(self): tools.drop_view_if_exists(self.env.cr, self._table) - count_active_sql = "COUNT(CASE WHEN ppl.active = True THEN ppl.id ELSE NULL END)" - count_inactive_sql = "COUNT(CASE WHEN ppl.active = False THEN ppl.id ELSE NULL END)" + sql = { + 'count_active': "COUNT(CASE WHEN ppl.active = True THEN ppl.id ELSE NULL END)", + 'count_inactive': "COUNT(CASE WHEN ppl.active = False THEN ppl.id ELSE NULL END)" + } self.env.cr.execute(""" CREATE OR REPLACE VIEW {table} AS ( SELECT p.id as id, p.id as product_id, ppi.computed_price as price, - ({count_active_sql} > 0) as has_promo, - {count_active_sql} as count_active, - {count_inactive_sql} as count_inactive + ({count_active} > 0) as has_promo, + {count_active} as count_active, + {count_inactive} as count_inactive FROM product_product p LEFT JOIN product_template pt ON pt.id = p.product_tmpl_id LEFT JOIN promotion_product pp ON pp.product_id = p.id @@ -38,6 +40,6 @@ class PromotionMonitoring(models.Model): ) """.format( table=self._table, - count_active_sql=count_active_sql, - count_inactive_sql=count_inactive_sql + count_active=sql['count_active'], + count_inactive=sql['count_inactive'] ))
\ No newline at end of file |
