diff options
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 @@ <field name="name">Promotion Monitoring Tree</field> <field name="model">promotion.monitoring</field> <field name="arch" type="xml"> - <tree> + <tree create="0"> <field name="product_id" /> <field name="has_promo" /> - <field name="count_promo" /> + <field name="count_active" /> + <field name="count_inactive" /> </tree> </field> </record> @@ -15,13 +16,14 @@ <field name="name">Promotion Monitoring Form</field> <field name="model">promotion.monitoring</field> <field name="arch" type="xml"> - <form> + <form create="0" edit="0"> <sheet> <group> <group> <field name="product_id" /> <field name="has_promo" /> - <field name="count_promo" /> + <field name="count_active" /> + <field name="count_inactive" /> </group> </group> </sheet> 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 @@ <sheet> <group> <group> - <field name="program_id" /> <field name="name" /> + <field name="program_id" /> <field name="promotion_type" /> + <field name="active" readonly="1" /> </group> <group> <field name="package_limit" /> |
