From 7c96326cc85efe6fd9d2cbd8c0284663282f1abc Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 26 Feb 2024 09:16:16 +0700 Subject: Add promotion monitoring --- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/promotion/__init__.py | 3 +- .../models/promotion/promotion_monitoring.py | 29 ++++++++++++++ .../views/promotion/promotion_monitoring.xml | 46 ++++++++++++++++++++++ 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 indoteknik_custom/models/promotion/promotion_monitoring.py create mode 100644 indoteknik_custom/views/promotion/promotion_monitoring.xml diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 6d1ca7b0..27617099 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -78,6 +78,7 @@ 'views/promotion/promotion_program.xml', 'views/promotion/promotion_program_line.xml', 'views/promotion/promotion_product.xml', + 'views/promotion/promotion_monitoring.xml', 'views/requisition.xml', 'views/landedcost.xml', 'views/product_sla.xml', diff --git a/indoteknik_custom/models/promotion/__init__.py b/indoteknik_custom/models/promotion/__init__.py index 1e15d714..82628d31 100644 --- a/indoteknik_custom/models/promotion/__init__.py +++ b/indoteknik_custom/models/promotion/__init__.py @@ -5,4 +5,5 @@ from . import promotion_free_product from . import sale_order_promotion from . import sale_order_line from . import sale_order -from . import promotion_keyword \ No newline at end of file +from . import promotion_keyword +from . import promotion_monitoring \ No newline at end of file diff --git a/indoteknik_custom/models/promotion/promotion_monitoring.py b/indoteknik_custom/models/promotion/promotion_monitoring.py new file mode 100644 index 00000000..e5598e40 --- /dev/null +++ b/indoteknik_custom/models/promotion/promotion_monitoring.py @@ -0,0 +1,29 @@ +from odoo import fields, models, tools + + +class PromotionMonitoring(models.Model): + _name = "promotion.monitoring" + _auto = False + _rec_name = "product_id" + + product_id = fields.Many2one(comodel_name="product.product", string="Product") + has_promo = fields.Boolean(string="Has Promo") + count_promo = fields.Integer(string="Count Promo") + + def init(self): + tools.drop_view_if_exists(self.env.cr, self._table) + self.env.cr.execute(""" + CREATE OR REPLACE VIEW %s AS ( + SELECT + p.id as id, + p.id as product_id, + (COUNT(pp.id) > 0) as has_promo, + COUNT(pp.id) as count_promo + 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 + WHERE p.active = True + AND pt.sale_ok = True + GROUP BY p.id + ) + """ % self._table) \ No newline at end of file diff --git a/indoteknik_custom/views/promotion/promotion_monitoring.xml b/indoteknik_custom/views/promotion/promotion_monitoring.xml new file mode 100644 index 00000000..b1f80276 --- /dev/null +++ b/indoteknik_custom/views/promotion/promotion_monitoring.xml @@ -0,0 +1,46 @@ + + + Promotion Monitoring Tree + promotion.monitoring + + + + + + + + + + + Promotion Monitoring Form + promotion.monitoring + +
+ + + + + + + + + +
+
+
+ + + Promotion Monitoring + ir.actions.act_window + promotion.monitoring + tree,form + + + +
\ No newline at end of file -- cgit v1.2.3