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/models/promotion/__init__.py | 3 ++- .../models/promotion/promotion_monitoring.py | 29 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 indoteknik_custom/models/promotion/promotion_monitoring.py (limited to 'indoteknik_custom/models') 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 -- cgit v1.2.3