summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xindoteknik_custom/models/product_template.py36
1 files changed, 35 insertions, 1 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index 348bda99..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,6 +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', 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:
@@ -27,6 +31,36 @@ class ProductTemplate(models.Model):
product_pricelist_item = self.env['product.pricelist.item'].search([('pricelist_id', '=', 1),('product_id', '=', product.id)],limit=1)
template.web_price = product_pricelist_item.fixed_price
+ def _have_promotion_program(self):
+ for template in self:
+ domain = [
+ ('rule_products_domain', 'ilike', template.x_manufacture.x_name),
+ ('active', '=', True)
+ ]
+ coupon_program = self.env['coupon.program'].search(domain, limit=1)
+ if coupon_program:
+ template.have_promotion_program = True
+ else:
+ template.have_promotion_program = False
+
+ @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)
+ 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_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):
_inherit = "product.product"
web_price = fields.Float(