From abcaa0fc701901cf6864c2872ffb2e469d808628 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 26 Feb 2024 13:51:24 +0700 Subject: Add active and inactive on promotion monitoring --- .../models/promotion/promotion_monitoring.py | 19 ++++++++++++++----- .../views/promotion/promotion_monitoring.xml | 10 ++++++---- .../views/promotion/promotion_program_line.xml | 3 ++- 3 files changed, 22 insertions(+), 10 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 diff --git a/indoteknik_custom/views/promotion/promotion_monitoring.xml b/indoteknik_custom/views/promotion/promotion_monitoring.xml index b1f80276..4af4fc82 100644 --- a/indoteknik_custom/views/promotion/promotion_monitoring.xml +++ b/indoteknik_custom/views/promotion/promotion_monitoring.xml @@ -3,10 +3,11 @@ Promotion Monitoring Tree promotion.monitoring - + - + + @@ -15,13 +16,14 @@ Promotion Monitoring Form promotion.monitoring -
+ - + + diff --git a/indoteknik_custom/views/promotion/promotion_program_line.xml b/indoteknik_custom/views/promotion/promotion_program_line.xml index 4bc737b9..025ea35a 100644 --- a/indoteknik_custom/views/promotion/promotion_program_line.xml +++ b/indoteknik_custom/views/promotion/promotion_program_line.xml @@ -21,9 +21,10 @@ - + + -- cgit v1.2.3