diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-03-29 17:26:02 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-03-29 17:26:02 +0700 |
| commit | 2b7330d20b56014630097a978934787271754639 (patch) | |
| tree | b5d5819a8b6390f19a1418267c3a4cad1688be9e | |
| parent | 42c65ada49ff3e59d1b8c4763fba7abe3216eee4 (diff) | |
add solr implementation
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/apache_solr.py | 67 | ||||
| -rwxr-xr-x | indoteknik_custom/security/ir.model.access.csv | 3 |
3 files changed, 70 insertions, 1 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 00a90576..679004d1 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -57,3 +57,4 @@ from . import wati_contact from . import uangmuka_penjualan from . import uangmuka_pembelian from . import automatic_purchase +from . import apache_solr diff --git a/indoteknik_custom/models/apache_solr.py b/indoteknik_custom/models/apache_solr.py new file mode 100644 index 00000000..d957f4bb --- /dev/null +++ b/indoteknik_custom/models/apache_solr.py @@ -0,0 +1,67 @@ +from odoo import models, api, fields +from odoo.exceptions import UserError +from datetime import datetime +import logging +import pysolr + +_logger = logging.getLogger(__name__) + + +class ApacheSolr(models.Model): + _name = 'apache.solr' + _order = 'id desc' + + def _sync_product_to_solr(self): + _logger.info('run sync to solr...') + solr = pysolr.Solr('http://192.168.23.5:8983/solr/product/', timeout=100) + + templates = self.env['product.template'].search([ + ('solr_flag', '=', 0), + # ('id', '=', 21560) + ], limit=5000) + document = [] + for template in templates: + price_excl_after_disc = price_excl = 0 + variants_name = variants_code = '' + if template.product_variant_count > 1: + for variant in template.product_variant_ids: + if price_excl_after_disc == 0: + price_excl = variant._get_website_price_exclude_tax() + price_excl_after_disc = variant._get_website_price_after_disc_and_tax() + elif variant._get_website_price_after_disc_and_tax() < price_excl_after_disc: + price_excl_after_disc = variant._get_website_price_after_disc_and_tax() + price_excl = variant._get_website_price_exclude_tax() + else: + price_excl_after_disc = price_excl_after_disc + price_excl = price_excl + variants_name += variant.display_name+', ' + variants_code += variant.default_code+', ' + + document=[({ + 'id': template.id, + 'display_name_s': template.display_name, + 'name_s': template.name, + 'default_code_s': template.default_code, + 'product_rating_i': template.product_rating, + 'product_id_i': template.id, + 'image_s': self.env['ir.attachment'].api_image('product.template', 'image_512', template.id), + 'price_f': price_excl or template.product_variant_id._get_website_price_exclude_tax(), + 'price_discount_f': price_excl_after_disc or template.product_variant_id._get_website_price_after_disc_and_tax(), + 'tax_f': template.product_variant_id._get_website_tax(), + 'variant_total_i': template.product_variant_count, + 'stock_total_i': template.qty_stock_vendor, + 'weight_f': template.weight, + 'manufacture_id_i': template.x_manufacture.id or 0, + '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), + 'category_id_i': template.categ_id.id or 0, + 'category_name_s': template.categ_id.name, + 'variants_name_t': variants_name, + 'variants_code_t': variants_code, + 'search_rank_i': template.search_rank, + 'search_rank_weekly_i': template.search_rank_weekly, + 'active_b': template.active + })] + solr.add(document) + # add counter for monitoring + print(template.id) diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 41dc51bf..1788c77f 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -43,4 +43,5 @@ access_uangmuka_penjualan,access.uangmuka.penjualan,model_uangmuka_penjualan,,1, access_uangmuka_pembelian,access.uangmuka.pembelian,model_uangmuka_pembelian,,1,1,1,1 access_automatic_purchase,access.automatic.purchase,model_automatic_purchase,,1,1,1,1 access_automatic_purchase_line,access.automatic.purchase.line,model_automatic_purchase_line,,1,1,1,1 -access_automatic_purchase_match,access.automatic.purchase.match,model_automatic_purchase_match,,1,1,1,1
\ No newline at end of file +access_automatic_purchase_match,access.automatic.purchase.match,model_automatic_purchase_match,,1,1,1,1 +access_apache_solr,access.apache.solr,model_apache_solr,,1,1,1,1
\ No newline at end of file |
