summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-05-29 16:43:59 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-05-29 16:43:59 +0700
commit50eacdb74fa081d5be2a0cea787843b8c123ec17 (patch)
tree8953310f1ed789aabf7d0bb86f372e937acf9510
parentcfdc348fec88a695a7d0df148ec5a3f83e8831d1 (diff)
add promotion program lines name on promotion monitoring
-rw-r--r--indoteknik_custom/models/promotion/promotion_monitoring.py13
-rw-r--r--indoteknik_custom/views/promotion/promotion_monitoring.xml1
2 files changed, 9 insertions, 5 deletions
diff --git a/indoteknik_custom/models/promotion/promotion_monitoring.py b/indoteknik_custom/models/promotion/promotion_monitoring.py
index 8a8aad8f..2c4b90f1 100644
--- a/indoteknik_custom/models/promotion/promotion_monitoring.py
+++ b/indoteknik_custom/models/promotion/promotion_monitoring.py
@@ -13,6 +13,7 @@ class PromotionMonitoring(models.Model):
count_active = fields.Integer(string="Count Active")
count_inactive = fields.Integer(string="Count Inactive")
human_last_update = fields.Datetime(string='Human Last Update')
+ promotion_program_line_names = fields.Text(string="Promotion Program Line Names")
def init(self):
tools.drop_view_if_exists(self.env.cr, self._table)
@@ -26,21 +27,23 @@ class PromotionMonitoring(models.Model):
p.id as id,
p.id as product_id,
ppi.computed_price as price,
- ({count_active} > 0) as has_promo,
- {count_active} as count_active,
- {count_inactive} as count_inactive,
- pr.human_last_update as human_last_update
+ (COUNT(ppl.id) FILTER (WHERE ppl.active = True) > 0) as has_promo,
+ COUNT(ppl.id) FILTER (WHERE ppl.active = True) as count_active,
+ COUNT(ppl.id) FILTER (WHERE ppl.active = False) as count_inactive,
+ pr.human_last_update as human_last_update,
+ STRING_AGG(DISTINCT ppl.name, ', ') as promotion_program_line_names -- Concatenate promotion_program_line names
FROM product_product p
LEFT JOIN product_template pt ON pt.id = p.product_tmpl_id
LEFT JOIN promotion_product pp ON pp.product_id = p.id
LEFT JOIN promotion_program_line ppl ON ppl.id = pp.program_line_id
LEFT JOIN product_pricelist_item ppi ON ppi.product_id = p.id
LEFT JOIN purchase_pricelist pr ON pr.product_id = p.id
+ LEFT JOIN promotion_product prp ON prp.product_id = p.id -- Join with promotion.product
WHERE p.active = True
AND pt.sale_ok = True
AND ppi.pricelist_id = 17023
GROUP BY p.id, ppi.id, pr.human_last_update
- )
+ );
""".format(
table=self._table,
count_active=sql['count_active'],
diff --git a/indoteknik_custom/views/promotion/promotion_monitoring.xml b/indoteknik_custom/views/promotion/promotion_monitoring.xml
index 746c3b61..5f6490ed 100644
--- a/indoteknik_custom/views/promotion/promotion_monitoring.xml
+++ b/indoteknik_custom/views/promotion/promotion_monitoring.xml
@@ -11,6 +11,7 @@
<field name="count_active" />
<field name="count_inactive" />
<field name="human_last_update" />
+ <field name="promotion_program_line_names"/>
</tree>
</field>
</record>