summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_custom/models')
-rw-r--r--indoteknik_custom/models/find_page.py56
1 files changed, 45 insertions, 11 deletions
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