diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-08-25 15:11:00 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-08-25 15:11:00 +0700 |
| commit | a9a3c3e8945dd11a0d81f64a5629876397a1e51d (patch) | |
| tree | e7d8850e7868b3f83e29f19bc37bcc9730922a4e /indoteknik_custom/models/product_template.py | |
| parent | 8424fbdfd66c6eca58d546c256d57a61e258e930 (diff) | |
Update sync solr function
Diffstat (limited to 'indoteknik_custom/models/product_template.py')
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 128 |
1 files changed, 3 insertions, 125 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 3caa3125..f72fa763 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -1,6 +1,6 @@ from odoo import fields, models, api -from datetime import datetime, timedelta, timezone -from odoo.exceptions import AccessError, UserError, ValidationError +from datetime import datetime, timedelta +from odoo.exceptions import UserError import logging import requests import json @@ -50,13 +50,6 @@ class ProductTemplate(models.Model): is_new_product = fields.Boolean(string='Produk Baru', help='Centang jika ingin ditammpilkan di website sebagai segment Produk Baru') seq_new_product = fields.Integer(string='Seq New Product', help='Urutan Sequence New Product') - last_update_solr = fields.Datetime(string='Last Update Solr') - desc_update_solr = fields.Char(string='Desc Update Solr') - - def change_solr_data(self, desc): - current_time = datetime.utcnow() - self.desc_update_solr = desc - self.last_update_solr = current_time def _compute_virtual_rating(self): for product in self: @@ -251,62 +244,6 @@ class ProductTemplate(models.Model): } self.env['token.storage'].create([values]) return values - - @api.constrains( - 'name', - 'default_code', - 'weight', - 'x_manufacture', - 'public_categ_ids', - 'product_variant_ids.display_name', - 'product_variant_ids.default_code', - 'search_rank', - 'search_rank_weekly', - 'image_1920' - ) - def _sync_product_template_to_solr(self, limit=500): - template = self - if not template.active or template.type != 'product': - return - - variant_names = ', '.join([x.display_name or '' for x in template.product_variant_ids]) - variant_codes = ', '.join([x.default_code or '' for x in template.product_variant_ids]) - - category_id = 0 - category_name = '' - for category in template.public_categ_ids: - category_id, category_name = category.id, category.name - break - - solr_model = self.env['apache.solr'] - solr = solr_model.connect('product') - document = solr_model.get_single_doc('product', template.id) - document.update({ - 'id': template.id, - 'display_name_s': template.display_name, - 'name_s': template.name, - 'default_code_s': template.default_code or '', - '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), - 'variant_total_i': template.product_variant_count, - 'stock_total_f': template.qty_stock_vendor, - 'weight_f': template.weight, - 'manufacture_id_i': template.x_manufacture.id or 0, - 'manufacture_name_s': template.x_manufacture.x_name or '', - 'manufacture_name': template.x_manufacture.x_name or '', - 'image_promotion_1_s': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_1', template.x_manufacture.id), - 'image_promotion_2_s': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_2', template.x_manufacture.id), - 'variants_name_t': variant_names, - 'variants_code_t': variant_codes, - 'search_rank_i': template.search_rank, - 'search_rank_weekly_i': template.search_rank_weekly, - 'category_id_i': category_id, - 'category_name_s': category_name, - 'category_name': category_name, - }) - solr.add([document]) - self.change_solr_data('Perubahan pada data product') class ProductProduct(models.Model): _inherit = "product.product" @@ -329,13 +266,6 @@ class ProductProduct(models.Model): qty_onhand_bandengan = fields.Float(string='Qty Incoming Bandengan', compute='_get_qty_onhand_bandengan') qty_incoming_bandengan = fields.Float(string='Qty Incoming Bandengan', compute='_get_qty_incoming_bandengan') sla_version = fields.Integer(string="SLA Version", default=0) - last_update_solr = fields.Datetime(string='Last Update Solr') - desc_update_solr = fields.Char(string='Desc Update Solr') - - def change_solr_data(self, desc): - current_time = datetime.now() - self.desc_update_solr = desc - self.last_update_solr = current_time def _get_qty_incoming_bandengan(self): for product in self: @@ -380,56 +310,4 @@ class ProductProduct(models.Model): ('end_date', '>=', current_time) ], limit=1) return pricelist - - @api.constrains( - 'name', - 'default_code', - 'virtual_rating', - 'weight', - 'x_manufacture', - 'public_categ_ids', - 'product_tmpl_id.default_code', - 'product_tmpl_id.image_1920', - 'search_rank', - 'search_rank_weekly', - 'image_1920' - ) - def _sync_variants_to_solr(self): - variant = self - if not variant.product_tmpl_id.active and variant.product_tmpl_id.type != 'product': - return - - category_id = 0 - category_name = '' - for category in variant.product_tmpl_id.public_categ_ids: - category_id = category.id - category_name = category.name - break - - solr_model = self.env['apache.solr'] - solr = solr_model.connect('variants') - document = solr_model.get_single_doc('variants', variant.id) - document.update({ - 'id': variant.id, - 'display_name_s': variant.display_name, - 'name_s': variant.name, - 'default_code_s': variant.default_code or '', - 'product_rating_f': variant.product_tmpl_id.virtual_rating, - 'product_id_i': variant.id, - 'template_id_i': variant.product_tmpl_id.id, - 'image_s': self.env['ir.attachment'].api_image('product.template', 'image_512', variant.product_tmpl_id.id), - 'stock_total_f': variant.qty_stock_vendor, - 'weight_f': variant.product_tmpl_id.weight, - 'manufacture_id_i': variant.product_tmpl_id.x_manufacture.id or 0, - 'manufacture_name_s': variant.product_tmpl_id.x_manufacture.x_name or '', - 'manufacture_name': variant.product_tmpl_id.x_manufacture.x_name or '', - 'image_promotion_1_s': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_1', variant.product_tmpl_id.x_manufacture.id), - 'image_promotion_2_s': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_2', variant.product_tmpl_id.x_manufacture.id), - 'category_id_i': category_id, - 'category_name_s': category_name, - 'category_name': category_name, - 'search_rank_i': variant.product_tmpl_id.search_rank, - 'search_rank_weekly_i': variant.product_tmpl_id.search_rank_weekly, - }) - solr.add([document]) - self.change_solr_data('Perubahan pada data product')
\ No newline at end of file +
\ No newline at end of file |
