summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-10-06 14:55:30 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-10-06 14:55:30 +0700
commit97b5798df4cba856d98715cea095fda414f434a9 (patch)
tree5397c4bf8b2782dfc285f0037843384a5abb4e07
parente2854b141338728d9d720fa9bd97dd44ab08d806 (diff)
Update product_template.py and product_template.xml
-rwxr-xr-xindoteknik_custom/models/product_template.py22
-rwxr-xr-xindoteknik_custom/views/product_template.xml11
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 @@
</xpath>
</field>
</record>
+ <record id="product_template_product_form_inherit" model="ir.ui.view">
+ <field name="name">Product Template</field>
+ <field name="model">product.template</field>
+ <field name="inherit_id" ref="website_sale.product_template_form_view"/>
+ <field name="arch" type="xml">
+ <field name="website_ribbon_id" position="after">
+ <field name="last_calculate_rating" attrs="{'readonly': [('type', '=', 'product')]}"/>
+ <field name="product_rating" attrs="{'readonly': [('type', '=', 'product')]}"/>
+ </field>
+ </field>
+ </record>
</data>
</odoo> \ No newline at end of file