From d7f4569c5d2dcda1316ca4ef37fed53f467df9df Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 15 Oct 2024 09:10:06 +0700 Subject: initial commit generate url --- indoteknik_custom/models/find_page.py | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 indoteknik_custom/models/find_page.py (limited to 'indoteknik_custom/models/find_page.py') diff --git a/indoteknik_custom/models/find_page.py b/indoteknik_custom/models/find_page.py new file mode 100644 index 00000000..b81b3845 --- /dev/null +++ b/indoteknik_custom/models/find_page.py @@ -0,0 +1,44 @@ +from odoo import fields, models, api, tools, _ +import logging + +_logger = logging.getLogger(__name__) + + +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' + + 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 _generate_url(self): + categories = self.env['v.brand.product.category'].search([]) + count = 0 + for category in categories: + print(category.brand_id.x_name+' '+category.category_id.name) + count += 1 + print(count) + + def _generate_url_parent(self): + print(1) -- cgit v1.2.3 From 245f5c63c40527b94cf45e20e4c8dd15f5b51e98 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 17 Oct 2024 17:08:06 +0700 Subject: update menampilkan category dan brand, sebelum ditampilkan cek dulu apakah brand termasuk kedalam category --- indoteknik_custom/models/find_page.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models/find_page.py') diff --git a/indoteknik_custom/models/find_page.py b/indoteknik_custom/models/find_page.py index b81b3845..463092ce 100644 --- a/indoteknik_custom/models/find_page.py +++ b/indoteknik_custom/models/find_page.py @@ -32,13 +32,41 @@ class FindPage(models.Model): category_id = fields.Many2one('product.public.category', string='Category', help='Bisa semua level Category') url = fields.Char(string='Url') + 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([]) count = 0 for category in categories: - print(category.brand_id.x_name+' '+category.category_id.name) + category_hierarchy = self._get_category_hierarchy(category.category_id) + + for level, cat in enumerate(category_hierarchy, start=1): + products = self.env['product.product'].search([ + ('public_categ_ids', '=', cat.id), + ('x_manufacture', '=', category.brand_id.id) + ]) + + if products: + print(f"Level {level} : {cat.name} {category.brand_id.x_name}") + count += 1 - print(count) + # if count == 5: + # break + print(f"Total categories processed: {count}") + + # def _generate_url(self): + # categories = self.env['v.brand.product.category'].search([]) + # count = 0 + # for category in categories: + # print(category.brand_id.x_name+' '+category.category_id.name) + # count += 1 + # print(count) def _generate_url_parent(self): print(1) -- cgit v1.2.3 From d0af9ab71c65f6e7e1280b2978ebac2d0d514a45 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 18 Oct 2024 09:09:07 +0700 Subject: update generate tanpa chek product --- indoteknik_custom/models/find_page.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'indoteknik_custom/models/find_page.py') diff --git a/indoteknik_custom/models/find_page.py b/indoteknik_custom/models/find_page.py index 463092ce..b7ad7f49 100644 --- a/indoteknik_custom/models/find_page.py +++ b/indoteknik_custom/models/find_page.py @@ -46,18 +46,10 @@ class FindPage(models.Model): for category in categories: category_hierarchy = self._get_category_hierarchy(category.category_id) - for level, cat in enumerate(category_hierarchy, start=1): - products = self.env['product.product'].search([ - ('public_categ_ids', '=', cat.id), - ('x_manufacture', '=', category.brand_id.id) - ]) - - if products: - print(f"Level {level} : {cat.name} {category.brand_id.x_name}") + for level, cat in enumerate(reversed(category_hierarchy), start=1): + print(f"Level {level}: {cat.name} {category.brand_id.x_name}") count += 1 - # if count == 5: - # break print(f"Total categories processed: {count}") # def _generate_url(self): -- cgit v1.2.3 From 943ee3ca2e3b8469d1f3969fa6ea45710e532fc0 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 23 Oct 2024 10:21:27 +0700 Subject: fix web find page --- indoteknik_custom/models/find_page.py | 56 ++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 11 deletions(-) (limited to 'indoteknik_custom/models/find_page.py') diff --git a/indoteknik_custom/models/find_page.py b/indoteknik_custom/models/find_page.py index b7ad7f49..697fd275 100644 --- a/indoteknik_custom/models/find_page.py +++ b/indoteknik_custom/models/find_page.py @@ -1,5 +1,6 @@ from odoo import fields, models, api, tools, _ import logging +import re _logger = logging.getLogger(__name__) @@ -27,6 +28,8 @@ class BrandProductCategory(models.Model): 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') @@ -42,23 +45,54 @@ class FindPage(models.Model): def _generate_url(self): categories = self.env['v.brand.product.category'].search([]) - count = 0 + + 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): - print(f"Level {level}: {cat.name} {category.brand_id.x_name}") + 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 _generate_url(self): - # categories = self.env['v.brand.product.category'].search([]) - # count = 0 - # for category in categories: - # print(category.brand_id.x_name+' '+category.category_id.name) - # count += 1 - # print(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_url_parent(self): - print(1) + 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 -- cgit v1.2.3 From 3852cfd075fb3bebf189234db6fd9c52acf6d667 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 23 Oct 2024 11:35:46 +0700 Subject: sync to solr web find page --- indoteknik_custom/models/find_page.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'indoteknik_custom/models/find_page.py') diff --git a/indoteknik_custom/models/find_page.py b/indoteknik_custom/models/find_page.py index 697fd275..467e30d1 100644 --- a/indoteknik_custom/models/find_page.py +++ b/indoteknik_custom/models/find_page.py @@ -1,8 +1,11 @@ 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): @@ -35,6 +38,26 @@ class FindPage(models.Model): 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 -- cgit v1.2.3