From 03ba190bca443625075ddbd637d895bfc1a27fcd Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 16 Feb 2024 09:55:41 +0700 Subject: Add active field on promotion program line --- indoteknik_custom/models/promotion/promotion_program_line.py | 1 + 1 file changed, 1 insertion(+) (limited to 'indoteknik_custom/models/promotion') diff --git a/indoteknik_custom/models/promotion/promotion_program_line.py b/indoteknik_custom/models/promotion/promotion_program_line.py index 18a7e184..43daf93b 100644 --- a/indoteknik_custom/models/promotion/promotion_program_line.py +++ b/indoteknik_custom/models/promotion/promotion_program_line.py @@ -30,6 +30,7 @@ class PromotionProgramLine(models.Model): discount_amount = fields.Float('Discount Amount') order_promotion_ids = fields.One2many('sale.order.promotion', 'program_line_id', 'Promotions') + active = fields.Boolean(default=True) def get_active_promotions(self, product_id): current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') -- cgit v1.2.3 From ad0759513cc296e4a41196b2dccac35885d834e3 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 16 Feb 2024 13:45:52 +0700 Subject: Fix get remaining time on promotion program line --- indoteknik_custom/models/promotion/promotion_program_line.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'indoteknik_custom/models/promotion') diff --git a/indoteknik_custom/models/promotion/promotion_program_line.py b/indoteknik_custom/models/promotion/promotion_program_line.py index 43daf93b..9fab6e58 100644 --- a/indoteknik_custom/models/promotion/promotion_program_line.py +++ b/indoteknik_custom/models/promotion/promotion_program_line.py @@ -75,6 +75,9 @@ class PromotionProgramLine(models.Model): } def _get_remaining_time(self): + if not self.program_id.end_time: + return 0 + calculate_time = self.program_id.end_time - datetime.now() return round(calculate_time.total_seconds()) -- cgit v1.2.3 From f954856557e5199989f2e83a3d7c3015b5d9d42c Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Tue, 20 Feb 2024 16:28:57 +0700 Subject: Add parent on promotion product api res --- indoteknik_custom/models/promotion/promotion_free_product.py | 4 ++++ indoteknik_custom/models/promotion/promotion_product.py | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'indoteknik_custom/models/promotion') diff --git a/indoteknik_custom/models/promotion/promotion_free_product.py b/indoteknik_custom/models/promotion/promotion_free_product.py index c5055562..e91d5137 100644 --- a/indoteknik_custom/models/promotion/promotion_free_product.py +++ b/indoteknik_custom/models/promotion/promotion_free_product.py @@ -17,6 +17,10 @@ class PromotionFreeProduct(models.Model): weight = rec.product_id.weight or 0 result.append({ 'id': rec.product_id.id, + 'parent': { + 'id': rec.product_id.product_tmpl_id.id, + 'name': rec.product_id.product_tmpl_id.name, + }, 'image': ir_attachment.api_image('product.template', 'image_256', rec.product_id.product_tmpl_id.id), 'display_name': rec.product_id.display_name, 'name': rec.product_id.name, diff --git a/indoteknik_custom/models/promotion/promotion_product.py b/indoteknik_custom/models/promotion/promotion_product.py index 2fad0f0d..ae26e888 100644 --- a/indoteknik_custom/models/promotion/promotion_product.py +++ b/indoteknik_custom/models/promotion/promotion_product.py @@ -17,6 +17,10 @@ class PromotionProduct(models.Model): weight = rec.product_id.weight or 0 result.append({ 'id': rec.product_id.id, + 'parent': { + 'id': rec.product_id.product_tmpl_id.id, + 'name': rec.product_id.product_tmpl_id.name, + }, 'image': ir_attachment.api_image('product.template', 'image_256', rec.product_id.product_tmpl_id.id), 'display_name': rec.product_id.display_name, 'name': rec.product_id.name, -- cgit v1.2.3 From 99df2a863b6d641e96b7dd9fafbed701642d5ca7 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 21 Feb 2024 10:21:01 +0700 Subject: Fix promotion program line weight --- indoteknik_custom/models/promotion/promotion_program_line.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'indoteknik_custom/models/promotion') diff --git a/indoteknik_custom/models/promotion/promotion_program_line.py b/indoteknik_custom/models/promotion/promotion_program_line.py index 9fab6e58..ce46d2e7 100644 --- a/indoteknik_custom/models/promotion/promotion_program_line.py +++ b/indoteknik_custom/models/promotion/promotion_program_line.py @@ -97,9 +97,7 @@ class PromotionProgramLine(models.Model): free_products = self.free_product_ids.formats(purchase_qty=qty) merged_products = products + free_products - weight = 0 - if not any(x['package_weight'] == 0 for x in merged_products): - weight = sum(x['package_weight'] for x in merged_products) + weight = sum(x['package_weight'] for x in merged_products) # Sum of products and free products in 1 package quantity products_total = sum(x['price']['price_discount'] * x['qty'] / qty for x in products) -- cgit v1.2.3 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/promotion') 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 From aec3028acc08c573b68a71b0144558f8fc091607 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 26 Feb 2024 13:20:54 +0700 Subject: Add solr flag and add to queue on program line --- indoteknik_custom/models/promotion/promotion_program_line.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models/promotion') diff --git a/indoteknik_custom/models/promotion/promotion_program_line.py b/indoteknik_custom/models/promotion/promotion_program_line.py index ce46d2e7..cb231889 100644 --- a/indoteknik_custom/models/promotion/promotion_program_line.py +++ b/indoteknik_custom/models/promotion/promotion_program_line.py @@ -30,7 +30,8 @@ class PromotionProgramLine(models.Model): discount_amount = fields.Float('Discount Amount') order_promotion_ids = fields.One2many('sale.order.promotion', 'program_line_id', 'Promotions') - active = fields.Boolean(default=True) + active = fields.Boolean(string="Active", default=True) + solr_flag = fields.Integer(string="Solr Flag", default=1) def get_active_promotions(self, product_id): current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') -- cgit v1.2.3 From abcaa0fc701901cf6864c2872ffb2e469d808628 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 26 Feb 2024 13:51:24 +0700 Subject: Add active and inactive on promotion monitoring --- .../models/promotion/promotion_monitoring.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'indoteknik_custom/models/promotion') 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 -- cgit v1.2.3 From 11309b5a62dfa0e75ca7a4bd0266816140465ba6 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 26 Feb 2024 14:40:23 +0700 Subject: Add price and manufacture on promotion monitoring --- indoteknik_custom/models/promotion/promotion_monitoring.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models/promotion') diff --git a/indoteknik_custom/models/promotion/promotion_monitoring.py b/indoteknik_custom/models/promotion/promotion_monitoring.py index 3197b9ba..d8a6dd43 100644 --- a/indoteknik_custom/models/promotion/promotion_monitoring.py +++ b/indoteknik_custom/models/promotion/promotion_monitoring.py @@ -7,6 +7,8 @@ class PromotionMonitoring(models.Model): _rec_name = "product_id" product_id = fields.Many2one(comodel_name="product.product", string="Product") + manufacture_id = fields.Many2one(comodel_name="x_manufactures", string="Manufacture", related="product_id.x_manufacture") + price = fields.Float(string="Price", help="Computed Price di Product Pricelist (Tier 1 New)") has_promo = fields.Boolean(string="Has Promo") count_active = fields.Integer(string="Count Active") count_inactive = fields.Integer(string="Count Inactive") @@ -20,16 +22,19 @@ class PromotionMonitoring(models.Model): SELECT p.id as id, p.id as product_id, + ppi.computed_price as price, ({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_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 WHERE p.active = True AND pt.sale_ok = True - GROUP BY p.id + AND ppi.pricelist_id = 17023 + GROUP BY p.id, ppi.id ) """.format( table=self._table, -- cgit v1.2.3 From fc998d7f567b0391de99145ae310f8af19a52f90 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 26 Feb 2024 14:46:52 +0700 Subject: Refactor promotion monitoring --- .../models/promotion/promotion_monitoring.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'indoteknik_custom/models/promotion') diff --git a/indoteknik_custom/models/promotion/promotion_monitoring.py b/indoteknik_custom/models/promotion/promotion_monitoring.py index d8a6dd43..9df0825d 100644 --- a/indoteknik_custom/models/promotion/promotion_monitoring.py +++ b/indoteknik_custom/models/promotion/promotion_monitoring.py @@ -15,17 +15,19 @@ class PromotionMonitoring(models.Model): 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)" + sql = { + 'count_active': "COUNT(CASE WHEN ppl.active = True THEN ppl.id ELSE NULL END)", + 'count_inactive': "COUNT(CASE WHEN ppl.active = False THEN ppl.id ELSE NULL END)" + } self.env.cr.execute(""" CREATE OR REPLACE VIEW {table} AS ( SELECT p.id as id, p.id as product_id, ppi.computed_price as price, - ({count_active_sql} > 0) as has_promo, - {count_active_sql} as count_active, - {count_inactive_sql} as count_inactive + ({count_active} > 0) as has_promo, + {count_active} as count_active, + {count_inactive} 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 pp.product_id = p.id @@ -38,6 +40,6 @@ class PromotionMonitoring(models.Model): ) """.format( table=self._table, - count_active_sql=count_active_sql, - count_inactive_sql=count_inactive_sql + count_active=sql['count_active'], + count_inactive=sql['count_inactive'] )) \ No newline at end of file -- cgit v1.2.3