2022-08-05 14:47:43 +00:00
|
|
|
# -*- 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.
|
|
|
|
|
2022-08-17 15:16:23 +00:00
|
|
|
from trytond.model import ModelView, fields
|
2022-08-05 14:47:43 +00:00
|
|
|
from trytond.pyson import PYSONEncoder
|
2022-08-09 13:08:41 +00:00
|
|
|
from trytond.wizard import Wizard, StateView, StateTransition, StateAction, Button
|
2022-08-05 14:47:43 +00:00
|
|
|
from trytond.i18n import gettext
|
2022-08-08 15:31:16 +00:00
|
|
|
from trytond.pool import Pool
|
2022-10-06 11:28:42 +00:00
|
|
|
from trytond.exceptions import UserError
|
2022-08-09 13:08:41 +00:00
|
|
|
from trytond.transaction import Transaction
|
2022-08-05 14:47:43 +00:00
|
|
|
|
|
|
|
|
2022-10-11 08:21:11 +00:00
|
|
|
class OLineMixin:
|
|
|
|
""" mixin to extend action-data
|
|
|
|
"""
|
|
|
|
def add_action_data(self, book):
|
|
|
|
""" add book and cfg
|
|
|
|
"""
|
|
|
|
Configuration = Pool().get('cashbook.configuration')
|
|
|
|
cfg1 = Configuration.get_singleton()
|
|
|
|
action = {
|
|
|
|
'pyson_context': PYSONEncoder().encode({
|
|
|
|
'cashbook': getattr(book, 'id', None),
|
|
|
|
'date_from': getattr(cfg1, 'date_from', None),
|
|
|
|
'date_to': getattr(cfg1, 'date_to', None),
|
|
|
|
'checked': getattr(cfg1, 'checked', None),
|
|
|
|
'done': getattr(cfg1, 'done', None),
|
|
|
|
}),
|
|
|
|
'name' : '%(name)s: %(cashbook)s' % {
|
|
|
|
'name': gettext('cashbook.msg_name_cashbook'),
|
|
|
|
'cashbook': getattr(book, 'rec_name', '-/-'),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return action
|
|
|
|
|
|
|
|
# OLineMixin
|
|
|
|
|
|
|
|
|
2022-08-05 14:47:43 +00:00
|
|
|
class OpenCashBookStart(ModelView):
|
|
|
|
'Open Cashbook'
|
2022-08-08 12:31:42 +00:00
|
|
|
__name__ = 'cashbook.open_lines.start'
|
2022-08-05 14:47:43 +00:00
|
|
|
|
2022-08-08 12:31:42 +00:00
|
|
|
cashbook = fields.Many2One(string='Cashbook', model_name='cashbook.book',
|
2022-09-16 08:15:51 +00:00
|
|
|
required=True, domain=[('btype', '!=', None)])
|
2022-08-08 12:31:42 +00:00
|
|
|
checked = fields.Boolean(string='Checked', help="Show cashbook lines in Checked-state.")
|
|
|
|
done = fields.Boolean(string='Done', help="Show cashbook lines in Done-state")
|
2022-08-05 14:47:43 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2022-10-11 08:21:11 +00:00
|
|
|
class OpenCashBook(OLineMixin, Wizard):
|
2022-08-05 14:47:43 +00:00
|
|
|
'Open Cashbook'
|
2022-08-08 12:31:42 +00:00
|
|
|
__name__ = 'cashbook.open_lines'
|
2022-08-05 14:47:43 +00:00
|
|
|
|
2022-08-09 13:08:41 +00:00
|
|
|
start_state = 'check'
|
|
|
|
check = StateTransition()
|
|
|
|
askuser = StateView('cashbook.open_lines.start',
|
2022-08-08 12:31:42 +00:00
|
|
|
'cashbook.open_lines_view_form', [
|
2022-08-05 14:47:43 +00:00
|
|
|
Button('Cancel', 'end', 'tryton-cancel'),
|
|
|
|
Button('Open', 'open_', 'tryton-ok', default=True),
|
|
|
|
])
|
2022-11-16 20:56:02 +00:00
|
|
|
open_ = StateAction('cashbook.act_line_view2')
|
2022-08-05 14:47:43 +00:00
|
|
|
|
2022-08-09 13:08:41 +00:00
|
|
|
def transition_check(self):
|
|
|
|
""" dont ask and open cashbook if user has 1x only
|
2022-08-08 15:31:16 +00:00
|
|
|
"""
|
|
|
|
Book = Pool().get('cashbook.book')
|
|
|
|
|
2022-08-09 13:08:41 +00:00
|
|
|
with Transaction().set_context({
|
|
|
|
'_check_access': True,
|
|
|
|
}):
|
2022-09-16 08:15:51 +00:00
|
|
|
books = Book.search([('btype', '!=', None)])
|
2022-08-09 13:08:41 +00:00
|
|
|
if len(books) == 1:
|
|
|
|
return 'open_'
|
|
|
|
return 'askuser'
|
2022-08-08 15:31:16 +00:00
|
|
|
|
2022-08-09 13:08:41 +00:00
|
|
|
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),
|
|
|
|
}
|
2022-08-08 15:31:16 +00:00
|
|
|
return result
|
|
|
|
|
2022-08-05 14:47:43 +00:00
|
|
|
def do_open_(self, action):
|
2022-08-09 13:08:41 +00:00
|
|
|
""" open view, use data from dialog
|
|
|
|
"""
|
|
|
|
pool = Pool()
|
|
|
|
Book = pool.get('cashbook.book')
|
|
|
|
Configuration = pool.get('cashbook.configuration')
|
|
|
|
|
|
|
|
cfg1 = Configuration.get_singleton()
|
book, line, category, types: berechtigung für company-user + test,
book: währung neu,
line: buchungstyp, betrag, credit, debit, währung, sortierung
2022-08-10 14:30:08 +00:00
|
|
|
if cfg1 is None:
|
|
|
|
cfg1 = Configuration()
|
|
|
|
cfg1.save()
|
|
|
|
|
2022-08-09 13:08:41 +00:00
|
|
|
book = getattr(self.askuser, 'cashbook', None)
|
|
|
|
if book is None:
|
|
|
|
with Transaction().set_context({
|
|
|
|
'_check_access': True,
|
|
|
|
}):
|
2022-09-16 08:15:51 +00:00
|
|
|
books = Book.search([('btype', '!=', None)])
|
2022-08-09 13:08:41 +00:00
|
|
|
if len(books) > 0:
|
|
|
|
book = books[0]
|
|
|
|
|
|
|
|
# save settings
|
2022-10-11 08:21:11 +00:00
|
|
|
cfg1.date_from = getattr(self.askuser, 'date_from', None)
|
|
|
|
cfg1.date_to = getattr(self.askuser, 'date_to', None)
|
|
|
|
cfg1.checked = getattr(self.askuser, 'checked', True)
|
|
|
|
cfg1.done = getattr(self.askuser, 'done', False)
|
2022-08-09 13:08:41 +00:00
|
|
|
cfg1.save()
|
2022-10-11 08:21:11 +00:00
|
|
|
action.update(self.add_action_data(book))
|
2022-08-05 14:47:43 +00:00
|
|
|
return action, {}
|
|
|
|
|
|
|
|
def transition_open_(self):
|
|
|
|
return 'end'
|
|
|
|
|
|
|
|
# end OpenCashBook
|
2022-10-06 11:28:42 +00:00
|
|
|
|
|
|
|
|
2022-10-11 08:21:11 +00:00
|
|
|
class OpenCashBookTree(OLineMixin, Wizard):
|
2022-10-06 11:28:42 +00:00
|
|
|
'Open Cashbook2'
|
|
|
|
__name__ = 'cashbook.open_lines_tree'
|
|
|
|
|
|
|
|
start_state = 'open_'
|
2022-11-16 20:56:02 +00:00
|
|
|
open_ = StateAction('cashbook.act_line_view2')
|
2022-10-06 11:28:42 +00:00
|
|
|
|
|
|
|
def do_open_(self, action):
|
|
|
|
""" open view from doubleclick
|
|
|
|
"""
|
|
|
|
pool = Pool()
|
|
|
|
Book = pool.get('cashbook.book')
|
|
|
|
Configuration = pool.get('cashbook.configuration')
|
|
|
|
|
|
|
|
cfg1 = Configuration.get_singleton()
|
|
|
|
if cfg1 is None:
|
|
|
|
cfg1 = Configuration()
|
|
|
|
cfg1.save()
|
|
|
|
|
|
|
|
book = self.record
|
|
|
|
if book is None:
|
|
|
|
with Transaction().set_context({
|
|
|
|
'_check_access': True,
|
|
|
|
}):
|
|
|
|
books = Book.search([('btype', '!=', None)])
|
|
|
|
if len(books) > 0:
|
|
|
|
book = books[0]
|
|
|
|
else :
|
|
|
|
if book.btype is None:
|
|
|
|
raise UserError(gettext(
|
|
|
|
'cashbook.msg_book_no_type_noopen',
|
|
|
|
bookname = book.rec_name,
|
|
|
|
))
|
|
|
|
|
2022-10-11 08:21:11 +00:00
|
|
|
action.update(self.add_action_data(book))
|
2022-10-06 11:28:42 +00:00
|
|
|
return action, {}
|
|
|
|
|
|
|
|
# end OpenCashBookTree
|