summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2023-09-21 09:28:08 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2023-09-21 09:28:08 +0700
commitc357d6bd7586b0331b27dbe864179b1fad63bf2e (patch)
tree7e1108529023463bdfce9d2c10865346e20926f1 /indoteknik_custom/models
parent33166b60a9e0e6b236f39b26e53d925d2790e9db (diff)
Add banner category to solr, auto sync solr banner category, fix button uang muka
Diffstat (limited to 'indoteknik_custom/models')
-rw-r--r--indoteknik_custom/models/solr/__init__.py3
-rw-r--r--indoteknik_custom/models/solr/x_banner_banner.py4
-rw-r--r--indoteknik_custom/models/solr/x_banner_category.py54
3 files changed, 58 insertions, 3 deletions
diff --git a/indoteknik_custom/models/solr/__init__.py b/indoteknik_custom/models/solr/__init__.py
index 16da73af..f2d13116 100644
--- a/indoteknik_custom/models/solr/__init__.py
+++ b/indoteknik_custom/models/solr/__init__.py
@@ -7,4 +7,5 @@ from . import product_template
from . import website_categories_homepage
from . import x_manufactures
from . import x_banner_banner
-from . import product_public_category \ No newline at end of file
+from . import product_public_category
+from . import x_banner_category \ No newline at end of file
diff --git a/indoteknik_custom/models/solr/x_banner_banner.py b/indoteknik_custom/models/solr/x_banner_banner.py
index 5608a3d7..67739d47 100644
--- a/indoteknik_custom/models/solr/x_banner_banner.py
+++ b/indoteknik_custom/models/solr/x_banner_banner.py
@@ -46,8 +46,8 @@ class XBannerBanner(models.Model):
'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 '',
+ 'category_id_i': banners.x_banner_category.id or '',
+ 'manufacture_id_i': banners.x_relasi_manufacture.id or '',
'group_by_week': banners.group_by_week or '',
})
self.solr().add([document])
diff --git a/indoteknik_custom/models/solr/x_banner_category.py b/indoteknik_custom/models/solr/x_banner_category.py
new file mode 100644
index 00000000..c73f6722
--- /dev/null
+++ b/indoteknik_custom/models/solr/x_banner_category.py
@@ -0,0 +1,54 @@
+from odoo import fields, models, api
+from datetime import datetime
+
+class XBannerCategory(models.Model):
+ _inherit = "x_banner.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('banner_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_banner_subtitle', 'x_studio_field_KKVl4', 'banner_ids')
+ def _create_solr_queue_sync_banner_categories(self):
+ self._create_solr_queue('_sync_banner_categories_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_banner_categories_to_solr')
+
+ def _sync_banner_categories_to_solr(self):
+ for banners in self:
+ document = {}
+ document.update({
+ 'id': banners.id,
+ 'display_name_s': banners.display_name,
+ 'name_s': banners.x_name,
+ 'banner_subtitle_s': banners.x_banner_subtitle or '',
+ 'x_studio_field_KKVl4_s': banners.x_studio_field_KKVl4 or '',
+ 'banners': [x.id for x in banners.banner_ids],
+ })
+ self.solr().add([document])
+ banners.update_last_update_solr()
+
+ self.solr().commit()
+
+ def unlink(self):
+ res = super(XBannerCategory, 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