cashbook/wizard_openline.py

77 lines
2.3 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, fields
from trytond.pyson import PYSONEncoder
from trytond.wizard import Wizard, StateView, StateAction, Button
from trytond.i18n import gettext
from trytond.pool import Pool
class OpenCashBookStart(ModelView):
'Open Cashbook'
__name__ = 'cashbook.open_lines.start'
cashbook = fields.Many2One(string='Cashbook', model_name='cashbook.book',
required=True)
checked = fields.Boolean(string='Checked', help="Show cashbook lines in Checked-state.")
done = fields.Boolean(string='Done', help="Show cashbook lines in Done-state")
date_from = fields.Date(string='Start Date')
date_to = fields.Date(string='End Date')
@classmethod
def default_checked(cls):
return True
@classmethod
def default_done(cls):
return False
# end OpenCashBookStart
class OpenCashBook(Wizard):
'Open Cashbook'
__name__ = 'cashbook.open_lines'
start = 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
"""
Book = Pool().get('cashbook.book')
result = {}
books = Book.search([])
print('\n## books:', books)
if len(books) == 1:
result['cashbook'] = books[0].id
return result
def do_open_(self, action):
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,
})
action['name'] = '%(name)s: %(cashbook)s' % {
'name': gettext('cashbook.msg_name_cashbook'),
'cashbook': self.start.cashbook.rec_name,
}
return action, {}
def transition_open_(self):
return 'end'
# end OpenCashBook