From 215fde914a2eae20928b9e40a9a5dd1ac179c4e1 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 31 Aug 2023 14:06:21 +0700 Subject: fix error solr --- .../models/solr/product_pricelist_item.py | 24 ++-------------------- indoteknik_custom/models/solr/product_template.py | 1 + 2 files changed, 3 insertions(+), 22 deletions(-) (limited to 'indoteknik_custom/models/solr') diff --git a/indoteknik_custom/models/solr/product_pricelist_item.py b/indoteknik_custom/models/solr/product_pricelist_item.py index 6ab2f588..fa042480 100644 --- a/indoteknik_custom/models/solr/product_pricelist_item.py +++ b/indoteknik_custom/models/solr/product_pricelist_item.py @@ -6,25 +6,5 @@ class ProductPricelistItem(models.Model): @api.constrains('applied_on', 'product_id', 'base', 'base_pricelist_id', 'price_discount') def _constrains_related_solr_field(self): - self.update_template_solr() - self.update_variant_solr() - - def update_template_solr(self): - updated_template_ids = [] - for rec in self: - template = rec.product_id.product_tmpl_id - if template.id in updated_template_ids: - continue - - template._sync_price_to_solr() - updated_template_ids.append(template.id) - - def update_variant_solr(self): - updated_product_ids = [] - for rec in self: - product = rec.product_id - if product.id in updated_product_ids: - continue - - product._sync_price_to_solr() - updated_product_ids.append(product.id) \ No newline at end of file + for rec in self: + rec.product_id.product_tmpl_id._create_solr_queue('_sync_price_to_solr') \ No newline at end of file diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index 6ae0bec2..692eaa94 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -151,6 +151,7 @@ class ProductTemplate(models.Model): 'has_price_info_b': True }) self.solr().add([document]) + 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'): -- cgit v1.2.3 From eff76a5d9671ba8a39b58166e3df9428a1f10e0c Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 31 Aug 2023 14:14:43 +0700 Subject: move code to folder solr --- indoteknik_custom/models/solr/product_pricelist_item.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models/solr') diff --git a/indoteknik_custom/models/solr/product_pricelist_item.py b/indoteknik_custom/models/solr/product_pricelist_item.py index fa042480..3be8c4c0 100644 --- a/indoteknik_custom/models/solr/product_pricelist_item.py +++ b/indoteknik_custom/models/solr/product_pricelist_item.py @@ -7,4 +7,14 @@ class ProductPricelistItem(models.Model): @api.constrains('applied_on', 'product_id', 'base', 'base_pricelist_id', 'price_discount') def _constrains_related_solr_field(self): for rec in self: - rec.product_id.product_tmpl_id._create_solr_queue('_sync_price_to_solr') \ No newline at end of file + rec.product_id.product_tmpl_id._create_solr_queue('_sync_price_to_solr') + + def action_sync_to_solr(self): + active_ids = self.env.context.get('active_ids', []) + + for pricelist_item_id in active_ids: + pricelist = self.env['product.pricelist.item'].browse(pricelist_item_id) + + templates = self.env['product.template'].search([('id', 'in', [pricelist.product_id.product_tmpl_id.id])]) + + templates._create_solr_queue('_sync_price_to_solr') -- cgit v1.2.3 From a08e9a90e24159b8d3a22844dac4416809c5ddff Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 1 Sep 2023 14:19:16 +0700 Subject: Fix solr product template --- indoteknik_custom/models/solr/product_template.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models/solr') diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index 692eaa94..63daeb46 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -106,14 +106,17 @@ class ProductTemplate(models.Model): for template in self: price_excl_after_disc = price_excl = discount = tax = 0 flashsale_data = tier1 = tier2 = tier3 = {} - + for variant in template.product_variant_ids: if price_excl_after_disc == 0 or variant._get_website_price_after_disc_and_tax() < price_excl_after_disc: + variant_flashsale = variant._get_flashsale_price() + flashsale_price = flashsale_data.get('flashsale_price') + if not flashsale_price or variant_flashsale['flashsale_price'] < flashsale_data.get('flashsale_price', 0): + flashsale_data = variant_flashsale 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() - 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() -- cgit v1.2.3 From 513bce9e13dee0453ce24b41a54d3b408e58c7f0 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 5 Sep 2023 14:45:18 +0700 Subject: Fix bug solr product variants, add analytic tags to jurnal entries line, remove validation edit di purchase pricelist --- indoteknik_custom/models/solr/product_template.py | 42 +++++++++-------------- 1 file changed, 16 insertions(+), 26 deletions(-) (limited to 'indoteknik_custom/models/solr') diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index 63daeb46..9950c93a 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -104,35 +104,25 @@ class ProductTemplate(models.Model): solr = self.solr() for template in self: - price_excl_after_disc = price_excl = discount = tax = 0 - flashsale_data = tier1 = tier2 = tier3 = {} + document = solr_model.get_doc('product', template.id) + flashsale_data = {} for variant in template.product_variant_ids: - if price_excl_after_disc == 0 or variant._get_website_price_after_disc_and_tax() < price_excl_after_disc: - variant_flashsale = variant._get_flashsale_price() - flashsale_price = flashsale_data.get('flashsale_price') - if not flashsale_price or variant_flashsale['flashsale_price'] < flashsale_data.get('flashsale_price', 0): - flashsale_data = variant_flashsale - 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() - # 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() - - if template.product_variant_count == 1: - price_excl = template.product_variant_id._get_website_price_exclude_tax() - discount = template.product_variant_id._get_website_disc(0) - price_excl_after_disc = template.product_variant_id._get_website_price_after_disc_and_tax() - tax = template.product_variant_id._get_website_tax() - flashsale_data = template.product_variant_id._get_flashsale_price() - tier1 = template.product_variant_id._get_pricelist_tier1() - tier2 = template.product_variant_id._get_pricelist_tier2() - tier3 = template.product_variant_id._get_pricelist_tier3() + variant_flashsale = variant._get_flashsale_price() + variant_flashsale_price = variant_flashsale.get('flashsale_price', 0) + flashsale_data_price = flashsale_data.get('flashsale_price', 0) + + if flashsale_data_price == 0 or (variant_flashsale_price != 0 and variant_flashsale_price < flashsale_data_price): + flashsale_data = variant_flashsale + + 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() + tier1 = variant._get_pricelist_tier1() + tier2 = variant._get_pricelist_tier2() + tier3 = variant._get_pricelist_tier3() - document = solr_model.get_doc('product', template.id) document.update({ 'id': template.id, 'flashsale_id_i': flashsale_data.get('flashsale_id', 0), -- cgit v1.2.3