summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/product_template.py
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2022-10-13 16:23:22 +0700
committerIT Fixcomart <it@fixcomart.co.id>2022-10-13 16:23:22 +0700
commit47be053bafe8e212e7c98332666819e65428c4e3 (patch)
tree19a7c4545989ff6a5d85968090346fdd4e268706 /indoteknik_custom/models/product_template.py
parentc4b6e2d594b8cbd7d424673d04741a1a4cb2ff81 (diff)
parent3acb428bfa048acb6d4d2d57e9d8720e77d08075 (diff)
Merge commit '3acb428bfa048acb6d4d2d57e9d8720e77d08075' into feature/rest-api
# Conflicts: # indoteknik_custom/models/product_template.py
Diffstat (limited to 'indoteknik_custom/models/product_template.py')
-rwxr-xr-xindoteknik_custom/models/product_template.py58
1 files changed, 47 insertions, 11 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index 5c75718a..8291a517 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -1,5 +1,8 @@
from odoo import fields, models, api
from datetime import datetime, timedelta
+import logging
+
+_logger = logging.getLogger(__name__)
class ProductTemplate(models.Model):
@@ -23,7 +26,8 @@ class ProductTemplate(models.Model):
digits='Product Price', inverse='_set_product_lst_price',
help="Web Price with pricelist_id = 1")
qty_stock_vendor = fields.Float('QTY Stock Vendor', compute='_compute_qty_stock_vendor')
- have_promotion_program = fields.Boolean('Have Promotion Program', compute='_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")
web_price_sorting = fields.Float('Web Price Sorting', help='Hanya digunakan untuk sorting di web, harga tidak berlaku')
@@ -36,9 +40,26 @@ class ProductTemplate(models.Model):
def _compute_web_price(self):
for template in self:
- product = self.env['product.product'].search([('product_tmpl_id', '=', template.id)],limit=1)
- 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
+ product = self.env['product.product'].search([('product_tmpl_id', '=', template.id)], limit=1)
+
+ # product_pricelist_default = self.env['ir.config_parameter'].sudo().get_param('product.pricelist.default')
+ # product_pricelist_disc = self.env['product.pricelist.item'].search([
+ # ('pricelist_id', '=', product_pricelist_default.int()),
+ # ('product_id', '=', product.id)], limit=1)
+ # disc = product_pricelist_disc.price_discount
+
+ product_pricelist_item = self.env['product.pricelist.item'].search([
+ ('pricelist_id', '=', 1),
+ ('product_id', '=', product.id)], limit=1)
+ price = product_pricelist_item.fixed_price
+ #
+ # if not disc and not price:
+ # template.web_price = 0
+ # elif not disc:
+ template.web_price = price
+ # else:
+ # price_disc = price - (price * disc / 100)
+ # template.web_price = price_disc
def _have_promotion_program(self):
for template in self:
@@ -63,10 +84,14 @@ class ProductTemplate(models.Model):
products = self.env['product.template'].search([
('type', '=', 'product'),
('active', '=', True),
- ('last_calculate_rating', '!=', False),
- ], limit=5000)
+ ('last_calculate_rating', '=', False),
+ # ('id', '=', 22798),
+ ], limit=10000)
+
for product in products:
- print("Calculate Rating Product ", product)
+ # print("Calculate Rating Product ", product)
+ _logger.info("Calculate Rating Product %s" % product.id)
+ product_variant = self.env['product.product'].search([('product_tmpl_id', '=', product.id)], limit=1)
rate = 0
if product.web_price:
rate += 1
@@ -75,6 +100,10 @@ class ProductTemplate(models.Model):
rate += 1
if product.image_128:
rate += 1
+ if product.website_description:
+ rate += 1
+ if product_variant.qty_stock_vendor > 0:
+ rate += 1
product.product_rating = rate
product.last_calculate_rating = current_time
@@ -82,9 +111,11 @@ class ProductTemplate(models.Model):
('type', '=', 'product'),
('active', '=', True),
('last_calculate_rating', '<', delta_time),
- ], limit=5000)
+ ], limit=10000)
+
for product in products:
print("Calculate Rating Product OutOfDate", product)
+ product_variant = self.env['product.product'].search([('product_tmpl_id', '=', product.id)], limit=1)
rate = 0
if product.web_price:
rate += 1
@@ -93,6 +124,10 @@ class ProductTemplate(models.Model):
rate += 1
if product.image_128:
rate += 1
+ if product.website_description:
+ rate += 1
+ if product_variant.qty_stock_vendor > 0:
+ rate += 1
product.product_rating = rate
product.last_calculate_rating = current_time
@@ -109,10 +144,11 @@ class ProductProduct(models.Model):
def _compute_web_price(self):
for product in self:
- product_pricelist_item = self.env['product.pricelist.item'].search([('pricelist_id', '=', 1),('product_id', '=', product.id)],limit=1)
+ product_pricelist_item = self.env['product.pricelist.item'].search(
+ [('pricelist_id', '=', 1), ('product_id', '=', product.id)], limit=1)
product.web_price = product_pricelist_item.fixed_price
def _compute_stock_vendor(self):
for product in self:
- stock_vendor = self.env['stock.vendor'].search([('product_variant_id', '=', product.id)],limit=1)
- product.qty_stock_vendor = stock_vendor.quantity+product.qty_available \ No newline at end of file
+ stock_vendor = self.env['stock.vendor'].search([('product_variant_id', '=', product.id)], limit=1)
+ product.qty_stock_vendor = stock_vendor.quantity + product.qty_available