formatting, indexes optimized
This commit is contained in:
parent
510357a13c
commit
9ee924f0d8
11 changed files with 90 additions and 94 deletions
51
line.py
51
line.py
|
@ -16,6 +16,7 @@ from sql.functions import DatePart
|
|||
from sql.conditionals import Case
|
||||
from .book import sel_state_book
|
||||
from .mixin import SecondCurrencyMixin, MemCacheIndexMx
|
||||
from .const import DEF_NONE
|
||||
|
||||
|
||||
sel_payee = [
|
||||
|
@ -48,7 +49,9 @@ STATES = {
|
|||
DEPENDS = ['state', 'state_cashbook']
|
||||
|
||||
|
||||
class Line(SecondCurrencyMixin, MemCacheIndexMx, Workflow, ModelSQL, ModelView):
|
||||
class Line(
|
||||
SecondCurrencyMixin, MemCacheIndexMx, Workflow, ModelSQL,
|
||||
ModelView):
|
||||
'Cashbook Line'
|
||||
__name__ = 'cashbook.line'
|
||||
|
||||
|
@ -75,8 +78,7 @@ class Line(SecondCurrencyMixin, MemCacheIndexMx, Workflow, ModelSQL, ModelView):
|
|||
states={
|
||||
'readonly': Or(
|
||||
STATES['readonly'],
|
||||
Bool(Eval('bookingtype')) == False,
|
||||
),
|
||||
~Bool(Eval('bookingtype'))),
|
||||
'required': Eval('bookingtype', '').in_(['in', 'out']),
|
||||
'invisible': ~Eval('bookingtype', '').in_(['in', 'out']),
|
||||
}, depends=DEPENDS+['bookingtype'],
|
||||
|
@ -161,7 +163,8 @@ class Line(SecondCurrencyMixin, MemCacheIndexMx, Workflow, ModelSQL, ModelView):
|
|||
splitlines = fields.One2Many(
|
||||
string='Split booking lines',
|
||||
model_name='cashbook.split',
|
||||
help='Rows with different categories form the total sum of the booking',
|
||||
help='Rows with different categories form the total ' +
|
||||
'sum of the booking',
|
||||
states={
|
||||
'invisible': ~Eval('bookingtype' '').in_(['spin', 'spout']),
|
||||
'readonly': Or(
|
||||
|
@ -225,9 +228,6 @@ class Line(SecondCurrencyMixin, MemCacheIndexMx, Workflow, ModelSQL, ModelView):
|
|||
t = cls.__table__()
|
||||
|
||||
cls._sql_indexes.update({
|
||||
Index(
|
||||
t,
|
||||
(t.cashbook, Index.Equality())),
|
||||
Index(
|
||||
t,
|
||||
(t.date, Index.Range(order='ASC'))),
|
||||
|
@ -308,7 +308,7 @@ class Line(SecondCurrencyMixin, MemCacheIndexMx, Workflow, ModelSQL, ModelView):
|
|||
).select(
|
||||
tab_line.id,
|
||||
where=tab_line.bookingtype.in_(['mvin', 'mvout']) &
|
||||
(tab_line.amount_2nd_currency == None) &
|
||||
(tab_line.amount_2nd_currency == DEF_NONE) &
|
||||
(tab_book.currency != tab_book2.currency)
|
||||
)
|
||||
lines = Line2.search([('id', 'in', query)])
|
||||
|
@ -344,7 +344,7 @@ class Line(SecondCurrencyMixin, MemCacheIndexMx, Workflow, ModelSQL, ModelView):
|
|||
for line in lines:
|
||||
if line.reference:
|
||||
if Transaction().context.get(
|
||||
'line.allow.wfedit', False) == False:
|
||||
'line.allow.wfedit', False) is False:
|
||||
raise UserError(gettext(
|
||||
'cashbook.msg_line_denywf_by_reference',
|
||||
recname=line.reference.rec_name,
|
||||
|
@ -508,19 +508,20 @@ class Line(SecondCurrencyMixin, MemCacheIndexMx, Workflow, ModelSQL, ModelView):
|
|||
"""
|
||||
credit = self.credit if self.credit is not None else Decimal('0.0')
|
||||
debit = self.debit if self.debit is not None else Decimal('0.0')
|
||||
return '%(date)s|%(type)s|%(amount)s %(symbol)s|%(desc)s [%(category)s]' % {
|
||||
'date': Report.format_date(self.date),
|
||||
'desc': (self.description or '-')[:40],
|
||||
'amount': Report.format_number(
|
||||
credit - debit, None,
|
||||
digits=getattr(self.currency, 'digits', 2)),
|
||||
'symbol': getattr(self.currency, 'symbol', '-'),
|
||||
'category': self.category_view
|
||||
if self.bookingtype in ['in', 'out']
|
||||
else getattr(self.booktransf, 'rec_name', '-'),
|
||||
'type': gettext(
|
||||
'cashbook.msg_line_bookingtype_%s' %
|
||||
self.bookingtype)}
|
||||
return '|'.join([
|
||||
Report.format_date(self.date),
|
||||
gettext('cashbook.msg_line_bookingtype_%s' % self.bookingtype),
|
||||
'%(amount)s %(symbol)s' % {
|
||||
'amount': Report.format_number(
|
||||
credit - debit, None,
|
||||
digits=getattr(self.currency, 'digits', 2)),
|
||||
'symbol': getattr(self.currency, 'symbol', '-')},
|
||||
'%(desc)s [%(category)s]' % {
|
||||
'desc': (self.description or '-')[:40],
|
||||
'category': self.category_view
|
||||
if self.bookingtype in ['in', 'out']
|
||||
else getattr(self.booktransf, 'rec_name', '-')},
|
||||
])
|
||||
|
||||
@staticmethod
|
||||
def order_state(tables):
|
||||
|
@ -535,8 +536,7 @@ class Line(SecondCurrencyMixin, MemCacheIndexMx, Workflow, ModelSQL, ModelView):
|
|||
(tab_line.state == 'edit', 1),
|
||||
(tab_line.state.in_(['check', 'recon', 'done']), 0),
|
||||
else_=2),
|
||||
where=tab_line.id == table.id
|
||||
)
|
||||
where=tab_line.id == table.id)
|
||||
return [query]
|
||||
|
||||
@staticmethod
|
||||
|
@ -626,7 +626,8 @@ class Line(SecondCurrencyMixin, MemCacheIndexMx, Workflow, ModelSQL, ModelView):
|
|||
|
||||
if self.bookingtype:
|
||||
if self.category:
|
||||
if self.bookingtype not in types.get(self.category.cattype, ''):
|
||||
if self.bookingtype not in types.get(
|
||||
self.category.cattype, ''):
|
||||
self.category = None
|
||||
|
||||
if self.bookingtype.startswith('sp'): # split booking
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue