summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/solr
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2023-09-11 11:55:47 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2023-09-11 11:55:47 +0700
commit02c2304b242245250177fec6ab3c911d9acba781 (patch)
treec6e905a5d99e9f50c3cfeb30a43f530533a5706c /indoteknik_custom/models/solr
parent439f7252866ae30b548326ad25f241e513f0fe85 (diff)
auto sync banner to solr, auto sync ecommerce categories to solr, add field carrier to stock_picking
Diffstat (limited to 'indoteknik_custom/models/solr')
-rw-r--r--indoteknik_custom/models/solr/__init__.py4
-rw-r--r--indoteknik_custom/models/solr/product_public_category.py72
-rw-r--r--indoteknik_custom/models/solr/website_categories_homepage.py2
-rw-r--r--indoteknik_custom/models/solr/x_banner_banner.py64
-rw-r--r--indoteknik_custom/models/solr/x_manufactures.py6
5 files changed, 143 insertions, 5 deletions
diff --git a/indoteknik_custom/models/solr/__init__.py b/indoteknik_custom/models/solr/__init__.py
index 9a13de77..45013d3d 100644
--- a/indoteknik_custom/models/solr/__init__.py
+++ b/indoteknik_custom/models/solr/__init__.py
@@ -4,4 +4,6 @@ from . import product_pricelist_item
from . import product_product
from . import product_template
from . import website_categories_homepage
-from . import x_manufactures \ No newline at end of file
+from . import x_manufactures
+from . import x_banner_banner
+from . import product_public_category \ No newline at end of file
diff --git a/indoteknik_custom/models/solr/product_public_category.py b/indoteknik_custom/models/solr/product_public_category.py
new file mode 100644
index 00000000..0bb34674
--- /dev/null
+++ b/indoteknik_custom/models/solr/product_public_category.py
@@ -0,0 +1,72 @@
+from odoo import models, fields, api
+import logging
+from datetime import datetime
+
+_logger = logging.getLogger(__name__)
+
+class ProductPublicCategory(models.Model):
+ _inherit = "product.public.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('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_url_banner', 'background_color', 'x_banner_image', 'x_banner_category', 'x_relasi_manufacture', 'x_sequence_banner', 'x_status_banner', 'sequence', 'group_by_week')
+ def _create_solr_queue_sync_brands(self):
+ self._create_solr_queue('_sync_categories_to_solr')
+
+ def action_sync_to_solr(self):
+ banner_ids = self.env.context.get('active_ids', [])
+ categories = self.search([('id', 'in', banner_ids)])
+ categories._create_solr_queue('_sync_categories_to_solr')
+
+ def _sync_categories_to_solr(self):
+ for category in self:
+ parent = category.parent_id and category.parent_id[0]
+ parent_frontend = category.parent_frontend_id and category.parent_frontend_id[0]
+
+ document = {
+ 'id': category.id,
+ 'display_name_s': category.display_name,
+ 'name_s': category.name,
+ 'english_name_s': category.english_name or '',
+ 'name_2_s': category.x_studio_field_d1HS4 or '',
+ 'name_3_s': category.x_studio_field_f54P2 or '',
+ 'nama_alias_s': category.x_studio_field_BfNp2 or '',
+ 'parent_id_i': parent.id if parent else 0,
+ 'parent_name_s': parent.name if parent else '',
+ 'sequence_i': category.sequence or 0,
+ 'website_meta_title_s': category.website_meta_title or '',
+ 'website_meta_keywords_s': category.website_meta_keywords or '',
+ 'website_meta_desc_t': category.website_meta_description or '',
+ 'tampil_di_index_b': category.x_studio_field_4qhoN or '',
+ 'sequence_frontend_i': category.sequence_frontend or 0,
+ 'parent_frontend_id_i': parent_frontend.id if parent_frontend else 0,
+ 'parent_frontend_name_s': parent_frontend.name if parent_frontend else '',
+ 'product_template': [x.id for x in category.product_tmpl_ids],
+ }
+
+ self.solr().add([document])
+ category.update_last_update_solr()
+
+ self.solr().commit()
+
+ def unlink(self):
+ res = super(ProductPublicCategory, 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/website_categories_homepage.py b/indoteknik_custom/models/solr/website_categories_homepage.py
index 68a9eb7b..75d84e73 100644
--- a/indoteknik_custom/models/solr/website_categories_homepage.py
+++ b/indoteknik_custom/models/solr/website_categories_homepage.py
@@ -48,7 +48,7 @@ class WebsiteCategoriesHomepage(models.Model):
if rec.status == 'tayang':
rec._sync_category_homepage_to_solr()
else:
- rec._sync_delete_solr()
+ rec.unlink()
def _sync_category_homepage_to_solr(self):
solr_model = self.env['apache.solr']
diff --git a/indoteknik_custom/models/solr/x_banner_banner.py b/indoteknik_custom/models/solr/x_banner_banner.py
new file mode 100644
index 00000000..5608a3d7
--- /dev/null
+++ b/indoteknik_custom/models/solr/x_banner_banner.py
@@ -0,0 +1,64 @@
+from odoo import models, fields, api
+import logging
+from datetime import datetime
+
+_logger = logging.getLogger(__name__)
+
+class XBannerBanner(models.Model):
+ _inherit = "x_banner.banner"
+
+ 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('banners')
+
+ 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_url_banner', 'background_color', 'x_banner_image', 'x_banner_category', 'x_relasi_manufacture', 'x_sequence_banner', 'x_status_banner', 'sequence', 'group_by_week')
+ def _create_solr_queue_sync_brands(self):
+ self._create_solr_queue('_sync_banners_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_banners_to_solr')
+
+ def _sync_banners_to_solr(self):
+ solr_model = self.env['apache.solr']
+
+ for banners in self:
+ document = {}
+ document.update({
+ 'id': banners.id,
+ 'display_name_s': banners.display_name,
+ 'name_s': banners.x_name,
+ 'sequence_i': banners.sequence or '',
+ 'url_s': banners.x_url_banner or '',
+ '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 '',
+ 'group_by_week': banners.group_by_week or '',
+ })
+ self.solr().add([document])
+ banners.update_last_update_solr()
+
+ self.solr().commit()
+
+ def unlink(self):
+ res = super(XBannerBanner, 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 b2f0cde0..c0c321e4 100644
--- a/indoteknik_custom/models/solr/x_manufactures.py
+++ b/indoteknik_custom/models/solr/x_manufactures.py
@@ -28,9 +28,9 @@ class XManufactures(models.Model):
self._create_solr_queue('_sync_brands_to_solr')
def action_sync_to_solr(self):
- template_ids = self.env.context.get('active_ids', [])
- templates = self.search([('id', 'in', template_ids)])
- templates._create_solr_queue('_sync_brands_to_solr')
+ manufacture_ids = self.env.context.get('active_ids', [])
+ manufactures = self.search([('id', 'in', manufacture_ids)])
+ manufactures._create_solr_queue('_sync_brands_to_solr')
def _sync_brands_to_solr(self):
solr_model = self.env['apache.solr']