From d6501fd1c30eab8686e87595327ee2887e587a49 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 7 Oct 2022 10:39:24 +0700 Subject: Update product_template.py --- indoteknik_custom/models/product_template.py | 29 +++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index d1a5867f..49f903e4 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -45,25 +45,36 @@ class ProductTemplate(models.Model): @api.model def _calculate_rating_product(self): - # TODO add filter last calculation date time - # current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') current_time = datetime.now() - current_time = current_time - timedelta(days=60) + delta_time = current_time - timedelta(days=60) + current_time = current_time.strftime('%Y-%m-%d %H:%M:%S') + delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') products = self.env['product.template'].search([ ('type', '=', 'product'), ('active', '=', True), - "|" ('last_calculate_rating', '!=', False), - ('last_calculate_rating', '<', current_time), - # ('x_manufacture', '=', 10) - # ('id', '=', 33627) ], limit=5000) for product in products: - print(product.last_calculate_rating) print("Calculate Rating Product ", product) - # print(product.image_128) + rate = 0 + if product.web_price: + rate += 1 + if product.have_promotion_program: + rate += 1 + if product.image_128: + rate += 1 + product.product_rating = rate + product.last_calculate_rating = current_time + + products = self.env['product.template'].search([ + ('type', '=', 'product'), + ('active', '=', True), + ('last_calculate_rating', '<', delta_time), + ], limit=5000) + for product in products: + print("Calculate Rating Product OutOfDate", product) rate = 0 if product.web_price: rate += 1 -- cgit v1.2.3