diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-07-27 10:40:15 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-07-27 10:40:15 +0700 |
| commit | 690c4951fde01ae5108e75f4093eef0f00e25bdd (patch) | |
| tree | 0373c7a07b13c1f51cb9c66355b4bf3a84ac474b | |
| parent | c0d30564d32210b9edb4c523ca8632e86de0f0a2 (diff) | |
Update calculate product rating on product template
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 7abdf1c1..933c4676 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -156,32 +156,35 @@ class ProductTemplate(models.Model): template.have_promotion_program = False @api.model - def _calculate_rating_product(self): - #["&","&",["type","=","product"],["active","=",True],"|",["last_calculate_rating","=",False],["last_calculate_rating","<","2023-01-01 00:00:00"]] + def _calculate_rating_product(self, limit=1000, expiry_days=30, ids=False): current_time = datetime.now() - delta_time = current_time - timedelta(days=30) + current_time_str = current_time.strftime('%Y-%m-%d %H:%M:%S') - current_time = current_time.strftime('%Y-%m-%d %H:%M:%S') - delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') + delta_time = current_time - timedelta(days=expiry_days) + delta_time_str = delta_time.strftime('%Y-%m-%d %H:%M:%S') - products = self.env['product.template'].search([ + query = [ '&','&', ('type', '=', 'product'), - ('active', '=', True), - '|', - ('last_calculate_rating', '=', False), - ('last_calculate_rating', '<', delta_time), - # ('id', '=', 22798), - ], limit=500) + ('active', '=', True) + ] + if not ids: + query += [ + '|', + ('last_calculate_rating', '=', False), + ('last_calculate_rating', '<', delta_time_str) + ] + else: + query += [('id', 'in', ids)] + + products = self.env['product.template'].search(query, limit=limit) for product in products: - # print("Calculate Rating Product ", product) _logger.info("Calculate Rating Product %s" % product.id) - # product_variant = self.env['product.product'].search([('product_tmpl_id', '=', product.id)], limit=1) rate = 0 if product.web_price: rate += 1 - if product.have_promotion_program: #have discount from pricelist + if product.have_promotion_program: rate += 1 if product.image_128: rate += 5 @@ -190,7 +193,7 @@ class ProductTemplate(models.Model): if product.product_variant_id.qty_stock_vendor > 0: rate += 1 product.product_rating = rate - product.last_calculate_rating = current_time + product.last_calculate_rating = current_time_str def _get_stock_website(self): qty = self._get_stock_altama() |
