diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2023-07-27 10:47:19 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2023-07-27 10:47:19 +0700 |
| commit | 421ff67560201e8155d03cbe4ff7029cd6b667a4 (patch) | |
| tree | 332eadffa49d97696aa53dc9c10bfd1cc0537e74 | |
| parent | 87a29b3262e0a952882199d4560f820805069d11 (diff) | |
| parent | df7bbe715bb49d9986d68046127410340b617713 (diff) | |
Merge branch 'production' of bitbucket.org:altafixco/indoteknik-addons into production
| -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() |
