neu: kategorie, config + test
This commit is contained in:
parent
b9bb433c39
commit
d6a8b254a3
28 changed files with 1255 additions and 35 deletions
|
@ -5,9 +5,11 @@
|
|||
|
||||
from trytond.model import ModelView, ModelSQL, fields
|
||||
from trytond.pyson import PYSONEncoder
|
||||
from trytond.wizard import Wizard, StateView, StateAction, Button
|
||||
from trytond.wizard import Wizard, StateView, StateTransition, StateAction, Button
|
||||
from trytond.i18n import gettext
|
||||
from trytond.pool import Pool
|
||||
from trytond.pyson import Eval
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
|
||||
class OpenCashBookStart(ModelView):
|
||||
|
@ -36,38 +38,81 @@ class OpenCashBook(Wizard):
|
|||
'Open Cashbook'
|
||||
__name__ = 'cashbook.open_lines'
|
||||
|
||||
start = StateView('cashbook.open_lines.start',
|
||||
start_state = 'check'
|
||||
check = StateTransition()
|
||||
askuser = StateView('cashbook.open_lines.start',
|
||||
'cashbook.open_lines_view_form', [
|
||||
Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Open', 'open_', 'tryton-ok', default=True),
|
||||
])
|
||||
open_ = StateAction('cashbook.act_line_view')
|
||||
|
||||
def default_start(self, fields):
|
||||
""" setup form
|
||||
def transition_check(self):
|
||||
""" dont ask and open cashbook if user has 1x only
|
||||
"""
|
||||
Book = Pool().get('cashbook.book')
|
||||
|
||||
result = {}
|
||||
with Transaction().set_context({
|
||||
'_check_access': True,
|
||||
}):
|
||||
books = Book.search([])
|
||||
if len(books) == 1:
|
||||
return 'open_'
|
||||
return 'askuser'
|
||||
|
||||
books = Book.search([])
|
||||
print('\n## books:', books)
|
||||
if len(books) == 1:
|
||||
result['cashbook'] = books[0].id
|
||||
def default_askuser(self, fields):
|
||||
""" setup form
|
||||
"""
|
||||
Configuration = Pool().get('cashbook.configuration')
|
||||
|
||||
cfg1 = Configuration.get_singleton()
|
||||
result = {
|
||||
'date_from': getattr(cfg1, 'date_from', None),
|
||||
'date_to': getattr(cfg1, 'date_to', None),
|
||||
'checked': getattr(cfg1, 'checked', True),
|
||||
'done': getattr(cfg1, 'done', False),
|
||||
}
|
||||
return result
|
||||
|
||||
def do_open_(self, action):
|
||||
""" open view, use data from dialog
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Configuration = pool.get('cashbook.configuration')
|
||||
|
||||
cfg1 = Configuration.get_singleton()
|
||||
book = getattr(self.askuser, 'cashbook', None)
|
||||
if book is None:
|
||||
with Transaction().set_context({
|
||||
'_check_access': True,
|
||||
}):
|
||||
books = Book.search([])
|
||||
if len(books) > 0:
|
||||
book = books[0]
|
||||
|
||||
date_from = getattr(self.askuser, 'date_from', None)
|
||||
date_to = getattr(self.askuser, 'date_to', None)
|
||||
checked = getattr(self.askuser, 'checked', True)
|
||||
done = getattr(self.askuser, 'done', False)
|
||||
|
||||
# save settings
|
||||
cfg1.date_from = date_from
|
||||
cfg1.date_to = date_to
|
||||
cfg1.checked = checked
|
||||
cfg1.done = done
|
||||
cfg1.save()
|
||||
|
||||
action['pyson_context'] = PYSONEncoder().encode({
|
||||
'cashbook': self.start.cashbook.id,
|
||||
'date_from': self.start.date_from,
|
||||
'date_to': self.start.date_to,
|
||||
'checked': self.start.checked,
|
||||
'done': self.start.done,
|
||||
'cashbook': getattr(book, 'id', None),
|
||||
'date_from': date_from,
|
||||
'date_to': date_to,
|
||||
'checked': checked,
|
||||
'done': done,
|
||||
})
|
||||
action['name'] = '%(name)s: %(cashbook)s' % {
|
||||
'name': gettext('cashbook.msg_name_cashbook'),
|
||||
'cashbook': self.start.cashbook.rec_name,
|
||||
'cashbook': getattr(book, 'rec_name', '-/-'),
|
||||
}
|
||||
return action, {}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue