From 97b5798df4cba856d98715cea095fda414f434a9 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 6 Oct 2022 14:55:30 +0700 Subject: Update product_template.py and product_template.xml --- indoteknik_custom/models/product_template.py | 22 ++++++++++++++++++---- indoteknik_custom/views/product_template.xml | 11 +++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 041fcd61..d1a5867f 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -1,5 +1,5 @@ from odoo import fields, models, api -from datetime import datetime +from datetime import datetime, timedelta class ProductTemplate(models.Model): @@ -46,10 +46,25 @@ class ProductTemplate(models.Model): @api.model def _calculate_rating_product(self): # TODO add filter last calculation date time - products = self.env['product.template'].search([('type', '=', 'product'),('active', '=', True)], limit=1) + # current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') + current_time = datetime.now() + current_time = current_time - timedelta(days=60) + current_time = current_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 - test = product.image_128 if product.web_price: rate += 1 if product.have_promotion_program: @@ -57,7 +72,6 @@ class ProductTemplate(models.Model): if product.image_128: rate += 1 product.product_rating = rate - current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') product.last_calculate_rating = current_time diff --git a/indoteknik_custom/views/product_template.xml b/indoteknik_custom/views/product_template.xml index 78aac34a..d4fa8d57 100755 --- a/indoteknik_custom/views/product_template.xml +++ b/indoteknik_custom/views/product_template.xml @@ -36,5 +36,16 @@ + + Product Template + product.template + + + + + + + + \ No newline at end of file -- cgit v1.2.3