diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-02-27 09:14:34 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-02-27 09:14:34 +0700 |
| commit | ac4f111ba1605fe3891582b7fc396e740130791d (patch) | |
| tree | d204380870d16a3e523df07b8ba0f907c0184904 /indoteknik_custom/models | |
| parent | 391fe72c5d9d92d49a09fc971a6c86a39a6e22d1 (diff) | |
| parent | db98ba79a92ca11df958cce513bc320110764434 (diff) | |
Merge branch 'production' of bitbucket.org:altafixco/indoteknik-addons into production
Diffstat (limited to 'indoteknik_custom/models')
3 files changed, 35 insertions, 10 deletions
diff --git a/indoteknik_custom/models/promotion/promotion_monitoring.py b/indoteknik_custom/models/promotion/promotion_monitoring.py index e5598e40..9df0825d 100644 --- a/indoteknik_custom/models/promotion/promotion_monitoring.py +++ b/indoteknik_custom/models/promotion/promotion_monitoring.py @@ -7,23 +7,39 @@ 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_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) + 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 %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 + ppi.computed_price as price, + ({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 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 ) - """ % self._table)
\ No newline at end of file + """.format( + table=self._table, + count_active=sql['count_active'], + count_inactive=sql['count_inactive'] + ))
\ No newline at end of file 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') diff --git a/indoteknik_custom/models/solr/promotion_program_line.py b/indoteknik_custom/models/solr/promotion_program_line.py index 30ce16c9..b241b248 100644 --- a/indoteknik_custom/models/solr/promotion_program_line.py +++ b/indoteknik_custom/models/solr/promotion_program_line.py @@ -54,9 +54,7 @@ class PromotionProgramLine(models.Model): 'total_qty_i': sum([x.qty for x in rec.product_ids] + [x.qty for x in rec.free_product_ids]), 'active': rec.active }) - self.solr().add([document]) - self.solr().commit() @api.model @@ -67,3 +65,13 @@ class PromotionProgramLine(models.Model): def write(self, vals): self._create_solr_queue('_sync_to_solr') return super(PromotionProgramLine, self).write(vals) + + def solr_flag_to_queue(self, limit=500): + domain = [ + ('solr_flag', '=', 2), + ('active', 'in', [True, False]) + ] + records = self.search(domain, limit=limit) + for record in records: + record._create_solr_queue('_sync_to_solr') + record.solr_flag = 1 |
