line: splitbuchung mit transfer

This commit is contained in:
Frederik Jaeckel 2022-09-10 21:21:17 +02:00
parent 86922aecef
commit 165612a627
8 changed files with 300 additions and 19 deletions

View file

@ -14,6 +14,17 @@ from .line import sel_linetype, sel_bookingtype, STATES, DEPENDS
from .book import sel_state_book
sel_linetype = [
('cat', 'Category'),
('tr', 'Transfer'),
]
sel_target = [
('cashbook.book', 'Cashbook'),
('cashbook.category', 'Category'),
]
class SplitLine(ModelSQL, ModelView):
'Split booking line'
__name__ = 'cashbook.split'
@ -23,9 +34,16 @@ class SplitLine(ModelSQL, ModelView):
readonly=True)
description = fields.Text(string='Description',
states=STATES, depends=DEPENDS)
splittype = fields.Selection(string='Type', required=True,
help='Type of split booking line', selection=sel_linetype,
states=STATES, depends=DEPENDS)
category = fields.Many2One(string='Category',
model_name='cashbook.category', ondelete='RESTRICT',
states=STATES, depends=DEPENDS+['bookingtype'], required=True,
states={
'readonly': STATES['readonly'],
'required': Eval('splittype', '') == 'cat',
'invisible': Eval('splittype', '') != 'cat',
}, depends=DEPENDS+['bookingtype', 'splittype'],
domain=[
If(
Eval('bookingtype', '') == 'spin',
@ -34,9 +52,23 @@ class SplitLine(ModelSQL, ModelView):
)])
category_view = fields.Function(fields.Char(string='Category', readonly=True),
'on_change_with_category_view')
booktransf = fields.Many2One(string='Source/Dest',
ondelete='RESTRICT', model_name='cashbook.book',
domain=[
('owner.id', '=', Eval('owner_cashbook', -1)),
('id', '!=', Eval('cashbook', -1)),
],
states={
'readonly': STATES['readonly'],
'invisible': Eval('splittype', '') != 'tr',
'required': Eval('splittype', '') == 'tr',
}, depends=DEPENDS+['bookingtype', 'owner_cashbook', 'cashbook'])
amount = fields.Numeric(string='Amount', digits=(16, Eval('currency_digits', 2)),
required=True, states=STATES, depends=DEPENDS+['currency_digits'])
target = fields.Function(fields.Reference(string='Target', readonly=True,
selection=sel_target), 'on_change_with_target')
currency = fields.Function(fields.Many2One(model_name='currency.currency',
string="Currency", readonly=True), 'on_change_with_currency')
currency_digits = fields.Function(fields.Integer(string='Currency Digits',
@ -45,18 +77,30 @@ class SplitLine(ModelSQL, ModelView):
selection=sel_bookingtype), 'on_change_with_bookingtype')
state = fields.Function(fields.Selection(string='State', readonly=True,
selection=sel_linetype), 'on_change_with_state')
cashbook = fields.Function(fields.Many2One(string='Cashbook',
readonly=True, states={'invisible': True}, model_name='cashbook.book'),
'on_change_with_cashbook')
state_cashbook = fields.Function(fields.Selection(string='State of Cashbook',
readonly=True, states={'invisible': True}, selection=sel_state_book),
'on_change_with_state_cashbook')
owner_cashbook = fields.Function(fields.Many2One(string='Owner', readonly=True,
states={'invisible': True}, model_name='res.user'),
'on_change_with_owner_cashbook')
@classmethod
def default_splittype(cls):
""" default category
"""
return 'cat'
def get_rec_name(self, name):
""" short + name
"""
return '%(type)s|%(amount)s %(symbol)s|%(desc)s [%(category)s]' % {
return '%(type)s|%(amount)s %(symbol)s|%(desc)s [%(target)s]' % {
'desc': (self.description or '-')[:40],
'amount': Report.format_number(self.amount, None),
'symbol': getattr(self.currency, 'symbol', '-'),
'category': self.category_view,
'target': self.category_view if self.splittype == 'cat' else self.booktransf.rec_name,
'type': gettext('cashbook.msg_line_bookingtype_%s' % self.line.bookingtype),
}
@ -80,6 +124,28 @@ class SplitLine(ModelSQL, ModelView):
to_currency)
return values
@fields.depends('splittype', 'category', 'booktransf')
def on_change_splittype(self):
""" clear category if not valid type
"""
if self.splittype:
if self.splittype == 'cat':
self.booktransf = None
if self.splittype == 'tr':
self.category = None
@fields.depends('splittype', 'category', 'booktransf')
def on_change_with_target(self, name=None):
""" get category or cashbook
"""
if self.splittype:
if self.splittype == 'cat':
if self.category:
return 'cashbook.category,%d' % self.category.id
elif self.splittype == 'tr':
if self.booktransf:
return 'cashbook.book,%d' % self.booktransf.id
@fields.depends('category')
def on_change_with_category_view(self, name=None):
""" show optimizef form of category for list-view
@ -101,6 +167,13 @@ class SplitLine(ModelSQL, ModelView):
if self.line:
return self.line.state
@fields.depends('line', '_parent_line.cashbook')
def on_change_with_cashbook(self, name=None):
""" get cashbook
"""
if self.line:
return self.line.cashbook.id
@fields.depends('line', '_parent_line.cashbook')
def on_change_with_state_cashbook(self, name=None):
""" get state of cashbook
@ -108,6 +181,13 @@ class SplitLine(ModelSQL, ModelView):
if self.line:
return self.line.cashbook.state
@fields.depends('line', '_parent_line.cashbook')
def on_change_with_owner_cashbook(self, name=None):
""" get current owner
"""
if self.line:
return self.line.cashbook.owner.id
@fields.depends('line', '_parent_line.bookingtype')
def on_change_with_bookingtype(self, name=None):
""" get type