diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2023-09-11 11:55:47 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2023-09-11 11:55:47 +0700 |
| commit | 02c2304b242245250177fec6ab3c911d9acba781 (patch) | |
| tree | c6e905a5d99e9f50c3cfeb30a43f530533a5706c | |
| parent | 439f7252866ae30b548326ad25f241e513f0fe85 (diff) | |
auto sync banner to solr, auto sync ecommerce categories to solr, add field carrier to stock_picking
| -rw-r--r-- | indoteknik_custom/models/solr/__init__.py | 4 | ||||
| -rw-r--r-- | indoteknik_custom/models/solr/product_public_category.py | 72 | ||||
| -rw-r--r-- | indoteknik_custom/models/solr/website_categories_homepage.py | 2 | ||||
| -rw-r--r-- | indoteknik_custom/models/solr/x_banner_banner.py | 64 | ||||
| -rw-r--r-- | indoteknik_custom/models/solr/x_manufactures.py | 6 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 2 | ||||
| -rwxr-xr-x | indoteknik_custom/views/product_public_category.xml | 9 | ||||
| -rw-r--r-- | indoteknik_custom/views/stock_picking.xml | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/views/x_banner_banner.xml | 9 |
9 files changed, 164 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'] diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 90963e1c..0e6137eb 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -73,6 +73,8 @@ class StockPicking(models.Model): waybill_id = fields.One2many(comodel_name='airway.bill', inverse_name='do_id', string='Airway Bill') purchase_representative_id = fields.Many2one('res.users', related='move_lines.purchase_line_id.order_id.user_id', string="Purchase Representative", readonly=True) + + carrier_id = fields.Many2one('delivery.carrier', string='Shipping Method') def action_create_invoice_from_mr(self): """Create the invoice associated to the PO. diff --git a/indoteknik_custom/views/product_public_category.xml b/indoteknik_custom/views/product_public_category.xml index 3a9eb2df..e0161acf 100755 --- a/indoteknik_custom/views/product_public_category.xml +++ b/indoteknik_custom/views/product_public_category.xml @@ -34,4 +34,13 @@ </xpath> </field> </record> + + <record id="ir_actions_server_product_public_category_sync_to_solr" model="ir.actions.server"> + <field name="name">Sync to solr</field> + <field name="model_id" ref="indoteknik_custom.model_product_public_category"/> + <field name="binding_model_id" ref="indoteknik_custom.model_product_public_category"/> + <field name="state">code</field> + <field name="code">model.action_sync_to_solr()</field> + </record> + </odoo>
\ No newline at end of file diff --git a/indoteknik_custom/views/stock_picking.xml b/indoteknik_custom/views/stock_picking.xml index b099b32c..ebc978aa 100644 --- a/indoteknik_custom/views/stock_picking.xml +++ b/indoteknik_custom/views/stock_picking.xml @@ -102,6 +102,7 @@ <field name="driver_arrival_date"/> <field name="delivery_tracking_no"/> <field name="driver_id"/> + <field name="carrier_id"/> <field name="picking_code" attrs="{'invisible': [['picking_code', '=', False]]}"/> <field name="picking_code" string="Picking code (akan digenerate ketika sudah di-validate)" attrs="{'invisible': [['picking_code', '!=', False]]}"/> </group> diff --git a/indoteknik_custom/views/x_banner_banner.xml b/indoteknik_custom/views/x_banner_banner.xml index 5e6526e0..be9ae951 100755 --- a/indoteknik_custom/views/x_banner_banner.xml +++ b/indoteknik_custom/views/x_banner_banner.xml @@ -31,6 +31,7 @@ <field name="x_status_banner" /> <field name="sequence" /> <field name="group_by_week" /> + <field name="last_update_solr" /> </group> <group> <field name="background_color" /> @@ -54,6 +55,14 @@ </field> </record> + <record id="ir_actions_server_x_banner_banner_sync_to_solr" model="ir.actions.server"> + <field name="name">Sync to solr</field> + <field name="model_id" ref="indoteknik_custom.model_x_banner_banner"/> + <field name="binding_model_id" ref="indoteknik_custom.model_x_banner_banner"/> + <field name="state">code</field> + <field name="code">model.action_sync_to_solr()</field> + </record> + <menuitem id="menu_x_banner_banner" name="Banner" |
