line: datumsbereich prüfen + test,
abstimmung: vorgänger beachten + test line: party/transfer-book + test muß noch
This commit is contained in:
parent
7a07da852d
commit
30b91cf518
8 changed files with 465 additions and 28 deletions
|
@ -81,6 +81,9 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
string="Currency"), 'on_change_with_currency')
|
||||
currency_digits = fields.Function(fields.Integer(string='Currency Digits'),
|
||||
'on_change_with_currency_digits')
|
||||
predecessor = fields.Function(fields.Many2One(string='Predecessor', readonly=True,
|
||||
model_name='cashbook.recon'),
|
||||
'on_change_with_predecessor')
|
||||
|
||||
state = fields.Selection(string='State', required=True, readonly=True,
|
||||
select=True, selection=sel_reconstate)
|
||||
|
@ -207,16 +210,25 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
for reconciliation in reconciliations:
|
||||
values = {}
|
||||
|
||||
# get start_amount: end_amount of predecessor
|
||||
pre_recon = Recon.search([
|
||||
('cashbook.id', '=', reconciliation.cashbook.id),
|
||||
('date_to', '<=', reconciliation.date_from),
|
||||
('state', 'in', ['check', 'done']),
|
||||
], order=[('date_to', 'DESC')], limit=1)
|
||||
if len(pre_recon) > 0:
|
||||
values['start_amount'] = pre_recon[0].end_amount
|
||||
if reconciliation.predecessor:
|
||||
# predecessor must be 'done'
|
||||
if reconciliation.predecessor.state != 'done':
|
||||
raise UserError(gettext(
|
||||
'cashbook.msg_recon_predecessor_not_done',
|
||||
recname_p = reconciliation.predecessor.rec_name,
|
||||
recname_c = reconciliation.rec_name,
|
||||
))
|
||||
|
||||
# check if current.date_from == predecessor.date_to
|
||||
if reconciliation.predecessor.date_to != reconciliation.date_from:
|
||||
raise UserError(gettext(
|
||||
'cashbook.msg_recon_date_from_to_mismatch',
|
||||
datefrom = Report.format_date(reconciliation.date_from),
|
||||
dateto = Report.format_date(reconciliation.predecessor.date_to),
|
||||
recname = reconciliation.rec_name,
|
||||
))
|
||||
values['start_amount'] = reconciliation.predecessor.end_amount
|
||||
else :
|
||||
# not found, use 'start_balance' of cashbook
|
||||
values['start_amount'] = reconciliation.cashbook.start_balance
|
||||
values['end_amount'] = values['start_amount']
|
||||
|
||||
|
@ -253,13 +265,32 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
for reconciliation in reconciliations:
|
||||
to_wfdone_line.extend(list(reconciliation.lines))
|
||||
|
||||
# deny if there are lines not linked to reconciliation
|
||||
if Line.search_count([
|
||||
('cashbook.id', '=', reconciliation.cashbook.id),
|
||||
('reconciliation', '=', None),
|
||||
['OR',
|
||||
[ # lines inside of date-range
|
||||
('date', '>', reconciliation.date_from),
|
||||
('date', '<', reconciliation.date_to),
|
||||
],
|
||||
# lines at from-date must relate to a reconciliation
|
||||
('date', '=', reconciliation.date_from),
|
||||
],
|
||||
]) > 0:
|
||||
raise UserError(gettext(
|
||||
'cashbook.msg_recon_lines_no_linked',
|
||||
date_from = Report.format_date(reconciliation.date_from),
|
||||
date_to = Report.format_date(reconciliation.date_to),
|
||||
))
|
||||
|
||||
if len(to_wfdone_line) > 0:
|
||||
Line.wfdone(to_wfdone_line)
|
||||
|
||||
def get_rec_name(self, name):
|
||||
""" short + name
|
||||
"""
|
||||
return '%(from)s - %(to)s | %(start_amount)s %(symbol)s - %(start_amount)s %(symbol)s [%(num)s]' % {
|
||||
return '%(from)s - %(to)s | %(start_amount)s %(symbol)s - %(end_amount)s %(symbol)s [%(num)s]' % {
|
||||
'from': Report.format_date(self.date_from, None) if self.date_from is not None else '-',
|
||||
'to': Report.format_date(self.date_to, None) if self.date_to is not None else '-',
|
||||
'start_amount': Report.format_number(self.start_amount or 0.0, None),
|
||||
|
@ -287,6 +318,21 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
IrDate = Pool().get('ir.date')
|
||||
return IrDate.today()
|
||||
|
||||
@fields.depends('cashbook', '_parent_cashbook.id', 'date_from')
|
||||
def on_change_with_predecessor(self, name=None):
|
||||
""" get predecessor
|
||||
"""
|
||||
Recon = Pool().get('cashbook.recon')
|
||||
|
||||
if self.cashbook:
|
||||
if self.date_from is not None:
|
||||
reconciliations = Recon.search([
|
||||
('cashbook.id', '=', self.cashbook.id),
|
||||
('date_from', '<', self.date_from),
|
||||
], order=[('date_from', 'DESC')], limit=1)
|
||||
if len(reconciliations) > 0:
|
||||
return reconciliations[0].id
|
||||
|
||||
@fields.depends('cashbook', '_parent_cashbook.currency')
|
||||
def on_change_with_currency(self, name=None):
|
||||
""" currency of cashbook
|
||||
|
@ -314,7 +360,16 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
def create(cls, vlist):
|
||||
""" add debit/credit
|
||||
"""
|
||||
Recon = Pool().get('cashbook.recon')
|
||||
|
||||
for values in vlist:
|
||||
# set date_from date_to of predecessor
|
||||
recons = Recon.search([
|
||||
('cashbook.id', '=', values.get('cashbook', -1)),
|
||||
], order=[('date_to', 'DESC')], limit=1)
|
||||
if len(recons) > 0:
|
||||
values['date_from'] = recons[0].date_to
|
||||
|
||||
cls.check_overlap_dates(
|
||||
values.get('date_from', None),
|
||||
values.get('date_to', None),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue