summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-07-24 10:30:22 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-07-24 10:30:22 +0700
commit30909e82d7ff1f3cac4700e284f80552a0d38523 (patch)
treed7653cccf81703a5e0bebb7d68dd8daeb3c411ce
parentbc0c9e782140d82dc2147afb4a049c37141b081a (diff)
Delete unused model
-rw-r--r--indoteknik_custom/models/typesense_client.py150
1 files changed, 0 insertions, 150 deletions
diff --git a/indoteknik_custom/models/typesense_client.py b/indoteknik_custom/models/typesense_client.py
deleted file mode 100644
index fccd04e3..00000000
--- a/indoteknik_custom/models/typesense_client.py
+++ /dev/null
@@ -1,150 +0,0 @@
-from odoo import models
-import typesense
-import logging
-import time
-
-
-_logger = logging.getLogger(__name__)
-_typesense = typesense.Client({
- 'nodes': [{
- 'host': 'localhost',
- 'port': '9090',
- 'protocol': 'http'
- }],
- 'api_key': 'WKWKdwakdjopwakfoij21321fkdmvaskamd'
-})
-
-class Typesense(models.Model):
- _name = 'typesense.client'
-
- def _check_collection(self, name):
- collections = _typesense.collections.retrieve()
- for collection in collections:
- if collection['name'] == name:
- return True
- return False
-
- def _init_collection(self, name):
- is_exist = self._check_collection(name)
- if is_exist:
- return False
-
- schema = {
- "name": name,
- "fields": [
- {"name": ".*", "type": "auto" },
- {"name": ".*_facet", "type": "auto", "facet": True }
- ]
- }
- _typesense.collections.create(schema)
- return True
-
- def _indexing_product(self, limit=500):
- start_time = time.time()
- self._init_collection('products')
-
- query = ["&", "&", ("type", "=", "product"), ("active", "=", True), "|", ("solr_flag", "=", 0), ("solr_flag", "=", 2)]
- product_templates = self.env['product.template'].search(query, limit=limit)
-
- counter = 0
- documents = []
- for product_template in product_templates:
- counter += 1
- template_time = time.time()
- document = self._map_product_document(product_template)
- documents.append(document)
- product_template.solr_flag = 1
- _logger.info('[SYNC_PRODUCT_TO_TYPESENSE] {}/{} {:.6f}'.format(counter, limit, time.time() - template_time))
- _logger.info('[SYNC_PRODUCT_TO_TYPESENSE] Success add to typesense product %s' % product_template.id)
-
- _typesense.collections['products'].documents.import_(documents, {'action': 'upsert'})
- end_time = time.time()
- _logger.info("[SYNC_PRODUCT_TO_SOLR] Finish task add to solr. Time taken: {:.6f} seconds".format(end_time - start_time))
-
- def _map_product_document(self, product_template):
- price_excl_after_disc = price_excl = discount = tax = 0
- variants_name = variants_code = ''
- flashsale_data = tier1 = tier2 = tier3 = {}
- if product_template.product_variant_count > 1:
- for variant in product_template.product_variant_ids:
- 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()
- 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()
- else:
- price_excl_after_disc = price_excl_after_disc
- price_excl = price_excl
- discount = discount
- tax = tax
- flashsale_data = flashsale_data
- tier1 = tier1
- tier2 = tier2
- tier3 = tier3
- variants_name += variant.display_name or ''+', '
- variants_code += variant.default_code or ''+', '
- else:
- variants_name = product_template.display_name
- price_excl = product_template.product_variant_id._get_website_price_exclude_tax()
- discount = product_template.product_variant_id._get_website_disc(0)
- price_excl_after_disc = product_template.product_variant_id._get_website_price_after_disc_and_tax()
- tax = product_template.product_variant_id._get_website_tax()
- flashsale_data = product_template.product_variant_id._get_flashsale_price()
- tier1 = product_template.product_variant_id._get_pricelist_tier1()
- tier2 = product_template.product_variant_id._get_pricelist_tier2()
- tier3 = product_template.product_variant_id._get_pricelist_tier3()
-
- category_id = ''
- category_name = ''
- for category in product_template.public_categ_ids:
- category_id = category.id
- category_name = category.name
-
- document = {
- 'id': str(product_template.id),
- 'display_name': product_template.display_name,
- 'name': product_template.name,
- 'default_code': product_template.default_code or '',
- 'product_rating': product_template.virtual_rating,
- 'product_id': product_template.id,
- 'image': self.env['ir.attachment'].api_image('product.template', 'image_512', product_template.id),
- 'price': price_excl,
- 'discount': discount,
- 'price_discount': price_excl_after_disc,
- 'tax': tax,
- 'variant_total': product_template.product_variant_count,
- 'stock_total': product_template.qty_stock_vendor,
- 'weight': product_template.weight,
- 'manufacture_id': product_template.x_manufacture.id or 0,
- 'manufacture_name': product_template.x_manufacture.x_name or '',
- 'manufacture_name': product_template.x_manufacture.x_name or '',
- 'image_promotion_1': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_1', product_template.x_manufacture.id),
- 'image_promotion_2': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_2', product_template.x_manufacture.id),
- 'category_id': category_id or 0,
- 'category_name': category_name or '',
- 'category_name': category_name or '',
- 'variants_name_t': variants_name,
- 'variants_code_t': variants_code,
- 'search_rank': product_template.search_rank,
- 'search_rank_weekly': product_template.search_rank_weekly,
- 'flashsale_id': flashsale_data['flashsale_id'] or 0,
- 'flashsale_name': flashsale_data['flashsale_name'] or '',
- 'flashsale_base_price': flashsale_data['flashsale_base_price'] or 0,
- 'flashsale_discount': flashsale_data['flashsale_discount'] or 0,
- 'flashsale_price': flashsale_data['flashsale_price'] or 0,
- 'discount_tier1': tier1['discount_tier1'] or 0,
- 'price_tier1': tier1['price_tier1'] or 0,
- 'discount_tier2': tier2['discount_tier2'] or 0,
- 'price_tier2': tier2['price_tier2'] or 0,
- 'discount_tier3': tier3['discount_tier3'] or 0,
- 'price_tier3': tier3['price_tier3'] or 0
- }
-
- return document
-
-