kategory: sortierung begnnen
This commit is contained in:
parent
937124bcaf
commit
7fd42c0b42
2 changed files with 73 additions and 0 deletions
27
category.py
27
category.py
|
@ -10,6 +10,7 @@ from trytond.pyson import Eval, If, Bool
|
||||||
from trytond.exceptions import UserError
|
from trytond.exceptions import UserError
|
||||||
from trytond.i18n import gettext
|
from trytond.i18n import gettext
|
||||||
from sql.operators import Equal
|
from sql.operators import Equal
|
||||||
|
from sql import With
|
||||||
|
|
||||||
|
|
||||||
sel_categorytype = [
|
sel_categorytype = [
|
||||||
|
@ -79,6 +80,32 @@ class Category(tree(separator='/'), sequence_ordered(), ModelSQL, ModelView):
|
||||||
def default_right():
|
def default_right():
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def order_rec_name(tables):
|
||||||
|
""" order by pos
|
||||||
|
"""
|
||||||
|
Category2 = Pool().get('cashbook.category')
|
||||||
|
tab_cat = Category2.__table__()
|
||||||
|
table, _ = tables[None]
|
||||||
|
|
||||||
|
categories = With('id', 'name', 'name_path', recursive=True)
|
||||||
|
categories.query = select(tab_cat.id, tab_cat.name, array[])
|
||||||
|
|
||||||
|
# ~ with recursive categories (id, level, name, name_path) as (
|
||||||
|
# ~ select "a"."id", 0, "a"."name", array["a"."name"]
|
||||||
|
# ~ from cashbook_category as "a"
|
||||||
|
# ~ where "a"."parent" is null
|
||||||
|
|
||||||
|
# ~ union all
|
||||||
|
|
||||||
|
# ~ select "b"."id", "c"."level" + 1, "b"."name", array_append("c"."name_path", "b"."name")
|
||||||
|
# ~ from cashbook_category as "b"
|
||||||
|
# ~ inner join categories as "c" on "c"."id" = "b"."parent"
|
||||||
|
# ~ )
|
||||||
|
# ~ select "d"."id", array_to_string("d"."name_path", '/') as "rec_name"
|
||||||
|
# ~ from categories as "d"
|
||||||
|
# ~ order by "rec_name"
|
||||||
|
|
||||||
@fields.depends('parent', '_parent_parent.cattype')
|
@fields.depends('parent', '_parent_parent.cattype')
|
||||||
def on_change_with_parent_cattype(self, name=None):
|
def on_change_with_parent_cattype(self, name=None):
|
||||||
""" get type of parent category or None
|
""" get type of parent category or None
|
||||||
|
|
|
@ -28,6 +28,52 @@ class CategoryTestCase(ModuleTestCase):
|
||||||
}])
|
}])
|
||||||
return category
|
return category
|
||||||
|
|
||||||
|
@with_transaction()
|
||||||
|
def test_category_check_rec_name(self):
|
||||||
|
""" create category, test rec_name, search, order
|
||||||
|
"""
|
||||||
|
pool = Pool()
|
||||||
|
Category = pool.get('cashbook.category')
|
||||||
|
company = self.prep_company()
|
||||||
|
|
||||||
|
Category.create([{
|
||||||
|
'company': company.id,
|
||||||
|
'name': 'Level 1',
|
||||||
|
'cattype': 'in',
|
||||||
|
'childs': [('create', [{
|
||||||
|
'company': company.id,
|
||||||
|
'name': 'Level 2a',
|
||||||
|
'cattype': 'in',
|
||||||
|
}, {
|
||||||
|
'company': company.id,
|
||||||
|
'name': 'Level 2b',
|
||||||
|
'cattype': 'in',
|
||||||
|
}])],
|
||||||
|
}, {
|
||||||
|
'company': company.id,
|
||||||
|
'name': 'Level 1b',
|
||||||
|
'cattype': 'in',
|
||||||
|
'childs': [('create', [{
|
||||||
|
'company': company.id,
|
||||||
|
'name': 'Level 1b.2a',
|
||||||
|
'cattype': 'in',
|
||||||
|
}, {
|
||||||
|
'company': company.id,
|
||||||
|
'name': 'Level 1b.2b',
|
||||||
|
'cattype': 'in',
|
||||||
|
}])],
|
||||||
|
}])
|
||||||
|
|
||||||
|
self.assertEqual(Category.search_count([
|
||||||
|
('rec_name', 'ilike', '%1b.2b%'),
|
||||||
|
]), 1)
|
||||||
|
self.assertEqual(Category.search_count([
|
||||||
|
('rec_name', 'ilike', '%1b.2%'),
|
||||||
|
]), 2)
|
||||||
|
self.assertEqual(Category.search_count([
|
||||||
|
('rec_name', '=', 'Level 1b/Level 1b.2b'),
|
||||||
|
]), 1)
|
||||||
|
|
||||||
@with_transaction()
|
@with_transaction()
|
||||||
def test_category_create_check_category_type(self):
|
def test_category_create_check_category_type(self):
|
||||||
""" create category, update type of category
|
""" create category, update type of category
|
||||||
|
|
Loading…
Reference in a new issue