line, book - wf + tests
This commit is contained in:
parent
ba442b726e
commit
654e9d2ee7
25 changed files with 786 additions and 160 deletions
99
line.py
99
line.py
|
@ -3,10 +3,14 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains the
|
||||
# full copyright notices and license terms.
|
||||
|
||||
from trytond.model import ModelView, ModelSQL, Workflow, fields
|
||||
from trytond.model import ModelView, ModelSQL, Workflow, fields, Check
|
||||
from trytond.pool import Pool
|
||||
from trytond.pyson import Eval, If
|
||||
from trytond.pyson import Eval, If, Or
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.report import Report
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.i18n import gettext
|
||||
from .book import sel_state_book
|
||||
|
||||
sel_linetype = [
|
||||
('edit', 'Edit'),
|
||||
|
@ -16,20 +20,23 @@ sel_linetype = [
|
|||
|
||||
|
||||
STATES = {
|
||||
'readonly': Eval('state', '') != 'edit',
|
||||
'readonly': Or(
|
||||
Eval('state', '') != 'edit',
|
||||
Eval('state_cashbook', '') != 'open',
|
||||
),
|
||||
}
|
||||
DEPENDS=['state']
|
||||
DEPENDS=['state', 'state_cashbook']
|
||||
|
||||
|
||||
class LineContext(ModelView):
|
||||
'Line Context'
|
||||
__name__ = 'cashbook.line.context'
|
||||
|
||||
account = fields.Many2One(string='Account', required=True,
|
||||
cashbook = fields.Many2One(string='Cashbook', required=True,
|
||||
model_name='cashbook.book',
|
||||
states={
|
||||
'readonly': Eval('num_account', 0) < 2,
|
||||
}, depends=['num_account'])
|
||||
'readonly': Eval('num_cashbook', 0) < 2,
|
||||
}, depends=['num_cashbook'])
|
||||
date_from = fields.Date(string='Start Date', depends=['date_to'],
|
||||
domain=[
|
||||
If(Eval('date_to') & Eval('date_from'),
|
||||
|
@ -46,16 +53,16 @@ class LineContext(ModelView):
|
|||
help='Show account lines in Checked-state.')
|
||||
done = fields.Boolean(string='Done',
|
||||
help='Show account lines in Done-state.')
|
||||
num_account = fields.Function(fields.Integer(string='Number of Accounts',
|
||||
num_cashbook = fields.Function(fields.Integer(string='Number of Cashbook',
|
||||
readonly=True, states={'invisible': True}),
|
||||
'on_change_with_num_account')
|
||||
'on_change_with_num_cashbook')
|
||||
|
||||
@classmethod
|
||||
def default_account(cls):
|
||||
def default_cashbook(cls):
|
||||
""" get default from context
|
||||
"""
|
||||
context = Transaction().context
|
||||
return context.get('account', None)
|
||||
return context.get('cashbook', None)
|
||||
|
||||
@classmethod
|
||||
def default_date_from(cls):
|
||||
|
@ -85,8 +92,8 @@ class LineContext(ModelView):
|
|||
context = Transaction().context
|
||||
return context.get('done', False)
|
||||
|
||||
def on_change_with_num_account(self, name=None):
|
||||
""" get number of accessible accounts,
|
||||
def on_change_with_num_cashbook(self, name=None):
|
||||
""" get number of accessible cashbooks,
|
||||
depends on user-permissions
|
||||
"""
|
||||
CashBook = Pool().get('cashbook.book')
|
||||
|
@ -96,10 +103,10 @@ class LineContext(ModelView):
|
|||
|
||||
|
||||
class Line(Workflow, ModelSQL, ModelView):
|
||||
'Account Line'
|
||||
'Cashbook Line'
|
||||
__name__ = 'cashbook.line'
|
||||
|
||||
account = fields.Many2One(string='Account', required=True, select=True,
|
||||
cashbook = fields.Many2One(string='Cashbook', required=True, select=True,
|
||||
model_name='cashbook.book', ondelete='CASCADE', readonly=True)
|
||||
date = fields.Date(string='Date', required=True, select=True,
|
||||
states=STATES, depends=DEPENDS)
|
||||
|
@ -107,11 +114,21 @@ class Line(Workflow, ModelSQL, ModelView):
|
|||
states=STATES, depends=DEPENDS)
|
||||
state = fields.Selection(string='State', required=True, readonly=True,
|
||||
select=True, selection=sel_linetype)
|
||||
state_string = state.translated('state')
|
||||
state_cashbook = fields.Function(fields.Selection(string='State of Cashbook',
|
||||
readonly=True, states={'invisible': True}, selection=sel_state_book),
|
||||
'on_change_with_state_cashbook', searcher='search_state_cashbook')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Line, cls).__setup__()
|
||||
cls._order.insert(0, ('date', 'ASC'))
|
||||
t = cls.__table__()
|
||||
cls._sql_constraints.extend([
|
||||
('state_val',
|
||||
Check(t, t.state.in_(['edit', 'check', 'done'])),
|
||||
'cashbook.msg_line_wrong_state_value'),
|
||||
])
|
||||
cls._transitions |= set((
|
||||
('edit', 'check'),
|
||||
('check', 'done'),
|
||||
|
@ -170,10 +187,58 @@ class Line(Workflow, ModelSQL, ModelView):
|
|||
return IrDate.today()
|
||||
|
||||
@classmethod
|
||||
def default_account(cls):
|
||||
def default_cashbook(cls):
|
||||
""" get default from context
|
||||
"""
|
||||
context = Transaction().context
|
||||
return context.get('account', None)
|
||||
return context.get('cashbook', None)
|
||||
|
||||
def get_rec_name(self, name):
|
||||
""" short + name
|
||||
"""
|
||||
return '%(date)s %(desc)s' % {
|
||||
'date': Report.format_date(self.date),
|
||||
'desc': (self.description or '-')[:40],
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def search_rec_name(cls, name, clause):
|
||||
""" search in description +...
|
||||
"""
|
||||
return [('description',) + tuple(clause[1:])]
|
||||
|
||||
@fields.depends('cashbook', '_parent_cashbook.state')
|
||||
def on_change_with_state_cashbook(self, name=None):
|
||||
""" get state of cashbook
|
||||
"""
|
||||
if self.cashbook:
|
||||
return self.cashbook.state
|
||||
|
||||
@classmethod
|
||||
def search_state_cashbook(cls, names, clause):
|
||||
""" search in state of cashbook
|
||||
"""
|
||||
return [('cashbook.state',) + tuple(clause[1:])]
|
||||
|
||||
@classmethod
|
||||
def delete(cls, lines):
|
||||
""" deny delete if book is not 'open' or wf is not 'edit'
|
||||
"""
|
||||
for line in lines:
|
||||
if line.cashbook.state == 'closed':
|
||||
raise UserError(gettext(
|
||||
'cashbook.msg_line_deny_delete1',
|
||||
linetxt = line.rec_name,
|
||||
bookname = line.cashbook.rec_name,
|
||||
bookstate = line.cashbook.state_string,
|
||||
))
|
||||
if line.state != 'edit':
|
||||
raise UserError(gettext(
|
||||
'cashbook.msg_line_deny_delete2',
|
||||
linetxt = line.rec_name,
|
||||
linestate = line.state_string,
|
||||
))
|
||||
|
||||
return super(Line, cls).delete(lines)
|
||||
|
||||
# end Line
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue