diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-10-23 15:26:52 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-10-23 15:26:52 +0700 |
| commit | e7742e5404e6016382ff22903a24ce18abe07ae1 (patch) | |
| tree | da3c7fd3c6e3eadd4c151a2001a3e8f57079c14d | |
| parent | 3fa5e5bfe91969b4ab74a43a63ab673a76aff9da (diff) | |
| parent | 3852cfd075fb3bebf189234db6fd9c52acf6d667 (diff) | |
Merge branch 'production' of bitbucket.org:altafixco/indoteknik-addons into production
| -rwxr-xr-x | indoteknik_custom/__manifest__.py | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/find_page.py | 121 | ||||
| -rwxr-xr-x | indoteknik_custom/security/ir.model.access.csv | 2 | ||||
| -rw-r--r-- | indoteknik_custom/views/find_page.xml | 70 |
5 files changed, 195 insertions, 0 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 116c64ec..c8a658b5 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -144,6 +144,7 @@ 'views/vendor_payment_term.xml', 'views/approval_unreserve.xml', 'views/vendor_approval.xml', + 'views/find_page.xml', 'report/report.xml', 'report/report_banner_banner.xml', 'report/report_banner_banner2.xml', diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 7b41a5fe..e62fbb4a 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -130,3 +130,4 @@ from . import account_tax from . import approval_unreserve from . import vendor_approval from . import partner +from . import find_page diff --git a/indoteknik_custom/models/find_page.py b/indoteknik_custom/models/find_page.py new file mode 100644 index 00000000..467e30d1 --- /dev/null +++ b/indoteknik_custom/models/find_page.py @@ -0,0 +1,121 @@ +from odoo import fields, models, api, tools, _ +import logging +import re +import pysolr + +_logger = logging.getLogger(__name__) +_cat_brand_solr = pysolr.Solr('http://10.148.0.5:8983/solr/url_category_brand/', always_commit=True, timeout=30) +# _cat_brand_solr_dev = pysolr.Solr('http://127.0.0.1:8983/solr/url_category_brand/', always_commit=True, timeout=30) + + +class BrandProductCategory(models.Model): + _name = 'v.brand.product.category' + _auto = False + _rec_name = 'brand_id' + brand_id = fields.Many2one('x_manufactures', string='Brand') + category_id = fields.Many2one('product.public.category', string='Category') + + def init(self): + tools.drop_view_if_exists(self.env.cr, self._table) + self.env.cr.execute(""" + CREATE OR REPLACE VIEW %s + AS select row_number() over(order by pt.x_manufacture) as id, + pt.x_manufacture as brand_id, + ppcptr.product_public_category_id as category_id + from product_template pt + join product_public_category_product_template_rel ppcptr on ppcptr.product_template_id = pt.id + join x_manufactures xm on xm.id = pt.x_manufacture + group by x_manufacture, ppcptr.product_public_category_id + """ % self._table) + + +class FindPage(models.Model): + _name = 'web.find.page' + _inherit = ['mail.thread'] + _rec_name = 'url' + + brand_id = fields.Many2one('x_manufactures', string='Brand') + category_id = fields.Many2one('product.public.category', string='Category', help='Bisa semua level Category') + url = fields.Char(string='Url') + + def _sync_to_solr(self, limit=10000): + urls = self.env['web.find.page'].search([]) + documents = [] + catch = {} + for url in urls: + try: + document = { + 'id': url.id, + 'category_id_i': url.category_id.id, + 'brand_id_i': url.brand_id.id, + 'url_s': url.url + } + documents.append(document) + catch = document + except Exception as e: + _logger.error('Failed to add document to Solr URL Category Brand: %s', e) + _logger.error('Document Data: %s', catch) + _cat_brand_solr.add(documents) + return True + + def _get_category_hierarchy(self, category): + categories = [] + current_category = category + while current_category: + categories.insert(0, current_category) + current_category = current_category.parent_id + return categories + + def _generate_url(self): + categories = self.env['v.brand.product.category'].search([]) + + list_url = [] + for category in categories: + category_hierarchy = self._get_category_hierarchy(category.category_id) + + for level, cat in enumerate(reversed(category_hierarchy), start=1): + list_url.append(self._generate_mod_url(cat, category.brand_id)) + # print(f"Level {level}: {cat.name} {category.brand_id.x_name}") + + unique_list = [] + for item in list_url: + if item not in unique_list: + unique_list.append(item) + count = 0 + for item in unique_list: + self._create_find_page(item['url'], item['category_id'], item['brand_id']) + count += 1 + print(f"Total categories processed: {count}") + + def _create_find_page(self, url, category_id, brand_id): + param = { + 'url': url, + 'category_id': category_id, + 'brand_id': brand_id, + } + find_page = self.env['web.find.page'].create(param) + _logger.info('Created Web Find Page %s' % find_page.id) + + def _generate_mod_url(self, category, brand): + # generate_url = 'https://indoteknik.com/shop/find/category-brand' example + cleaned_category = re.sub(r'[^\w\s]', '', category.name) + cleaned_brand = re.sub(r'[^\w\s]', '', brand.x_name) + cleaned_combined = cleaned_category+' '+cleaned_brand + cleaned_combined = cleaned_combined.replace(' ', '-') + cleaned_combined = cleaned_combined.replace('--', '-') + url = 'https://indoteknik.com/shop/find/'+cleaned_combined + url = url.lower() + result = { + 'url': url, + 'category_id': category.id, + 'brand_id': brand.id + } + # print(url) + # param = { + # 'brand_id': brand.id, + # 'category_id': category.id, + # 'url':'' + # } + # self.env['web.find.page'].create() + # print(1) + return result diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 408aae55..553047e6 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -141,3 +141,5 @@ access_approval_unreserve_line,access.approval.unreserve.line,model_approval_unr access_vendor_approval,access.vendor.approval,model_vendor_approval,,1,1,1,1 access_vendor_approval_line,access.vendor.approval.line,model_vendor_approval_line,,1,1,1,1 access_vit_kota,access.vit.kota,model_vit_kota,,1,1,1,1 +access_v_brand_product_category,access.v.brand.product.category,model_v_brand_product_category,,1,1,1,1 +access_web_find_page,access.web.find.page,model_web_find_page,,1,1,1,1 diff --git a/indoteknik_custom/views/find_page.xml b/indoteknik_custom/views/find_page.xml new file mode 100644 index 00000000..c752aa98 --- /dev/null +++ b/indoteknik_custom/views/find_page.xml @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<odoo> + <record id="web_find_page_tree" model="ir.ui.view"> + <field name="name">web.find.page.tree</field> + <field name="model">web.find.page</field> + <field name="arch" type="xml"> + <tree> + <field name="category_id"/> + <field name="brand_id"/> + <field name="url"/> + <field name="create_uid"/> + <field name="write_uid"/> + </tree> + </field> + </record> + + <record id="web_find_page_form" model="ir.ui.view"> + <field name="name">web.find.page.form</field> + <field name="model">web.find.page</field> + <field name="arch" type="xml"> + <form> + <sheet string="Web Find Page"> + <div class="oe_button_box" name="button_box"/> + <group> + <group> + <field name="category_id"/> + <field name="brand_id"/> + <field name="url"/> + </group> + <group> + <field name="create_uid"/> + <field name="write_uid"/> + </group> + </group> + </sheet> + <div class="oe_chatter"> + <field name="message_follower_ids" widget="mail_followers"/> + <field name="message_ids" widget="mail_thread"/> + </div> + </form> + </field> + </record> + + <record id="view_web_find_page_filter" model="ir.ui.view"> + <field name="name">web.find.page.list.select</field> + <field name="model">web.find.page</field> + <field name="priority" eval="15"/> + <field name="arch" type="xml"> + <search string="Search Web Find Page"> + <field name="category_id"/> + <field name="brand_id"/> + <field name="url"/> + </search> + </field> + </record> + + <record id="web_find_page_action" model="ir.actions.act_window"> + <field name="name">Web Find Page</field> + <field name="type">ir.actions.act_window</field> + <field name="res_model">web.find.page</field> + <field name="search_view_id" ref="view_web_find_page_filter"/> + <field name="view_mode">tree,form</field> + </record> + + <menuitem id="menu_web_find_page" + name="Web Find Page" + action="web_find_page_action" + parent="website_sale.menu_orders" + sequence="8"/> +</odoo>
\ No newline at end of file |
