reconciliation: check_overlap_dates() in validate() verschoben + tests
This commit is contained in:
parent
91a34e216b
commit
0b3f82f6c7
2 changed files with 174 additions and 141 deletions
|
@ -117,35 +117,31 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
},
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def check_overlap_dates(cls, date_from, date_to, id_cashbook, record=None):
|
||||
def check_overlap_dates(self):
|
||||
""" deny overlap of date_from/date_to between records of same cashbook
|
||||
allow: date_to=date_from
|
||||
"""
|
||||
Recon = Pool().get('cashbook.recon')
|
||||
|
||||
query = [
|
||||
('cashbook.id', '=', id_cashbook),
|
||||
('cashbook.id', '=', self.cashbook.id),
|
||||
('id', '!=', self.id),
|
||||
['OR',
|
||||
[ # 'start' is inside of other record
|
||||
('date_from', '<=', date_from),
|
||||
('date_to', '>', date_from),
|
||||
('date_from', '<=', self.date_from),
|
||||
('date_to', '>', self.date_from),
|
||||
],
|
||||
[ # 'end' is inside of other record
|
||||
('date_from', '<', date_to),
|
||||
('date_to', '>=', date_to),
|
||||
('date_from', '<', self.date_to),
|
||||
('date_to', '>=', self.date_to),
|
||||
],
|
||||
[ # enclose other record
|
||||
('date_from', '>=', date_from),
|
||||
('date_to', '<=', date_to),
|
||||
('date_from', '>=', self.date_from),
|
||||
('date_to', '<=', self.date_to),
|
||||
],
|
||||
],
|
||||
]
|
||||
|
||||
# avoid finding ourselves
|
||||
if record:
|
||||
query.append(('id', '!=', record.id))
|
||||
|
||||
if Recon.search_count(query) > 0:
|
||||
raise UserError(gettext('cashbook.msg_recon_err_overlap'))
|
||||
|
||||
|
@ -373,6 +369,15 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
if self.cashbook:
|
||||
return self.cashbook.state
|
||||
|
||||
@classmethod
|
||||
def validate(cls, reconciliations):
|
||||
""" deny overlap of dates
|
||||
"""
|
||||
super(Reconciliation, cls).validate(reconciliations)
|
||||
|
||||
for reconciliation in reconciliations:
|
||||
reconciliation.check_overlap_dates()
|
||||
|
||||
@classmethod
|
||||
def create(cls, vlist):
|
||||
""" add debit/credit
|
||||
|
@ -403,10 +408,6 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
if len(lines) > 0:
|
||||
values['date_to'] = lines[0].date
|
||||
|
||||
cls.check_overlap_dates(
|
||||
values.get('date_from', None),
|
||||
values.get('date_to', None),
|
||||
values.get('cashbook', None))
|
||||
return super(Reconciliation, cls).create(vlist)
|
||||
|
||||
@classmethod
|
||||
|
@ -418,22 +419,12 @@ class Reconciliation(Workflow, ModelSQL, ModelView):
|
|||
for reconciliations, values in zip(actions, actions):
|
||||
# deny write if chashbook is not open
|
||||
for reconciliation in reconciliations:
|
||||
|
||||
# deny overlap
|
||||
if len(set({'date_from', 'date_to'}).intersection(set(values.keys()))) > 0:
|
||||
cls.check_overlap_dates(
|
||||
values.get('date_from', reconciliation.date_from),
|
||||
values.get('date_to', reconciliation.date_to),
|
||||
reconciliation.cashbook.id,
|
||||
reconciliation)
|
||||
|
||||
if reconciliation.cashbook.state != 'open':
|
||||
raise UserError(gettext(
|
||||
'cashbook.msg_book_deny_write',
|
||||
bookname = reconciliation.cashbook.rec_name,
|
||||
state_txt = reconciliation.cashbook.state_string,
|
||||
))
|
||||
|
||||
super(Reconciliation, cls).write(*args)
|
||||
|
||||
@classmethod
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue