diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-10-10 17:21:22 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-10-10 17:21:22 +0700 |
| commit | 9c36563c5eae2299f4bb9bdc2123299d7984d77d (patch) | |
| tree | 038bbd8d584d6dcb9ce1f3af421f0207de56a7f7 | |
| parent | a8030033bac10dd7f343e4bbb0acef44c6e865a6 (diff) | |
Update product_template.py
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 51 |
1 files changed, 38 insertions, 13 deletions
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 |
