mirror of
https://github.com/OCA/account-reconcile.git
synced 2025-01-20 12:27:39 +02:00
[FIX] Fail gracefully if there is no history to show
This commit is contained in:
@@ -140,8 +140,10 @@ class account_easy_reconcile(Model):
|
||||
def _last_history(self, cr, uid, ids, name, args, context=None):
|
||||
result = {}
|
||||
for history in self.browse(cr, uid, ids, context=context):
|
||||
# history is sorted by date desc
|
||||
result[history.id] = history.history_ids[0].id
|
||||
result[history.id] = False
|
||||
if history.history_ids:
|
||||
# history is sorted by date desc
|
||||
result[history.id] = history.history_ids[0].id
|
||||
return result
|
||||
|
||||
_columns = {
|
||||
@@ -222,6 +224,16 @@ class account_easy_reconcile(Model):
|
||||
context=context)
|
||||
return True
|
||||
|
||||
def _no_history(self, cr, uid, rec, context=None):
|
||||
""" Raise an `osv.except_osv` error, supposed to
|
||||
be called when there is no history on the reconciliation
|
||||
task.
|
||||
"""
|
||||
raise osv.except_osv(
|
||||
_('Error'),
|
||||
_('There is no history of reconciled '
|
||||
'entries on the task: %s.') % rec.name)
|
||||
|
||||
def last_history_reconcile(self, cr, uid, rec_id, context=None):
|
||||
""" Get the last history record for this reconciliation profile
|
||||
and return the action which opens move lines reconciled
|
||||
@@ -231,6 +243,8 @@ class account_easy_reconcile(Model):
|
||||
"Only 1 id expected"
|
||||
rec_id = rec_id[0]
|
||||
rec = self.browse(cr, uid, rec_id, context=context)
|
||||
if not rec.last_history:
|
||||
self._no_history(cr, uid, rec, context=context)
|
||||
return rec.last_history.open_reconcile()
|
||||
|
||||
def last_history_partial(self, cr, uid, rec_id, context=None):
|
||||
@@ -242,4 +256,6 @@ class account_easy_reconcile(Model):
|
||||
"Only 1 id expected"
|
||||
rec_id = rec_id[0]
|
||||
rec = self.browse(cr, uid, rec_id, context=context)
|
||||
if not rec.last_history:
|
||||
self._no_history(cr, uid, rec, context=context)
|
||||
return rec.last_history.open_partial()
|
||||
|
||||
Reference in New Issue
Block a user