line: reiter für monate, kategorie + test
This commit is contained in:
parent
d6a8b254a3
commit
a23407f515
9 changed files with 333 additions and 3 deletions
53
line.py
53
line.py
|
@ -10,6 +10,8 @@ from trytond.transaction import Transaction
|
|||
from trytond.report import Report
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.i18n import gettext
|
||||
from sql import Cast, Literal
|
||||
from sql.functions import DatePart
|
||||
from .book import sel_state_book
|
||||
|
||||
|
||||
|
@ -121,7 +123,12 @@ class Line(Workflow, ModelSQL, ModelView):
|
|||
model_name='cashbook.book', ondelete='CASCADE', readonly=True)
|
||||
date = fields.Date(string='Date', required=True, select=True,
|
||||
states=STATES, depends=DEPENDS)
|
||||
description = fields.Char(string='Description',
|
||||
month = fields.Function(fields.Integer(string='Month', readonly=True),
|
||||
'on_change_with_month', searcher='search_month')
|
||||
description = fields.Text(string='Description',
|
||||
states=STATES, depends=DEPENDS)
|
||||
category = fields.Many2One(string='Category', required=True,
|
||||
model_name='cashbook.category', ondelete='RESTRICT',
|
||||
states=STATES, depends=DEPENDS)
|
||||
state = fields.Selection(string='State', required=True, readonly=True,
|
||||
select=True, selection=sel_linetype)
|
||||
|
@ -220,6 +227,35 @@ class Line(Workflow, ModelSQL, ModelView):
|
|||
"""
|
||||
return [('description',) + tuple(clause[1:])]
|
||||
|
||||
@fields.depends('date')
|
||||
def on_change_with_month(self, name=None):
|
||||
""" get difference of month to current date
|
||||
"""
|
||||
IrDate = Pool().get('ir.date')
|
||||
if self.date is not None:
|
||||
dt1 = IrDate.today()
|
||||
return (12 * dt1.year + dt1.month) - \
|
||||
(12 * self.date.year + self.date.month)
|
||||
|
||||
@classmethod
|
||||
def search_month(cls, names, clause):
|
||||
""" search in month
|
||||
"""
|
||||
pool = Pool()
|
||||
Line = pool.get('cashbook.line')
|
||||
IrDate = pool.get('ir.date')
|
||||
tab_line = Line.__table__()
|
||||
Operator = fields.SQL_OPERATORS[clause[1]]
|
||||
|
||||
dt1 = IrDate.today()
|
||||
query = tab_line.select(tab_line.id,
|
||||
where=Operator(
|
||||
Literal(12 * dt1.year + dt1.month) - \
|
||||
(Literal(12) * DatePart('year', tab_line.date) + DatePart('month', tab_line.date)),
|
||||
clause[2]),
|
||||
)
|
||||
return [('id', 'in', query)]
|
||||
|
||||
@fields.depends('cashbook', '_parent_cashbook.state')
|
||||
def on_change_with_state_cashbook(self, name=None):
|
||||
""" get state of cashbook
|
||||
|
@ -233,6 +269,21 @@ class Line(Workflow, ModelSQL, ModelView):
|
|||
"""
|
||||
return [('cashbook.state',) + tuple(clause[1:])]
|
||||
|
||||
@classmethod
|
||||
def write(cls, *args):
|
||||
""" deny update if cashbook.line!='open'
|
||||
"""
|
||||
actions = iter(args)
|
||||
for lines, values in zip(actions, actions):
|
||||
for line in lines:
|
||||
if line.cashbook.state != 'open':
|
||||
raise UserError(gettext(
|
||||
'cashbook.msg_book_deny_write',
|
||||
bookname = line.cashbook.rec_name,
|
||||
state_txt = line.cashbook.state_string,
|
||||
))
|
||||
super(Line, cls).write(*args)
|
||||
|
||||
@classmethod
|
||||
def delete(cls, lines):
|
||||
""" deny delete if book is not 'open' or wf is not 'edit'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue