line/book: kassenbuch öffnen/anzeige optimiert

This commit is contained in:
Frederik Jaeckel 2022-10-11 10:21:11 +02:00
parent 557a8b47ba
commit ef32bd79f9
4 changed files with 40 additions and 78 deletions

34
line.py
View file

@ -984,12 +984,6 @@ class LineContext(ModelView):
'Line Context' 'Line Context'
__name__ = 'cashbook.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'], date_from = fields.Date(string='Start Date', depends=['date_to'],
help='Limits the date range for the displayed entries.', help='Limits the date range for the displayed entries.',
domain=[ domain=[
@ -1008,16 +1002,6 @@ class LineContext(ModelView):
help='Show account lines in Checked-state.') help='Show account lines in Checked-state.')
done = fields.Boolean(string='Done', done = fields.Boolean(string='Done',
help='Show account lines in Done-state.') 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 @classmethod
def default_date_from(cls): def default_date_from(cls):
@ -1040,17 +1024,6 @@ class LineContext(ModelView):
context = Transaction().context context = Transaction().context
return context.get('checked', False) 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 @classmethod
def default_done(cls): def default_done(cls):
""" get default from context """ get default from context
@ -1058,11 +1031,4 @@ class LineContext(ModelView):
context = Transaction().context context = Transaction().context
return context.get('done', False) 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 # end LineContext

View file

@ -32,7 +32,6 @@ full copyright notices and license terms. -->
<field name="context_model">cashbook.line.context</field> <field name="context_model">cashbook.line.context</field>
<field name="context_domain" <field name="context_domain"
eval="[ eval="[
('cashbook', '=', Eval('cashbook', -1)),
If(Bool(Eval('date_from')), ('date', '&gt;=', Eval('date_from')), ()), If(Bool(Eval('date_from')), ('date', '&gt;=', Eval('date_from')), ()),
If(Bool(Eval('date_to')), ('date', '&lt;=', Eval('date_to')), ()), If(Bool(Eval('date_to')), ('date', '&lt;=', Eval('date_to')), ()),
['OR', ['OR',
@ -42,6 +41,9 @@ full copyright notices and license terms. -->
], ],
]" ]"
pyson="1"/> pyson="1"/>
<field name="domain"
eval="[('cashbook', '=', Eval('cashbook', -1))]"
pyson="1"/>
</record> </record>
<record model="ir.action.act_window.view" id="act_line_view-1"> <record model="ir.action.act_window.view" id="act_line_view-1">
<field name="sequence" eval="10"/> <field name="sequence" eval="10"/>

View file

@ -2,20 +2,14 @@
<!-- This file is part of the cashbook-module from m-ds for Tryton. <!-- 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 The COPYRIGHT file at the top level of this repository contains the
full copyright notices and license terms. --> full copyright notices and license terms. -->
<form col="6"> <form col="8">
<label name="cashbook"/>
<field name="cashbook" widget="selection" colspan="3"/>
<label name="checked"/>
<field name="checked"/>
<label name="date_from"/> <label name="date_from"/>
<field name="date_from"/> <field name="date_from"/>
<label name="date_to"/> <label name="date_to"/>
<field name="date_to"/> <field name="date_to"/>
<label name="checked"/>
<field name="checked"/>
<label name="done"/> <label name="done"/>
<field name="done"/> <field name="done"/>
<field name="num_cashbook"/>
</form> </form>

View file

@ -12,6 +12,32 @@ from trytond.exceptions import UserError
from trytond.transaction import Transaction 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): class OpenCashBookStart(ModelView):
'Open Cashbook' 'Open Cashbook'
__name__ = 'cashbook.open_lines.start' __name__ = 'cashbook.open_lines.start'
@ -34,7 +60,7 @@ class OpenCashBookStart(ModelView):
# end OpenCashBookStart # end OpenCashBookStart
class OpenCashBook(Wizard): class OpenCashBook(OLineMixin, Wizard):
'Open Cashbook' 'Open Cashbook'
__name__ = 'cashbook.open_lines' __name__ = 'cashbook.open_lines'
@ -95,29 +121,13 @@ class OpenCashBook(Wizard):
if len(books) > 0: if len(books) > 0:
book = 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 # save settings
cfg1.date_from = date_from cfg1.date_from = getattr(self.askuser, 'date_from', None)
cfg1.date_to = date_to cfg1.date_to = getattr(self.askuser, 'date_to', None)
cfg1.checked = checked cfg1.checked = getattr(self.askuser, 'checked', True)
cfg1.done = done cfg1.done = getattr(self.askuser, 'done', False)
cfg1.save() cfg1.save()
action.update(self.add_action_data(book))
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', '-/-'),
}
return action, {} return action, {}
def transition_open_(self): def transition_open_(self):
@ -126,7 +136,7 @@ class OpenCashBook(Wizard):
# end OpenCashBook # end OpenCashBook
class OpenCashBookTree(Wizard): class OpenCashBookTree(OLineMixin, Wizard):
'Open Cashbook2' 'Open Cashbook2'
__name__ = 'cashbook.open_lines_tree' __name__ = 'cashbook.open_lines_tree'
@ -160,17 +170,7 @@ class OpenCashBookTree(Wizard):
bookname = book.rec_name, bookname = book.rec_name,
)) ))
action['pyson_context'] = PYSONEncoder().encode({ action.update(self.add_action_data(book))
'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', '-/-'),
}
return action, {} return action, {}
# end OpenCashBookTree # end OpenCashBookTree