book/category: hierarchische sortierung, form optimiert
This commit is contained in:
parent
1c22aac197
commit
7999440de7
5 changed files with 76 additions and 62 deletions
10
book.py
10
book.py
|
@ -13,6 +13,7 @@ from trytond.report import Report
|
|||
from decimal import Decimal
|
||||
from sql.aggregate import Sum
|
||||
from sql.conditionals import Case
|
||||
from .model import order_name_hierarchical
|
||||
|
||||
|
||||
STATES = {
|
||||
|
@ -136,7 +137,7 @@ class Book(tree(separator='/'), Workflow, ModelSQL, ModelView):
|
|||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Book, cls).__setup__()
|
||||
cls._order.insert(0, ('name', 'ASC'))
|
||||
cls._order.insert(0, ('rec_name', 'ASC'))
|
||||
cls._order.insert(0, ('state', 'ASC'))
|
||||
t = cls.__table__()
|
||||
cls._sql_constraints.extend([
|
||||
|
@ -225,6 +226,13 @@ class Book(tree(separator='/'), Workflow, ModelSQL, ModelView):
|
|||
)
|
||||
return [query]
|
||||
|
||||
@staticmethod
|
||||
def order_rec_name(tables):
|
||||
""" order by pos
|
||||
a recursive sorting
|
||||
"""
|
||||
return order_name_hierarchical('cashbook.book', tables)
|
||||
|
||||
def get_rec_name(self, name):
|
||||
""" name, balance, state
|
||||
"""
|
||||
|
|
57
category.py
57
category.py
|
@ -10,39 +10,7 @@ from trytond.pyson import Eval, If, Bool
|
|||
from trytond.exceptions import UserError
|
||||
from trytond.i18n import gettext
|
||||
from sql.operators import Equal
|
||||
from sql.functions import Function
|
||||
from sql import With, Literal
|
||||
|
||||
|
||||
class ArrayApppend(Function):
|
||||
""" sql: array_append
|
||||
"""
|
||||
__slots__ = ()
|
||||
_function = 'ARRAY_APPEND'
|
||||
|
||||
# end ArrayApppend
|
||||
|
||||
|
||||
class ArrayToString(Function):
|
||||
""" sql: array_to_string
|
||||
"""
|
||||
__slots__ = ()
|
||||
_function = 'ARRAY_TO_STRING'
|
||||
|
||||
# end ArrayToString
|
||||
|
||||
|
||||
class Array(Function):
|
||||
""" sql: array-type
|
||||
"""
|
||||
__slots__ = ()
|
||||
_function = 'ARRAY'
|
||||
|
||||
def __str__(self):
|
||||
return self._function + '[' + ', '.join(
|
||||
map(self._format, self.args)) + ']'
|
||||
|
||||
# end Array
|
||||
from .model import order_name_hierarchical
|
||||
|
||||
|
||||
sel_categorytype = [
|
||||
|
@ -128,28 +96,7 @@ class Category(tree(separator='/'), ModelSQL, ModelView):
|
|||
""" order by pos
|
||||
a recursive sorting
|
||||
"""
|
||||
Category2 = Pool().get('cashbook.category')
|
||||
tab_cat = Category2.__table__()
|
||||
tab_cat2 = Category2.__table__()
|
||||
table, _ = tables[None]
|
||||
|
||||
categories = With('id', 'name', 'name_path', recursive=True)
|
||||
categories.query = tab_cat.select(
|
||||
tab_cat.id, tab_cat.name, Array(tab_cat.name),
|
||||
where = tab_cat.parent==None,
|
||||
)
|
||||
categories.query |= tab_cat2.join(categories,
|
||||
condition=categories.id==tab_cat2.parent,
|
||||
).select(
|
||||
tab_cat2.id, tab_cat2.name, ArrayApppend(categories.name_path, tab_cat2.name),
|
||||
)
|
||||
categories.query.all_ = True
|
||||
|
||||
query = categories.select(
|
||||
ArrayToString(categories.name_path, '/').as_('rec_name'),
|
||||
where = table.id==categories.id,
|
||||
with_ = [categories])
|
||||
return [query]
|
||||
return order_name_hierarchical('cashbook.category', tables)
|
||||
|
||||
@fields.depends('parent', '_parent_parent.cattype')
|
||||
def on_change_with_parent_cattype(self, name=None):
|
||||
|
|
62
model.py
62
model.py
|
@ -5,6 +5,68 @@
|
|||
|
||||
from trytond.model import MultiValueMixin, ValueMixin, fields, Unique
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pool import Pool
|
||||
from sql import With, Literal
|
||||
from sql.functions import Function
|
||||
|
||||
|
||||
class ArrayApppend(Function):
|
||||
""" sql: array_append
|
||||
"""
|
||||
__slots__ = ()
|
||||
_function = 'ARRAY_APPEND'
|
||||
|
||||
# end ArrayApppend
|
||||
|
||||
|
||||
class ArrayToString(Function):
|
||||
""" sql: array_to_string
|
||||
"""
|
||||
__slots__ = ()
|
||||
_function = 'ARRAY_TO_STRING'
|
||||
|
||||
# end ArrayToString
|
||||
|
||||
|
||||
class Array(Function):
|
||||
""" sql: array-type
|
||||
"""
|
||||
__slots__ = ()
|
||||
_function = 'ARRAY'
|
||||
|
||||
def __str__(self):
|
||||
return self._function + '[' + ', '.join(
|
||||
map(self._format, self.args)) + ']'
|
||||
|
||||
# end Array
|
||||
|
||||
|
||||
def order_name_hierarchical(model_name, tables):
|
||||
""" order by pos
|
||||
a recursive sorting
|
||||
"""
|
||||
Model2 = Pool().get(model_name)
|
||||
tab_mod = Model2.__table__()
|
||||
tab_mod2 = Model2.__table__()
|
||||
table, _ = tables[None]
|
||||
|
||||
lines = With('id', 'name', 'name_path', recursive=True)
|
||||
lines.query = tab_mod.select(
|
||||
tab_mod.id, tab_mod.name, Array(tab_mod.name),
|
||||
where = tab_mod.parent==None,
|
||||
)
|
||||
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),
|
||||
)
|
||||
lines.query.all_ = True
|
||||
|
||||
query = lines.select(
|
||||
ArrayToString(lines.name_path, '/').as_('rec_name'),
|
||||
where = table.id==lines.id,
|
||||
with_ = [lines])
|
||||
return [query]
|
||||
|
||||
|
||||
class UserValueMixin(ValueMixin):
|
||||
|
|
|
@ -44,8 +44,6 @@ full copyright notices and license terms. -->
|
|||
<field name="start_date"/>
|
||||
<label name="currency"/>
|
||||
<field name="currency"/>
|
||||
|
||||
<label id="phaccount" colspan="2" string=" "/>
|
||||
</page>
|
||||
<page id="pgperm" string="Owner and Authorizeds" col="4">
|
||||
<label name="owner"/>
|
||||
|
|
|
@ -2,17 +2,16 @@
|
|||
<!-- This file is part of the cashbook-module from m-ds for Tryton.
|
||||
The COPYRIGHT file at the top level of this repository contains the
|
||||
full copyright notices and license terms. -->
|
||||
<form col="6">
|
||||
<form col="4">
|
||||
<label name="name"/>
|
||||
<field name="name"/>
|
||||
<label name="cattype"/>
|
||||
<field name="cattype"/>
|
||||
<label id="phaccount" colspan="2" string=" "/>
|
||||
|
||||
<label name="description"/>
|
||||
<field name="description" colspan="5"/>
|
||||
<field name="description" colspan="3"/>
|
||||
|
||||
<notebook colspan="6">
|
||||
<notebook colspan="4">
|
||||
<page string="General Information" id="general" col="4">
|
||||
<label name="company"/>
|
||||
<field name="company"/>
|
||||
|
|
Loading…
Reference in a new issue