From a09833c98b4dfeee1aff7bd8d5f899b2908e2146 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 10 Oct 2022 16:11:18 +0700 Subject: Update product_template.py --- indoteknik_custom/models/product_template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models/product_template.py') diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index a51f0600..60bcf1b1 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -63,7 +63,7 @@ class ProductTemplate(models.Model): products = self.env['product.template'].search([ ('type', '=', 'product'), ('active', '=', True), - ('last_calculate_rating', '!=', False), + ('last_calculate_rating', '=', False), ], limit=5000) for product in products: print("Calculate Rating Product ", product) -- cgit v1.2.3 From a8030033bac10dd7f343e4bbb0acef44c6e865a6 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 10 Oct 2022 16:44:10 +0700 Subject: Update product_template.py --- indoteknik_custom/models/product_template.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'indoteknik_custom/models/product_template.py') diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 60bcf1b1..0921cc79 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -71,6 +71,7 @@ class ProductTemplate(models.Model): if product.web_price: rate += 1 product.web_price_sorting = product.web_price + # TODO add calculate second discount if product.have_promotion_program: rate += 1 if product.image_128: @@ -93,6 +94,8 @@ class ProductTemplate(models.Model): rate += 1 if product.image_128: rate += 1 + if product.website_description: + rate += 1 product.product_rating = rate product.last_calculate_rating = current_time -- cgit v1.2.3 From 9c36563c5eae2299f4bb9bdc2123299d7984d77d Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 10 Oct 2022 17:21:22 +0700 Subject: Update product_template.py --- indoteknik_custom/models/product_template.py | 51 +++++++++++++++++++++------- 1 file changed, 38 insertions(+), 13 deletions(-) (limited to 'indoteknik_custom/models/product_template.py') diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 0921cc79..6454bc21 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,22 +26,41 @@ 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') + web_price_sorting = fields.Float('Web Price Sorting', + help='Hanya digunakan untuk sorting di web, harga tidak berlaku') def _compute_qty_stock_vendor(self): for product_template in self: product_template.qty_stock_vendor = 0 for product_variant in product_template.product_variant_ids: product_template.qty_stock_vendor += product_variant.qty_stock_vendor - + 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), + ('product_id', '=', product.id)], limit=1) + disc = product_pricelist_disc.price_discount + + product_pricelist_item = self.env['product.pricelist.item'].search([ + ('pricelist_id', '=', product_pricelist_disc.base_pricelist_id.id), + ('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: @@ -64,18 +86,20 @@ class ProductTemplate(models.Model): ('type', '=', 'product'), ('active', '=', True), ('last_calculate_rating', '=', False), - ], limit=5000) + ], limit=10000) for product in products: - print("Calculate Rating Product ", product) + # print("Calculate Rating Product ", product) + _logger.info("Calculate Rating Product %s" % product.id) rate = 0 if product.web_price: rate += 1 product.web_price_sorting = product.web_price - # TODO add calculate second discount if product.have_promotion_program: rate += 1 if product.image_128: rate += 1 + if product.website_description: + rate += 1 product.product_rating = rate product.last_calculate_rating = current_time @@ -83,7 +107,7 @@ 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) rate = 0 @@ -112,10 +136,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 -- cgit v1.2.3 From 378e076fa40fd7de2f2755e6ff2873264b24cd70 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 11 Oct 2022 08:30:11 +0700 Subject: Update product_template.py --- indoteknik_custom/models/product_template.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'indoteknik_custom/models/product_template.py') diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 6454bc21..ccbc9ff6 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -43,24 +43,24 @@ class ProductTemplate(models.Model): for template in self: 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), - ('product_id', '=', product.id)], limit=1) - disc = product_pricelist_disc.price_discount + # 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', '=', product_pricelist_disc.base_pricelist_id.id), + ('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 + # + # 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: -- cgit v1.2.3 From 1c09eab41878d452338d6b6a850550f03e8f1540 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 11 Oct 2022 15:23:21 +0700 Subject: Update product_template.py --- indoteknik_custom/models/product_template.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'indoteknik_custom/models/product_template.py') diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index ccbc9ff6..b1dcabb6 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -86,10 +86,13 @@ class ProductTemplate(models.Model): ('type', '=', 'product'), ('active', '=', True), ('last_calculate_rating', '=', False), + # ('id', '=', 22798), ], limit=10000) + for product in products: # 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 @@ -100,6 +103,8 @@ class ProductTemplate(models.Model): 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 @@ -108,8 +113,10 @@ class ProductTemplate(models.Model): ('active', '=', True), ('last_calculate_rating', '<', delta_time), ], 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 @@ -120,6 +127,8 @@ class ProductTemplate(models.Model): 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 -- cgit v1.2.3