book: Feld 'start_date' + test,
line: balance-berechnung mit abstimmung gekoppelt + test, abstimmung: start/enddatum automatisch
This commit is contained in:
parent
5729ed0a07
commit
91a34e216b
13 changed files with 446 additions and 20 deletions
59
line.py
59
line.py
|
@ -123,7 +123,10 @@ class Line(Workflow, ModelSQL, ModelView):
|
|||
reconciliation = fields.Many2One(string='Reconciliation', readonly=True,
|
||||
model_name='cashbook.recon', ondelete='SET NULL',
|
||||
domain=[('cashbook.id', '=', Eval('cashbook'))],
|
||||
depends=['cashbook'])
|
||||
depends=['cashbook'],
|
||||
states={
|
||||
'invisible': ~Bool(Eval('reconciliation')),
|
||||
})
|
||||
|
||||
balance = fields.Function(fields.Numeric(string='Balance',
|
||||
digits=(16, Eval('currency_digits', 2)),
|
||||
|
@ -491,17 +494,44 @@ class Line(Workflow, ModelSQL, ModelView):
|
|||
else:
|
||||
return 2
|
||||
|
||||
@fields.depends('id', 'cashbook', '_parent_cashbook.start_balance', '_parent_cashbook.id')
|
||||
@fields.depends('id', 'date', 'cashbook', \
|
||||
'_parent_cashbook.start_balance', '_parent_cashbook.id',\
|
||||
'reconciliation', '_parent_reconciliation.start_amount')
|
||||
def on_change_with_balance(self, name=None):
|
||||
""" compute balance until current line, with current sort order
|
||||
""" compute balance until current line, with current sort order,
|
||||
try to use a reconciliation as start to speed up calculation
|
||||
"""
|
||||
Line = Pool().get('cashbook.line')
|
||||
pool = Pool()
|
||||
Reconciliation = pool.get('cashbook.recon')
|
||||
Line = pool.get('cashbook.line')
|
||||
|
||||
if self.cashbook:
|
||||
balance = self.cashbook.start_balance
|
||||
lines = Line.search([
|
||||
query = [
|
||||
('cashbook.id', '=', self.cashbook.id),
|
||||
])
|
||||
]
|
||||
balance = self.cashbook.start_balance
|
||||
|
||||
# get existing reconciliation, starting before current line
|
||||
# this will speed up calculation of by-line-balance
|
||||
if self.date is not None:
|
||||
recons = Reconciliation.search([
|
||||
('cashbook.id', '=', self.cashbook.id),
|
||||
('date_from', '<=', self.date),
|
||||
('state', '=', 'done'),
|
||||
], order=[('date_from', 'DESC')], limit=1)
|
||||
if len(recons) > 0:
|
||||
query.extend([
|
||||
['OR',
|
||||
('date', '>', recons[0].date_from),
|
||||
[
|
||||
('date', '=', recons[0].date_from),
|
||||
('reconciliation.id', '=',recons[0].id),
|
||||
],
|
||||
]
|
||||
])
|
||||
balance = recons[0].start_amount
|
||||
|
||||
lines = Line.search(query)
|
||||
for line in lines:
|
||||
balance += line.credit - line.debit
|
||||
if line.id == self.id:
|
||||
|
@ -535,6 +565,19 @@ class Line(Workflow, ModelSQL, ModelView):
|
|||
raise ValueError('invalid "bookingtype"')
|
||||
return {}
|
||||
|
||||
@classmethod
|
||||
def validate(cls, lines):
|
||||
""" deny date before 'start_date' of cashbook
|
||||
"""
|
||||
super(Line, cls).validate(lines)
|
||||
for line in lines:
|
||||
if line.date < line.cashbook.start_date:
|
||||
raise UserError(gettext(
|
||||
'cashbook.msg_line_date_before_book',
|
||||
datebook = Report.format_date(line.cashbook.start_date),
|
||||
recname = line.rec_name,
|
||||
))
|
||||
|
||||
@classmethod
|
||||
def copy(cls, lines, default=None):
|
||||
""" reset values
|
||||
|
@ -580,7 +623,7 @@ 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
|
||||
# deny write if cashbook is not open
|
||||
if line.cashbook.state != 'open':
|
||||
raise UserError(gettext(
|
||||
'cashbook.msg_book_deny_write',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue