diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2024-02-26 09:16:16 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2024-02-26 09:16:16 +0700 |
| commit | 7c96326cc85efe6fd9d2cbd8c0284663282f1abc (patch) | |
| tree | 6aeeb25e681951c2b9ff285d4d1ec5265dbf2790 /indoteknik_custom/models/promotion/promotion_monitoring.py | |
| parent | fc460ec7349d557654316c0628d76d49c12fd575 (diff) | |
Add promotion monitoring
Diffstat (limited to 'indoteknik_custom/models/promotion/promotion_monitoring.py')
| -rw-r--r-- | indoteknik_custom/models/promotion/promotion_monitoring.py | 29 |
1 files changed, 29 insertions, 0 deletions
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 |
