diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-10-06 11:06:10 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-10-06 11:06:10 +0700 |
| commit | c3d509642ddc1d25b4695362a01cb058b186c1d0 (patch) | |
| tree | bab8e43c5ec8c7b94688479d6f59a2facda57ecd | |
| parent | d3a28f88b3b94123a3db4ae0873c7e157bbb13f8 (diff) | |
Update product_template.py
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index b121ffe9..041fcd61 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -1,4 +1,5 @@ -from odoo import fields, models +from odoo import fields, models, api +from datetime import datetime class ProductTemplate(models.Model): @@ -20,8 +21,9 @@ class ProductTemplate(models.Model): 'Web Price', compute='_compute_web_price', digits='Product Price', inverse='_set_product_lst_price', help="Web Price with pricelist_id = 1") - have_promotion_program = fields.Boolean('Have Promotion Program', help="Punya promotion program gak?") + have_promotion_program = fields.Boolean('Have Promotion Program', compute='_have_promotion_program', help="Punya promotion program gak?") product_rating = fields.Float('Product Rating', help="Digunakan untuk sorting product di website") + last_calculate_rating = fields.Datetime("Last Calculate Rating") def _compute_web_price(self): for template in self: @@ -41,15 +43,22 @@ class ProductTemplate(models.Model): else: template.have_promotion_program = False + @api.model def _calculate_rating_product(self): - for product in self: + # TODO add filter last calculation date time + products = self.env['product.template'].search([('type', '=', 'product'),('active', '=', True)], limit=1) + for product in products: rate = 0 + test = product.image_128 if product.web_price: rate += 1 if product.have_promotion_program: rate += 1 - if product.image_1024: + 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 class ProductProduct(models.Model): |
