diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2024-02-26 13:51:24 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2024-02-26 13:51:24 +0700 |
| commit | abcaa0fc701901cf6864c2872ffb2e469d808628 (patch) | |
| tree | 31a237e9e9f95ff2086029775fe9915c3b366a01 /indoteknik_custom/models | |
| parent | e7675d4af1d150f9c9dc123feffa27d29719e1dc (diff) | |
Add active and inactive on promotion monitoring
Diffstat (limited to 'indoteknik_custom/models')
| -rw-r--r-- | indoteknik_custom/models/promotion/promotion_monitoring.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/indoteknik_custom/models/promotion/promotion_monitoring.py b/indoteknik_custom/models/promotion/promotion_monitoring.py index e5598e40..3197b9ba 100644 --- a/indoteknik_custom/models/promotion/promotion_monitoring.py +++ b/indoteknik_custom/models/promotion/promotion_monitoring.py @@ -8,22 +8,31 @@ class PromotionMonitoring(models.Model): product_id = fields.Many2one(comodel_name="product.product", string="Product") has_promo = fields.Boolean(string="Has Promo") - count_promo = fields.Integer(string="Count Promo") + count_active = fields.Integer(string="Count Active") + count_inactive = fields.Integer(string="Count Inactive") 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)" self.env.cr.execute(""" - CREATE OR REPLACE VIEW %s AS ( + CREATE OR REPLACE VIEW {table} AS ( SELECT p.id as id, p.id as product_id, - (COUNT(pp.id) > 0) as has_promo, - COUNT(pp.id) as count_promo + ({count_active_sql} > 0) as has_promo, + {count_active_sql} as count_active, + {count_inactive_sql} 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 p.id = pp.product_id + LEFT JOIN promotion_program_line ppl ON ppl.id = pp.program_line_id WHERE p.active = True AND pt.sale_ok = True GROUP BY p.id ) - """ % self._table)
\ No newline at end of file + """.format( + table=self._table, + count_active_sql=count_active_sql, + count_inactive_sql=count_inactive_sql + ))
\ No newline at end of file |
