From 6d9ac5debfc7f8809e627900555301aac6ab6083 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 16 Oct 2023 15:24:28 +0700 Subject: Add qty sold field and solr data --- indoteknik_custom/models/solr/product_product.py | 1 + indoteknik_custom/models/solr/product_template.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models/solr') diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py index 31a0026d..720be7fa 100644 --- a/indoteknik_custom/models/solr/product_product.py +++ b/indoteknik_custom/models/solr/product_product.py @@ -64,6 +64,7 @@ class ProductProduct(models.Model): 'attributes': [x.name for x in variant.product_template_attribute_value_ids], 'has_product_info_b': True, 'publish_b': variant.product_tmpl_id.active and variant.product_tmpl_id.type == 'product', + 'qty_sold_f': variant.qty_sold }) self.solr().add(docs=[document], softCommit=True) diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index d7439bcb..cc8d4bf2 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -80,7 +80,8 @@ class ProductTemplate(models.Model): "category_name": category_name, "description_t": template.website_description or '', 'has_product_info_b': True, - 'publish_b': template.active and template.type == 'product' + 'publish_b': template.active and template.type == 'product', + "qty_sold_f": template.qty_sold }) self.solr().add(docs=[document], softCommit=True) -- cgit v1.2.3 From c70cca235282dc01134f105a2c45fc071f09ae9e Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 18 Oct 2023 10:04:57 +0700 Subject: Fix sync active product solr --- indoteknik_custom/models/solr/product_product.py | 10 ++++++++-- indoteknik_custom/models/solr/product_template.py | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models/solr') diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py index 720be7fa..15c910a5 100644 --- a/indoteknik_custom/models/solr/product_product.py +++ b/indoteknik_custom/models/solr/product_product.py @@ -1,4 +1,4 @@ -from odoo import models, fields +from odoo import models, fields, api from datetime import datetime @@ -186,4 +186,10 @@ class ProductProduct(models.Model): results.append(result) - return results \ No newline at end of file + return results + + @api.constrains('active') + def constrains_active(self): + for rec in self: + rec.product_tmpl_id._create_solr_queue_sync_product_template() + \ 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 cc8d4bf2..f178dd5f 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -221,3 +221,8 @@ class ProductTemplate(models.Model): results.append(result) return results + + @api.constrains('active') + def constrains_active(self): + for rec in self: + rec._create_solr_queue_sync_product_template() \ No newline at end of file -- cgit v1.2.3 From a07d76148eb51f4cdb263f915371208cc2f4b05d Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 18 Oct 2023 10:17:39 +0700 Subject: Fix variant publish condition solr --- indoteknik_custom/models/solr/product_product.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models/solr') diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py index 15c910a5..567e2a3e 100644 --- a/indoteknik_custom/models/solr/product_product.py +++ b/indoteknik_custom/models/solr/product_product.py @@ -63,7 +63,7 @@ class ProductProduct(models.Model): '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, - 'publish_b': variant.product_tmpl_id.active and variant.product_tmpl_id.type == 'product', + 'publish_b': variant.active and variant.type == 'product', 'qty_sold_f': variant.qty_sold }) -- cgit v1.2.3 From 1292cb9fc57d972dec21a13df874099cf6d8bef2 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 19 Oct 2023 16:03:34 +0700 Subject: Fix product price calculation for solr --- indoteknik_custom/models/solr/product_product.py | 46 ++++--------- indoteknik_custom/models/solr/product_template.py | 82 +++++++++++------------ 2 files changed, 53 insertions(+), 75 deletions(-) (limited to 'indoteknik_custom/models/solr') diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py index 567e2a3e..e1342fc2 100644 --- a/indoteknik_custom/models/solr/product_product.py +++ b/indoteknik_custom/models/solr/product_product.py @@ -75,24 +75,12 @@ class ProductProduct(models.Model): def _sync_price_to_solr(self): solr_model = self.env['apache.solr'] + TIER_NUMBERS = ['1_v2', '2_v2', '3_v2', '4_v2', '5_v2'] for variant in self: - price_excl_after_disc = price_excl = discount = tax = 0 - flashsale_data = {} + flashsale_data = variant.with_context(price_for="web")._get_flashsale_price() - 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() - tax = variant._get_website_tax() - discount = variant._get_website_disc(0) - flashsale_data = variant.with_context(price_for="web")._get_flashsale_price() - - 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({ + flashsale_doc = { "id": variant.id, "flashsale_id_i": flashsale_data.get('flashsale_id', 0), "flashsale_tag_s": flashsale_data.get('flashsale_tag', ''), @@ -102,25 +90,19 @@ class ProductProduct(models.Model): "flashsale_base_price_f": flashsale_data.get('flashsale_base_price', 0), "flashsale_discount_f": flashsale_data.get('flashsale_discount', 0), "flashsale_price_f": flashsale_data.get('flashsale_price', 0), - "price_f": price_excl, - "discount_f": discount, - "price_discount_f": price_excl_after_disc, - "tax_f": tax, - "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']: + } + + price_doc = {} + + for tier_number in TIER_NUMBERS: 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] + price_doc[f"discount_tier{tier_number}_f"] = tier.get(f'discount_tier{tier_number}', 0) + price_doc[f"price_tier{tier_number}_f"] = tier.get(f'price_tier{tier_number}', 0) + document = solr_model.get_doc('variants', variant.id) + document['id'] = variant.id + document.update(flashsale_doc) + document.update(price_doc) document.update({"has_price_info_b": True}) self.solr().add(docs=[document], softCommit=True) diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index f178dd5f..aa1708cc 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -97,56 +97,52 @@ class ProductTemplate(models.Model): def _sync_price_to_solr(self): solr_model = self.env['apache.solr'] + TIER_NUMBERS = ['1_v2', '2_v2', '3_v2', '4_v2', '5_v2'] for template in self: - flashsale_data = {} - price_excl = price_excl_after_disc = discount = tax = 0 - tier_data = {} + cheapest_flashsale = {} for variant in template.product_variant_ids: variant_flashsale = variant.with_context(price_for="web")._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() - - 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() - + cheapest_flashsale_price = cheapest_flashsale.get('flashsale_price', 0) + + if cheapest_flashsale_price == 0 or (variant_flashsale_price != 0 and variant_flashsale_price < cheapest_flashsale_price): + cheapest_flashsale = variant_flashsale + + flashsale_doc = { + "flashsale_id_i": cheapest_flashsale.get('flashsale_id', 0), + "flashsale_tag_s": cheapest_flashsale.get('flashsale_tag', ''), + "flashsale_name_s": cheapest_flashsale.get('flashsale_name', ''), + "flashsale_start_date_s": cheapest_flashsale.get('flashsale_start_date', ''), + "flashsale_end_date_s": cheapest_flashsale.get('flashsale_end_date', ''), + "flashsale_base_price_f": cheapest_flashsale.get('flashsale_base_price', 0), + "flashsale_discount_f": cheapest_flashsale.get('flashsale_discount', 0), + "flashsale_price_f": cheapest_flashsale.get('flashsale_price', 0) + } + + price_doc = {} + + # Loop tier to get each variant price + for tier_number in TIER_NUMBERS: + for variant in template.product_variant_ids: + tier = variant._get_pricelist_tier(tier_number) + discount_tier_key = f'discount_tier{tier_number}' + price_tier_key = f'price_tier{tier_number}' + + variant_discount = tier.get(discount_tier_key, 0) + variant_price = tier.get(price_tier_key, 0) + + price_tier = price_doc.get(f"{price_tier_key}_f", 0) + # When price tier is 0 or variant_price less than price tier then use variant price + if price_tier == 0 or variant_price < price_tier: + price_doc[f"{discount_tier_key}_f"] = variant_discount + price_doc[f"{price_tier_key}_f"] = variant_price + document = solr_model.get_doc('product', template.id) - document.update({ - "id": template.id, - "flashsale_id_i": flashsale_data.get('flashsale_id', 0), - "flashsale_tag_s": flashsale_data.get('flashsale_tag', ''), - "flashsale_name_s": flashsale_data.get('flashsale_name', ''), - "flashsale_start_date_s": flashsale_data.get('flashsale_start_date', ''), - "flashsale_end_date_s": flashsale_data.get('flashsale_end_date', ''), - "flashsale_base_price_f": flashsale_data.get('flashsale_base_price', 0), - "flashsale_discount_f": flashsale_data.get('flashsale_discount', 0), - "flashsale_price_f": flashsale_data.get('flashsale_price', 0), - "price_f": price_excl, - "discount_f": discount, - "price_discount_f": price_excl_after_disc, - "tax_f": tax, - "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['id'] = template.id + document.update(flashsale_doc) + document.update(price_doc) document.update({"has_price_info_b": True}) self.solr().add(docs=[document], softCommit=True) -- cgit v1.2.3 From 49d7b473a8cd458ade6a4e703c276b0771707db2 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 20 Oct 2023 15:31:03 +0700 Subject: Add unpublished field on product template and variant --- indoteknik_custom/models/solr/product_product.py | 10 +++++++--- indoteknik_custom/models/solr/product_template.py | 5 +++-- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'indoteknik_custom/models/solr') diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py index e1342fc2..85c94741 100644 --- a/indoteknik_custom/models/solr/product_product.py +++ b/indoteknik_custom/models/solr/product_product.py @@ -5,6 +5,7 @@ from datetime import datetime class ProductProduct(models.Model): _inherit = 'product.product' + unpublished = fields.Boolean(string='Unpublished') last_update_solr = fields.Datetime(string='Last Update Solr') desc_update_solr = fields.Char(string='Desc Update Solr') @@ -63,7 +64,7 @@ class ProductProduct(models.Model): '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, - 'publish_b': variant.active and variant.type == 'product', + 'publish_b': not variant.unpublished, 'qty_sold_f': variant.qty_sold }) @@ -170,8 +171,11 @@ class ProductProduct(models.Model): return results - @api.constrains('active') - def constrains_active(self): + @api.constrains('unpublished') + def _constrains_unpublished(self): for rec in self: + if rec.product_variant_count == 1: + rec.product_tmpl_id.unpublished = rec.unpublished + rec.product_tmpl_id._create_solr_queue_sync_product_template() \ 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 aa1708cc..25d7d4b8 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -5,6 +5,7 @@ from datetime import datetime class ProductTemplate(models.Model): _inherit = "product.template" + unpublished = fields.Boolean(string='Unpublished') last_update_solr = fields.Datetime(string='Last Update Solr') desc_update_solr = fields.Char(string='Desc Update Solr') @@ -23,7 +24,7 @@ class ProductTemplate(models.Model): 'function_name': function_name }) - @api.constrains('name', 'default_code', 'weight', 'x_manufacture', 'public_categ_ids', 'search_rank', 'search_rank_weekly', 'image_1920', 'active') + @api.constrains('name', 'default_code', 'weight', 'x_manufacture', 'public_categ_ids', 'search_rank', 'search_rank_weekly', 'image_1920', 'unpublished') def _create_solr_queue_sync_product_template(self): self._create_solr_queue('_sync_product_template_to_solr') @@ -80,7 +81,7 @@ class ProductTemplate(models.Model): "category_name": category_name, "description_t": template.website_description or '', 'has_product_info_b': True, - 'publish_b': template.active and template.type == 'product', + 'publish_b': not template.unpublished, "qty_sold_f": template.qty_sold }) -- cgit v1.2.3 From 5ddda2a380e9aeaf63241e8f6b1c35e3005a3468 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 23 Oct 2023 15:36:50 +0700 Subject: Add action on sync by solr flag --- indoteknik_custom/models/solr/product_product.py | 1 + indoteknik_custom/models/solr/product_template.py | 1 + 2 files changed, 2 insertions(+) (limited to 'indoteknik_custom/models/solr') diff --git a/indoteknik_custom/models/solr/product_product.py b/indoteknik_custom/models/solr/product_product.py index 85c94741..03eaaf13 100644 --- a/indoteknik_custom/models/solr/product_product.py +++ b/indoteknik_custom/models/solr/product_product.py @@ -25,6 +25,7 @@ class ProductProduct(models.Model): def variant_solr_flag_to_solr(self, limit=500): variant_products = self.search([('solr_flag', '=', 2)], limit=limit) for product in variant_products: + product.product_tmpl_id._create_solr_queue('_sync_product_template_to_solr') product.product_tmpl_id._create_solr_queue('_sync_price_to_solr') product.solr_flag = 1 diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py index 25d7d4b8..2bbcab9c 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -36,6 +36,7 @@ class ProductTemplate(models.Model): def solr_flag_to_solr(self, limit=500): template_products = self.search([('solr_flag', '=', 2)], limit=limit) for product in template_products: + product._create_solr_queue('_sync_product_template_to_solr') product._create_solr_queue('_sync_price_to_solr') product.solr_flag = 1 -- cgit v1.2.3 From 5bb681f2975a3fb38fcd87c89f72d18c6e794170 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Sat, 28 Oct 2023 10:07:00 +0700 Subject: Bug fix condition sync product price to solr --- indoteknik_custom/models/solr/product_template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 2bbcab9c..648a0625 100644 --- a/indoteknik_custom/models/solr/product_template.py +++ b/indoteknik_custom/models/solr/product_template.py @@ -137,7 +137,7 @@ class ProductTemplate(models.Model): price_tier = price_doc.get(f"{price_tier_key}_f", 0) # When price tier is 0 or variant_price less than price tier then use variant price - if price_tier == 0 or variant_price < price_tier: + if price_tier == 0 or (variant_price < price_tier and variant_price > 0): price_doc[f"{discount_tier_key}_f"] = variant_discount price_doc[f"{price_tier_key}_f"] = variant_price -- cgit v1.2.3 From c114fc17c7502174415c4e4bf1e7f8e24a46998c Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 30 Oct 2023 08:59:11 +0700 Subject: Change name manufacture on solr to lowercase --- indoteknik_custom/models/solr/x_manufactures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models/solr') diff --git a/indoteknik_custom/models/solr/x_manufactures.py b/indoteknik_custom/models/solr/x_manufactures.py index 375b7708..98b1d01d 100644 --- a/indoteknik_custom/models/solr/x_manufactures.py +++ b/indoteknik_custom/models/solr/x_manufactures.py @@ -40,7 +40,7 @@ class XManufactures(models.Model): document.update({ 'id': brands.id, 'display_name_s': brands.display_name, - 'name_s': brands.x_name, + 'name_s': brands.x_name.lower(), 'sequence_i': brands.sequence or '', 'negara_asal_s': brands.x_negara_asal or '', 'short_desc_s': brands.x_short_desc or '', -- cgit v1.2.3 From b4e74170aeaf00937f78e5af9047218ddb17516c Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 10 Nov 2023 13:37:46 +0700 Subject: Add parameter on delete weekly solr --- indoteknik_custom/models/solr/apache_solr_queue.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models/solr') diff --git a/indoteknik_custom/models/solr/apache_solr_queue.py b/indoteknik_custom/models/solr/apache_solr_queue.py index 8dd7c273..07274295 100644 --- a/indoteknik_custom/models/solr/apache_solr_queue.py +++ b/indoteknik_custom/models/solr/apache_solr_queue.py @@ -72,11 +72,12 @@ class ApacheSolrQueue(models.Model): if count == 0: self.create(payload) - def delete_weekly_solr(self, limit=500): + def delete_weekly_solr(self, limit=500, days_after=30): solr = self.search([ ('execute_status', '=', 'success'), - ('execute_date', '>=', (datetime.utcnow() - timedelta(days=7))), + ('execute_date', '>=', (datetime.utcnow() - timedelta(days=days_after))), ], limit=limit) + for rec in solr: rec.unlink() -- cgit v1.2.3