diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-05-03 15:09:11 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-05-03 15:09:11 +0700 |
| commit | 515addbceca9df25b3aaf440e8687286620d603a (patch) | |
| tree | 8e081a84df8705912c67ac7edf50cab68d0c9009 | |
| parent | 02d95b8fbc4faf0045d293514ce63de358fa7645 (diff) | |
update virtual product rating to solr
| -rw-r--r-- | indoteknik_custom/models/apache_solr.py | 2 | ||||
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 63 | ||||
| -rwxr-xr-x | indoteknik_custom/views/product_template.xml | 1 |
3 files changed, 31 insertions, 35 deletions
diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py index ebe516a0..72584a8f 100644 --- a/indoteknik_custom/models/apache_solr.py +++ b/indoteknik_custom/models/apache_solr.py @@ -73,7 +73,7 @@ class ApacheSolr(models.Model): 'display_name_s': template.display_name, 'name_s': template.name, 'default_code_s': template.default_code or '', - 'product_rating_f': template.product_rating, + 'product_rating_f': template.virtual_rating, 'product_id_i': template.id, 'image_s': self.env['ir.attachment'].api_image('product.template', 'image_512', template.id), 'price_f': price_excl, diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 74b4edb1..a43d8dc2 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -29,6 +29,7 @@ class ProductTemplate(models.Model): 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", default=0.0) + virtual_rating = fields.Float('Virtual Rating', compute='_compute_virtual_rating', help="Column Virtual untuk product rating, digunakan oleh Solr", default=0.0) 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', default=0.0) virtual_qty = fields.Float(string='Virtual Qty', default=0) @@ -53,6 +54,21 @@ class ProductTemplate(models.Model): # vals['solr_flag'] = 2 # return super().write(vals) + def _compute_virtual_rating(self): + for product in self: + rate = 0 + if product.web_price: + rate += 1 + if product.have_promotion_program: #have discount from pricelist + rate += 1 + if product.image_128: + rate += 5 + if product.website_description: + rate += 1 + if product.product_variant_id.qty_stock_vendor > 0: + rate += 1 + product.virtual_rating = rate + def update_new_product(self): current_time = datetime.now() delta_time = current_time - timedelta(days=30) @@ -111,21 +127,21 @@ 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 = 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) + ('product_id', '=', template.product_variant_id.id)], limit=1) price = product_pricelist_item.fixed_price template.web_price = price def _have_promotion_program(self): for template in self: - product = self.env['product.product'].search([('product_tmpl_id', '=', template.id)], limit=1) + # product = self.env['product.product'].search([('product_tmpl_id', '=', template.id)], limit=1) product_pricelist_item = self.env['product.pricelist.item'].search([ ('pricelist_id', '=', 4), - ('product_id', '=', product.id)], limit=1) + ('product_id', '=', template.product_variant_id.id)], limit=1) discount = product_pricelist_item.price_discount if discount: template.have_promotion_program = True @@ -134,6 +150,7 @@ class ProductTemplate(models.Model): @api.model def _calculate_rating_product(self): + #["&","&",["type","=","product"],["active","=",True],"|",["last_calculate_rating","=",False],["last_calculate_rating","<","2023-01-01 00:00:00"]] current_time = datetime.now() delta_time = current_time - timedelta(days=30) @@ -141,51 +158,29 @@ class ProductTemplate(models.Model): delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') products = self.env['product.template'].search([ + '&','&', ('type', '=', 'product'), ('active', '=', True), + '|', ('last_calculate_rating', '=', False), + ('last_calculate_rating', '<', delta_time), # ('id', '=', 22798), - ], limit=100) + ], limit=500) 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 - product.web_price_sorting = product.web_price - if product.have_promotion_program: - 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 - - products = self.env['product.template'].search([ - ('type', '=', 'product'), - ('active', '=', True), - ('last_calculate_rating', '<', delta_time), - ], limit=100) - - for product in products: - print("Calculate Rating Product OutOfDate", product) - product_variant = self.env['product.product'].search([('product_tmpl_id', '=', product.id)], limit=1) + # product_variant = self.env['product.product'].search([('product_tmpl_id', '=', product.id)], limit=1) rate = 0 if product.web_price: rate += 1 - product.web_price_sorting = product.web_price - if product.have_promotion_program: + if product.have_promotion_program: #have discount from pricelist rate += 1 if product.image_128: - rate += 1 + rate += 5 if product.website_description: rate += 1 - if product_variant.qty_stock_vendor > 0: + if product.product_variant_id.qty_stock_vendor > 0: rate += 1 product.product_rating = rate product.last_calculate_rating = current_time diff --git a/indoteknik_custom/views/product_template.xml b/indoteknik_custom/views/product_template.xml index 5fcb8b05..558805b1 100755 --- a/indoteknik_custom/views/product_template.xml +++ b/indoteknik_custom/views/product_template.xml @@ -53,6 +53,7 @@ <field name="usage"/> <field name="specification"/> <field name="material"/> + <field name="virtual_rating"/> <field name="search_rank"/> <field name="solr_flag"/> </field> |
