line: änderungesperre bei diversen wf-zuständen + test,

abstimmung: datum/betrag anfang/ende korrekt + test für beträge muß noch
This commit is contained in:
Frederik Jaeckel 2022-08-12 16:43:49 +02:00
parent 01825cc09c
commit 149baef174
10 changed files with 1099 additions and 64 deletions

65
line.py
View file

@ -78,7 +78,9 @@ class Line(Workflow, ModelSQL, ModelView):
credit = fields.Numeric(string='Credit', digits=(16, Eval('currency_digits', 2)),
required=True, readonly=True, depends=['currency_digits'])
reconciliation = fields.Many2One(string='Reconciliation', readonly=True,
model_name='cashbook.recon', ondelete='SET NULL')
model_name='cashbook.recon', ondelete='SET NULL',
domain=[('cashbook.id', '=', Eval('cashbook'))],
depends=['cashbook'])
balance = fields.Function(fields.Numeric(string='Balance',
digits=(16, Eval('currency_digits', 2)),
@ -184,9 +186,12 @@ class Line(Workflow, ModelSQL, ModelView):
def get_rec_name(self, name):
""" short + name
"""
return '%(date)s %(desc)s' % {
return '%(date)s|%(amount)s %(symbol)s|%(desc)s [%(category)s]' % {
'date': Report.format_date(self.date),
'desc': (self.description or '-')[:40],
'amount': Report.format_number(self.amount or 0.0, None),
'symbol': getattr(self.currency, 'symbol', '-'),
'category': self.category_view,
}
@staticmethod
@ -360,8 +365,23 @@ class Line(Workflow, ModelSQL, ModelView):
""" add debit/credit
"""
vlist = [x.copy() for x in vlist]
for vals in vlist:
vals.update(cls.get_debit_credit(vals))
for values in vlist:
values.update(cls.get_debit_credit(values))
# deny add to reconciliation if state is not 'check' or 'done'
if values.get('reconciliation', None):
if not values.get('state', '-') in ['check', 'done']:
date_txt = '-'
if values.get('date', None):
date_txt = Report.format_date(values.get('date', None))
raise UserError(gettext(
'cashbook.msg_line_deny_recon_by_state',
recname = '%(date)s|%(descr)s' % {
'date': date_txt,
'descr': values.get('description', '-'),
},
))
return super(Line, cls).create(vlist)
@classmethod
@ -373,14 +393,49 @@ class Line(Workflow, ModelSQL, ModelView):
to_write = []
for lines, values in zip(actions, actions):
for line in lines:
# deny write if chashbook is not open
if line.cashbook.state != 'open':
raise UserError(gettext(
'cashbook.msg_book_deny_write',
bookname = line.cashbook.rec_name,
state_txt = line.cashbook.state_string,
))
if line.reconciliation:
# deny state-change to 'edit' if line is linked to reconciliation
if values.get('state', '-') == 'edit':
raise UserError(gettext(
'cashbook.msg_line_deny_stateedit_with_recon',
recname = line.rec_name,
))
# debit / credit
# deny write if reconciliation is 'check' or 'done'
if line.reconciliation.state == 'done':
raise UserError(gettext(
'cashbook.msg_line_deny_write_by_reconciliation',
recname = line.rec_name,
reconame = line.reconciliation.rec_name,
))
# deny write if line is not 'Edit'
if line.state != 'edit':
# allow state-update, if its the only action
if not ((len(set({'state', 'reconciliation'}).intersection(values.keys())) > 0) \
and (len(values.keys()) == 1)):
raise UserError(gettext(
'cashbook.msg_line_deny_write',
recname = line.rec_name,
state_txt = line.state_string,
))
# deny add to reconciliation if state is not 'check' or 'done'
if values.get('reconciliation', None):
for line in lines:
if not line.state in ['check', 'done']:
raise UserError(gettext(
'cashbook.msg_line_deny_recon_by_state',
recname = line.rec_name
))
# update debit / credit
if len(set(values.keys()).intersection(set({'amount', 'bookingtype'}))) > 0:
for line in lines:
values2 = {}