179 lines
4.9 KiB
Python
179 lines
4.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
# 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.
|
|
|
|
from trytond.model import ModelView, ModelSQL, Workflow, fields
|
|
from trytond.pool import Pool
|
|
from trytond.pyson import Eval, If
|
|
from trytond.transaction import Transaction
|
|
|
|
sel_linetype = [
|
|
('edit', 'Edit'),
|
|
('check', 'Checked'),
|
|
('done', 'Done'),
|
|
]
|
|
|
|
|
|
STATES = {
|
|
'readonly': Eval('state', '') != 'edit',
|
|
}
|
|
DEPENDS=['state']
|
|
|
|
|
|
class LineContext(ModelView):
|
|
'Line Context'
|
|
__name__ = 'cashbook.line.context'
|
|
|
|
account = fields.Many2One(string='Account', required=True,
|
|
model_name='cashbook.book',
|
|
states={
|
|
'readonly': Eval('num_account', 0) < 2,
|
|
}, depends=['num_account'])
|
|
date_from = fields.Date(string='Start Date', depends=['date_to'],
|
|
domain=[
|
|
If(Eval('date_to') & Eval('date_from'),
|
|
('date_from', '<=', Eval('date_to')),
|
|
()),
|
|
])
|
|
date_to = fields.Date(string='End Date', depends=['date_from'],
|
|
domain=[
|
|
If(Eval('date_to') & Eval('date_from'),
|
|
('date_from', '<=', Eval('date_to')),
|
|
()),
|
|
])
|
|
checked = fields.Boolean(string='Checked',
|
|
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',
|
|
readonly=True, states={'invisible': True}),
|
|
'on_change_with_num_account')
|
|
|
|
@classmethod
|
|
def default_account(cls):
|
|
""" get default from context
|
|
"""
|
|
context = Transaction().context
|
|
return context.get('account', None)
|
|
|
|
@classmethod
|
|
def default_date_from(cls):
|
|
""" get default from context
|
|
"""
|
|
context = Transaction().context
|
|
return context.get('date_from', None)
|
|
|
|
@classmethod
|
|
def default_date_to(cls):
|
|
""" get default from context
|
|
"""
|
|
context = Transaction().context
|
|
return context.get('date_to', None)
|
|
|
|
@classmethod
|
|
def default_checked(cls):
|
|
""" get default from context
|
|
"""
|
|
context = Transaction().context
|
|
return context.get('checked', False)
|
|
|
|
@classmethod
|
|
def default_done(cls):
|
|
""" get default from context
|
|
"""
|
|
context = Transaction().context
|
|
return context.get('done', False)
|
|
|
|
def on_change_with_num_account(self, name=None):
|
|
""" get number of accessible accounts,
|
|
depends on user-permissions
|
|
"""
|
|
CashBook = Pool().get('cashbook.book')
|
|
return CashBook.search_count([])
|
|
|
|
# end LineContext
|
|
|
|
|
|
class Line(Workflow, ModelSQL, ModelView):
|
|
'Account Line'
|
|
__name__ = 'cashbook.line'
|
|
|
|
account = fields.Many2One(string='Account', 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)
|
|
description = fields.Char(string='Description',
|
|
states=STATES, depends=DEPENDS)
|
|
state = fields.Selection(string='State', required=True, readonly=True,
|
|
select=True, selection=sel_linetype)
|
|
|
|
@classmethod
|
|
def __setup__(cls):
|
|
super(Line, cls).__setup__()
|
|
cls._order.insert(0, ('date', 'ASC'))
|
|
cls._transitions |= set((
|
|
('edit', 'check'),
|
|
('check', 'done'),
|
|
('check', 'edit'),
|
|
))
|
|
cls._buttons.update({
|
|
'wfedit': {
|
|
'invisible': Eval('state', '') != 'check',
|
|
'depends': ['state'],
|
|
},
|
|
'wfcheck': {
|
|
'invisible': Eval('state') != 'edit',
|
|
'depends': ['state'],
|
|
},
|
|
'wfdone': {
|
|
'invisible': Eval('state') != 'check',
|
|
'depends': ['state'],
|
|
},
|
|
})
|
|
|
|
@classmethod
|
|
@ModelView.button
|
|
@Workflow.transition('edit')
|
|
def wfedit(cls, lines):
|
|
""" edit line
|
|
"""
|
|
pass
|
|
|
|
@classmethod
|
|
@ModelView.button
|
|
@Workflow.transition('check')
|
|
def wfcheck(cls, lines):
|
|
""" line is checked
|
|
"""
|
|
pass
|
|
|
|
@classmethod
|
|
@ModelView.button
|
|
@Workflow.transition('done')
|
|
def wfdone(cls, lines):
|
|
""" line is done
|
|
"""
|
|
pass
|
|
|
|
@classmethod
|
|
def default_state(cls):
|
|
""" default: edit
|
|
"""
|
|
return 'edit'
|
|
|
|
@classmethod
|
|
def default_date(cls):
|
|
""" default: today
|
|
"""
|
|
IrDate = Pool().get('ir.date')
|
|
return IrDate.today()
|
|
|
|
@classmethod
|
|
def default_account(cls):
|
|
""" get default from context
|
|
"""
|
|
context = Transaction().context
|
|
return context.get('account', None)
|
|
|
|
# end Line
|