cashbook: abfragen für Felder 'balance*' optimiert + suche + sortierung + test
cashbook-liste: verbergen von Kassenbücher ohne Type
This commit is contained in:
parent
3a0e8f290d
commit
63390df9ca
4 changed files with 233 additions and 101 deletions
37
model.py
37
model.py
|
@ -10,7 +10,15 @@ from sql import With, Literal
|
|||
from sql.functions import Function
|
||||
|
||||
|
||||
class ArrayApppend(Function):
|
||||
class ArrayAgg(Function):
|
||||
"""input values, including nulls, concatenated into an array.
|
||||
"""
|
||||
__slots__ = ()
|
||||
_function = 'ARRAY_AGG'
|
||||
|
||||
# end ArrayAgg
|
||||
|
||||
class ArrayAppend(Function):
|
||||
""" sql: array_append
|
||||
"""
|
||||
__slots__ = ()
|
||||
|
@ -41,6 +49,31 @@ class Array(Function):
|
|||
# end Array
|
||||
|
||||
|
||||
def sub_ids_hierarchical(model_name):
|
||||
""" get table with id and sub-ids
|
||||
"""
|
||||
Model2 = Pool().get(model_name)
|
||||
tab_mod = Model2.__table__()
|
||||
tab_mod2 = Model2.__table__()
|
||||
|
||||
lines = With('parent', 'id', recursive=True)
|
||||
lines.query = tab_mod.select(
|
||||
tab_mod.id, tab_mod.id,
|
||||
) | tab_mod2.join(lines,
|
||||
condition=lines.id==tab_mod2.parent,
|
||||
).select(
|
||||
lines.parent, tab_mod2.id,
|
||||
)
|
||||
lines.query.all_ = True
|
||||
|
||||
query = lines.select(
|
||||
lines.parent,
|
||||
ArrayAgg(lines.id).as_('subids'),
|
||||
group_by=[lines.parent],
|
||||
with_ = [lines])
|
||||
return query
|
||||
|
||||
|
||||
def order_name_hierarchical(model_name, tables):
|
||||
""" order by pos
|
||||
a recursive sorting
|
||||
|
@ -58,7 +91,7 @@ def order_name_hierarchical(model_name, tables):
|
|||
lines.query |= tab_mod2.join(lines,
|
||||
condition=lines.id==tab_mod2.parent,
|
||||
).select(
|
||||
tab_mod2.id, tab_mod2.name, ArrayApppend(lines.name_path, tab_mod2.name),
|
||||
tab_mod2.id, tab_mod2.name, ArrayAppend(lines.name_path, tab_mod2.name),
|
||||
)
|
||||
lines.query.all_ = True
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue