1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
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 _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:
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}")
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 _generate_url_parent(self):
print(1)
|