diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2023-09-21 09:28:08 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2023-09-21 09:28:08 +0700 |
| commit | c357d6bd7586b0331b27dbe864179b1fad63bf2e (patch) | |
| tree | 7e1108529023463bdfce9d2c10865346e20926f1 | |
| parent | 33166b60a9e0e6b236f39b26e53d925d2790e9db (diff) | |
Add banner category to solr, auto sync solr banner category, fix button uang muka
| -rw-r--r-- | indoteknik_custom/models/solr/__init__.py | 3 | ||||
| -rw-r--r-- | indoteknik_custom/models/solr/x_banner_banner.py | 4 | ||||
| -rw-r--r-- | indoteknik_custom/models/solr/x_banner_category.py | 54 | ||||
| -rwxr-xr-x | indoteknik_custom/views/x_banner_banner.xml | 2 | ||||
| -rwxr-xr-x | indoteknik_custom/views/x_banner_category.xml | 9 |
5 files changed, 68 insertions, 4 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 diff --git a/indoteknik_custom/views/x_banner_banner.xml b/indoteknik_custom/views/x_banner_banner.xml index be9ae951..c90e718b 100755 --- a/indoteknik_custom/views/x_banner_banner.xml +++ b/indoteknik_custom/views/x_banner_banner.xml @@ -31,7 +31,7 @@ <field name="x_status_banner" /> <field name="sequence" /> <field name="group_by_week" /> - <field name="last_update_solr" /> + <field name="last_update_solr" readonly="1"/> </group> <group> <field name="background_color" /> diff --git a/indoteknik_custom/views/x_banner_category.xml b/indoteknik_custom/views/x_banner_category.xml index 45ad7940..11feb207 100755 --- a/indoteknik_custom/views/x_banner_category.xml +++ b/indoteknik_custom/views/x_banner_category.xml @@ -24,6 +24,7 @@ <field name="x_name"/> <field name="x_banner_subtitle"/> <field name="x_studio_field_KKVl4"/> + <field name="last_update_solr" readonly="1"/> </group> <group></group> </group> @@ -49,6 +50,14 @@ </field> </record> + <record id="ir_actions_server_x_banner_category_sync_to_solr" model="ir.actions.server"> + <field name="name">Sync to solr</field> + <field name="model_id" ref="indoteknik_custom.model_x_banner_category"/> + <field name="binding_model_id" ref="indoteknik_custom.model_x_banner_category"/> + <field name="state">code</field> + <field name="code">model.action_sync_to_solr()</field> + </record> + <menuitem id="menu_banner_category" name="Banner Category" |
