diff --git a/line.py b/line.py
index 099bde5..d45ce5b 100644
--- a/line.py
+++ b/line.py
@@ -984,12 +984,6 @@ class LineContext(ModelView):
'Line Context'
__name__ = 'cashbook.line.context'
- cashbook = fields.Many2One(string='Cashbook', required=True,
- model_name='cashbook.book',
- domain=[('btype', '!=', None)],
- states={
- 'readonly': Eval('num_cashbook', 0) < 2,
- }, depends=['num_cashbook'])
date_from = fields.Date(string='Start Date', depends=['date_to'],
help='Limits the date range for the displayed entries.',
domain=[
@@ -1008,16 +1002,6 @@ class LineContext(ModelView):
help='Show account lines in Checked-state.')
done = fields.Boolean(string='Done',
help='Show account lines in Done-state.')
- num_cashbook = fields.Function(fields.Integer(string='Number of Cashbook',
- readonly=True, states={'invisible': True}),
- 'on_change_with_num_cashbook')
-
- @classmethod
- def default_cashbook(cls):
- """ get default from context
- """
- context = Transaction().context
- return context.get('cashbook', None)
@classmethod
def default_date_from(cls):
@@ -1040,17 +1024,6 @@ class LineContext(ModelView):
context = Transaction().context
return context.get('checked', False)
- @classmethod
- def default_num_cashbook(cls):
- """ get default from context
- """
- CashBook = Pool().get('cashbook.book')
-
- with Transaction().set_context({
- '_check_access': True,
- }):
- return CashBook.search_count([('btype', '!=', None)])
-
@classmethod
def default_done(cls):
""" get default from context
@@ -1058,11 +1031,4 @@ class LineContext(ModelView):
context = Transaction().context
return context.get('done', False)
- def on_change_with_num_cashbook(self, name=None):
- """ get number of accessible cashbooks,
- depends on user-permissions
- """
- LineContext = Pool().get('cashbook.line.context')
- return LineContext.default_num_cashbook()
-
# end LineContext
diff --git a/line.xml b/line.xml
index 284f259..b2a7ea3 100644
--- a/line.xml
+++ b/line.xml
@@ -32,7 +32,6 @@ full copyright notices and license terms. -->
cashbook.line.context
+
diff --git a/view/cashbook_line_context_form.xml b/view/cashbook_line_context_form.xml
index 01f1edb..9f7cbe1 100644
--- a/view/cashbook_line_context_form.xml
+++ b/view/cashbook_line_context_form.xml
@@ -2,20 +2,14 @@
-
diff --git a/wizard_openline.py b/wizard_openline.py
index 4aac5be..f4a6dbd 100644
--- a/wizard_openline.py
+++ b/wizard_openline.py
@@ -12,6 +12,32 @@ from trytond.exceptions import UserError
from trytond.transaction import Transaction
+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
+
+
class OpenCashBookStart(ModelView):
'Open Cashbook'
__name__ = 'cashbook.open_lines.start'
@@ -34,7 +60,7 @@ class OpenCashBookStart(ModelView):
# end OpenCashBookStart
-class OpenCashBook(Wizard):
+class OpenCashBook(OLineMixin, Wizard):
'Open Cashbook'
__name__ = 'cashbook.open_lines'
@@ -95,29 +121,13 @@ class OpenCashBook(Wizard):
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.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)
cfg1.save()
-
- action['pyson_context'] = PYSONEncoder().encode({
- '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': getattr(book, 'rec_name', '-/-'),
- }
+ action.update(self.add_action_data(book))
return action, {}
def transition_open_(self):
@@ -126,7 +136,7 @@ class OpenCashBook(Wizard):
# end OpenCashBook
-class OpenCashBookTree(Wizard):
+class OpenCashBookTree(OLineMixin, Wizard):
'Open Cashbook2'
__name__ = 'cashbook.open_lines_tree'
@@ -160,17 +170,7 @@ class OpenCashBookTree(Wizard):
bookname = book.rec_name,
))
- action['pyson_context'] = PYSONEncoder().encode({
- 'cashbook': getattr(book, 'id', None),
- 'date_from': cfg1.date_from,
- 'date_to': cfg1.date_to,
- 'checked': cfg1.checked,
- 'done': cfg1.done,
- })
- action['name'] = '%(name)s: %(cashbook)s' % {
- 'name': gettext('cashbook.msg_name_cashbook'),
- 'cashbook': getattr(book, 'rec_name', '-/-'),
- }
+ action.update(self.add_action_data(book))
return action, {}
# end OpenCashBookTree