diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2023-09-29 02:32:56 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2023-09-29 02:32:56 +0000 |
| commit | 78f205302c35cab2512971d64c8152aab2dcfa95 (patch) | |
| tree | 72be75ad949fe9efaf7b55c8f7f5722225538b28 /indoteknik_custom/models/solr | |
| parent | 50b5bd7bd984ef108e8bd324440050a222d8262f (diff) | |
| parent | 0bb47005022b33c79ecfb5924d41f35ce794c5fb (diff) | |
Merged in production (pull request #126)
Production
Diffstat (limited to 'indoteknik_custom/models/solr')
| -rw-r--r-- | indoteknik_custom/models/solr/__init__.py | 3 | ||||
| -rw-r--r-- | indoteknik_custom/models/solr/apache_solr.py | 4 | ||||
| -rw-r--r-- | indoteknik_custom/models/solr/product_product.py | 40 | ||||
| -rw-r--r-- | indoteknik_custom/models/solr/product_template.py | 76 | ||||
| -rw-r--r-- | indoteknik_custom/models/solr/x_banner_banner.py | 4 | ||||
| -rw-r--r-- | indoteknik_custom/models/solr/x_banner_category.py | 54 | ||||
| -rw-r--r-- | indoteknik_custom/models/solr/x_manufactures.py | 5 |
7 files changed, 129 insertions, 57 deletions
diff --git a/indoteknik_custom/models/solr/__init__.py b/indoteknik_custom/models/solr/__init__.py index 16da73af..f2d13116 100644 --- a/indoteknik_custom/models/solr/__init__.py +++ b/indoteknik_custom/models/solr/__init__.py @@ -7,4 +7,5 @@ from . import product_template from . import website_categories_homepage from . import x_manufactures from . import x_banner_banner -from . import product_public_category
\ No newline at end of file +from . import product_public_category +from . import x_banner_category
\ No newline at end of file diff --git a/indoteknik_custom/models/solr/apache_solr.py b/indoteknik_custom/models/solr/apache_solr.py index eb02cb57..5acfded8 100644 --- a/indoteknik_custom/models/solr/apache_solr.py +++ b/indoteknik_custom/models/solr/apache_solr.py @@ -213,6 +213,8 @@ class ApacheSolr(models.Model): end_time = time.time() _logger.info("[SYNC_PRODUCT_TO_SOLR] Finish task add to solr. Time taken: {:.6f} seconds".format(end_time - start_time)) + return True + def _test_product_price(self, product_id=228178): product = self.env['product.product'].search([('id', '=', product_id)], limit=1) _logger.info('price incl tax: %s' % product._get_website_price_include_tax()) @@ -287,3 +289,5 @@ class ApacheSolr(models.Model): _variants_solr.add(documents) end_time = time.time() _logger.info("[SYNC_VARIANTS_TO_SOLR] Finish task add to solr. Time taken: {:.6f} seconds".format(end_time - start_time)) + + return False diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py index 93e26793..41af2d0e 100644 --- a/indoteknik_custom/models/solr/product_product.py +++ b/indoteknik_custom/models/solr/product_product.py @@ -31,8 +31,6 @@ class ProductProduct(models.Model): solr_model = self.env['apache.solr'] for variant in self: - if not variant.product_tmpl_id.active and variant.product_tmpl_id.type != 'product': - continue category_id = 0 category_name = '' @@ -64,7 +62,8 @@ class ProductProduct(models.Model): 'search_rank_i': variant.product_tmpl_id.search_rank, 'search_rank_weekly_i': variant.product_tmpl_id.search_rank_weekly, 'attributes': [x.name for x in variant.product_template_attribute_value_ids], - 'has_product_info_b': True + 'has_product_info_b': True, + 'publish_b': variant.product_tmpl_id.publish, }) self.solr().add(docs=[document], softCommit=True) @@ -78,18 +77,18 @@ class ProductProduct(models.Model): for variant in self: price_excl_after_disc = price_excl = discount = tax = 0 - flashsale_data = tier1 = tier2 = tier3 = {} + flashsale_data = {} if price_excl_after_disc == 0 or variant._get_website_price_after_disc_and_tax() < price_excl_after_disc: price_excl = variant._get_website_price_exclude_tax() price_excl_after_disc = variant._get_website_price_after_disc_and_tax() - discount = variant._get_website_disc(0) tax = variant._get_website_tax() + discount = variant._get_website_disc(0) flashsale_data = variant._get_flashsale_price() - # add price tiering for base price, discount, and price after discount (tier 1 - 3) - tier1 = variant._get_pricelist_tier1() - tier2 = variant._get_pricelist_tier2() - tier3 = variant._get_pricelist_tier3() + + price_excl_v2 = variant._v2_get_website_price_exclude_tax() + price_excl_after_disc_v2 = variant._v2_get_website_price_after_disc_and_tax() + tax_v2 = variant._v2_get_website_tax() document = solr_model.get_doc('variants', variant.id) document.update({ @@ -106,14 +105,23 @@ class ProductProduct(models.Model): "discount_f": discount, "price_discount_f": price_excl_after_disc, "tax_f": tax, - "discount_tier1_f": tier1.get('discount_tier1', 0), - "price_tier1_f": tier1.get('price_tier1', 0), - "discount_tier2_f": tier2.get('discount_tier2', 0), - "price_tier2_f": tier2.get('price_tier2', 0), - "discount_tier3_f": tier3.get('discount_tier3', 0), - "price_tier3_f": tier3.get('price_tier3', 0), - "has_price_info_b": True + "price_v2_f": price_excl_v2, + "price_discount_v2_f": price_excl_after_disc_v2, + "tax_v2_f": tax_v2, }) + + for tier_number in [1, 2, 3, '1_v2', '2_v2', '3_v2', '4_v2', '5_v2']: + tier = variant._get_pricelist_tier(tier_number) + document.update({ + f"discount_tier{tier_number}_f": tier.get(f'discount_tier{tier_number}', 0), + f"price_tier{tier_number}_f": tier.get(f'price_tier{tier_number}', 0), + }) + + # for tier_number in [1, 2, 3, '1_v2', '2_v2', '3_v2', '4_v2', '5_v2']: + # tier = tier_data[tier_number] + + document.update({"has_price_info_b": True}) + self.solr().add(docs=[document], softCommit=True) variant.change_solr_data('Ada perubahan pada harga product') diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index ea976359..b4782d1c 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -23,9 +23,21 @@ class ProductTemplate(models.Model): 'function_name': function_name }) - @api.constrains('active') - def _create_solr_queue_sync_active(self): - self._create_solr_queue('_sync_active_template_solr') + @api.constrains('active', 'type') + def constrains_active(self): + for template in self: + template.publish = template.active and template.type == 'product' + self._create_solr_queue('_sync_product_template_to_solr') + + @api.constrains('publish') + def constrains_publish(self): + for template in self: + if template.active and template.type == 'product': + continue + template.product_variant_ids.publish = template.publish + self._create_solr_queue('_sync_product_template_to_solr') + + constrains_active._priority = 1 @api.constrains('name', 'default_code', 'weight', 'x_manufacture', 'public_categ_ids', 'search_rank', 'search_rank_weekly', 'image_1920') def _create_solr_queue_sync_product_template(self): @@ -42,25 +54,10 @@ class ProductTemplate(models.Model): product._create_solr_queue('_sync_price_to_solr') product.solr_flag = 1 - def _sync_active_template_solr(self): - for template in self: - if not template.active or template.type != 'product': - template._sync_delete_solr() - else: - template._sync_product_template_to_solr() - template._sync_price_to_solr() - - products = self.env['product.product'].search( - [('product_tmpl_id', '=', template.id), ('active', 'in', [True, False])]) - products._sync_variants_to_solr() - def _sync_product_template_to_solr(self): solr_model = self.env['apache.solr'] for template in self: - if not template.active or template.type != 'product': - continue - 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]) @@ -96,10 +93,15 @@ class ProductTemplate(models.Model): "category_name": category_name, "description_t": template.website_description or '', 'has_product_info_b': True, + 'publish_b': template.publish }) self.solr().add(docs=[document], softCommit=True) - template.product_variant_ids._sync_variants_to_solr() + products = self.env['product.product'].search([ + ('product_tmpl_id', '=', template.id), + ('active', 'in', [True, False]) + ]) + products._sync_variants_to_solr() self.change_solr_data('Perubahan pada data product') if not document.get('has_price_info_b'): @@ -110,6 +112,8 @@ class ProductTemplate(models.Model): for template in self: flashsale_data = {} + price_excl = price_excl_after_disc = discount = tax = 0 + tier_data = {} for variant in template.product_variant_ids: variant_flashsale = variant._get_flashsale_price() @@ -123,9 +127,10 @@ class ProductTemplate(models.Model): price_excl_after_disc = variant._get_website_price_after_disc_and_tax() discount = variant._get_website_disc(0) tax = variant._get_website_tax() - tier1 = variant._get_pricelist_tier1() - tier2 = variant._get_pricelist_tier2() - tier3 = variant._get_pricelist_tier3() + + price_excl_v2 = variant._v2_get_website_price_exclude_tax() + price_excl_after_disc_v2 = variant._v2_get_website_price_after_disc_and_tax() + tax_v2 = variant._v2_get_website_tax() document = solr_model.get_doc('product', template.id) document.update({ @@ -142,28 +147,27 @@ class ProductTemplate(models.Model): "discount_f": discount, "price_discount_f": price_excl_after_disc, "tax_f": tax, - "discount_tier1_f": tier1.get('discount_tier1', 0), - "price_tier1_f": tier1.get('price_tier1', 0), - "discount_tier2_f": tier2.get('discount_tier2', 0), - "price_tier2_f": tier2.get('price_tier2', 0), - "discount_tier3_f": tier3.get('discount_tier3', 0), - "price_tier3_f": tier3.get('price_tier3', 0), - "has_price_info_b": True + "price_v2_f": price_excl_v2, + "price_discount_v2_f": price_excl_after_disc_v2, + "tax_v2_f": tax_v2, }) + for tier_number in [1, 2, 3, '1_v2', '2_v2', '3_v2', '4_v2', '5_v2']: + tier = variant._get_pricelist_tier(tier_number) + document.update({ + f"discount_tier{tier_number}_f": tier.get(f'discount_tier{tier_number}', 0), + f"price_tier{tier_number}_f": tier.get(f'price_tier{tier_number}', 0), + }) + + document.update({"has_price_info_b": True}) + self.solr().add(docs=[document], softCommit=True) template.product_variant_ids._sync_price_to_solr() template.change_solr_data('Ada perubahan pada harga product') if not document.get('has_product_info_b'): template._sync_product_template_to_solr() - - def _sync_delete_solr(self): - for rec in self: - self.solr().delete(rec.id) - for variant in rec.product_variant_ids: - variant._sync_delete_solr() - + def solr_results(self, detail=False): solr_model = self.env['apache.solr'] pricelist = self.env.user_pricelist diff --git a/indoteknik_custom/models/solr/x_banner_banner.py b/indoteknik_custom/models/solr/x_banner_banner.py index 5608a3d7..67739d47 100644 --- a/indoteknik_custom/models/solr/x_banner_banner.py +++ b/indoteknik_custom/models/solr/x_banner_banner.py @@ -46,8 +46,8 @@ class XBannerBanner(models.Model): 'background_color_s': banners.background_color or '', 'image_s': self.env['ir.attachment'].api_image('x_banner.banner', 'x_banner_image', banners.id), 'status_s': banners.x_status_banner or '', - 'categories': banners.x_banner_category.id or '', - 'manufactures': banners.x_relasi_manufacture.id or '', + 'category_id_i': banners.x_banner_category.id or '', + 'manufacture_id_i': banners.x_relasi_manufacture.id or '', 'group_by_week': banners.group_by_week or '', }) self.solr().add([document]) diff --git a/indoteknik_custom/models/solr/x_banner_category.py b/indoteknik_custom/models/solr/x_banner_category.py new file mode 100644 index 00000000..c73f6722 --- /dev/null +++ b/indoteknik_custom/models/solr/x_banner_category.py @@ -0,0 +1,54 @@ +from odoo import fields, models, api +from datetime import datetime + +class XBannerCategory(models.Model): + _inherit = "x_banner.category" + + last_update_solr = fields.Datetime(string='Last Update Solr') + + def update_last_update_solr(self): + self.last_update_solr = datetime.utcnow() + + def solr(self): + return self.env['apache.solr'].connect('banner_categories') + + def _create_solr_queue(self, function_name): + for rec in self: + self.env['apache.solr.queue'].create_unique({ + 'res_model': self._name, + 'res_id': rec.id, + 'function_name': function_name + }) + + @api.constrains('x_name', 'x_banner_subtitle', 'x_studio_field_KKVl4', 'banner_ids') + def _create_solr_queue_sync_banner_categories(self): + self._create_solr_queue('_sync_banner_categories_to_solr') + + def action_sync_to_solr(self): + banner_ids = self.env.context.get('active_ids', []) + banners = self.search([('id', 'in', banner_ids)]) + banners._create_solr_queue('_sync_banner_categories_to_solr') + + def _sync_banner_categories_to_solr(self): + for banners in self: + document = {} + document.update({ + 'id': banners.id, + 'display_name_s': banners.display_name, + 'name_s': banners.x_name, + 'banner_subtitle_s': banners.x_banner_subtitle or '', + 'x_studio_field_KKVl4_s': banners.x_studio_field_KKVl4 or '', + 'banners': [x.id for x in banners.banner_ids], + }) + self.solr().add([document]) + banners.update_last_update_solr() + + self.solr().commit() + + def unlink(self): + res = super(XBannerCategory, self).unlink() + for rec in self: + self.solr().delete(rec.id) + self.solr().optimize() + self.solr().commit() + return res
\ No newline at end of file diff --git a/indoteknik_custom/models/solr/x_manufactures.py b/indoteknik_custom/models/solr/x_manufactures.py index c0c321e4..375b7708 100644 --- a/indoteknik_custom/models/solr/x_manufactures.py +++ b/indoteknik_custom/models/solr/x_manufactures.py @@ -44,10 +44,11 @@ class XManufactures(models.Model): 'sequence_i': brands.sequence or '', 'negara_asal_s': brands.x_negara_asal or '', 'short_desc_s': brands.x_short_desc or '', + 'level_s': brands.x_manufacture_level or '', 'image_s': self.env['ir.attachment'].api_image('x_manufactures', 'x_logo_manufacture', brands.id), 'produk_aksesoris_sparepart_s': brands.x_produk_aksesoris_sparepart or '', - 'categories': [x.id for x in brands.category_ids], - 'banners': [x.id for x in brands.x_manufactures_banners], + 'category_ids': [x.id for x in brands.category_ids], + 'banner_ids': [x.id for x in brands.x_manufactures_banners], }) self.solr().add([document]) brands.update_last_update_solr() |
