[ledgercli] Do not remove the old transaction on invalid update
This commit is contained in:
parent
86a6bec585
commit
816099ad55
2 changed files with 20 additions and 1 deletions
|
@ -442,7 +442,11 @@ class Ledger(Storage):
|
||||||
|
|
||||||
self.delete_transaction(transaction.id)
|
self.delete_transaction(transaction.id)
|
||||||
|
|
||||||
|
try:
|
||||||
self.add_transaction(transaction)
|
self.add_transaction(transaction)
|
||||||
|
except AccountingException as exc:
|
||||||
|
self.add_transaction(old_transaction)
|
||||||
|
raise exc
|
||||||
|
|
||||||
_log.info('Updated transaction %s', transaction.id)
|
_log.info('Updated transaction %s', transaction.id)
|
||||||
_log.debug('Updated transaction from: %s to: %s', old_transaction,
|
_log.debug('Updated transaction from: %s to: %s', old_transaction,
|
||||||
|
|
|
@ -336,5 +336,20 @@ class TransactionTestCase(unittest.TestCase):
|
||||||
'Something about this transaction\'s postings is' \
|
'Something about this transaction\'s postings is' \
|
||||||
' unexpected'
|
' unexpected'
|
||||||
|
|
||||||
|
def test_invalid_update_transaction_does_not_remove_existing(self):
|
||||||
|
transaction = self._add_simple_transaction()
|
||||||
|
old_transaction = copy.deepcopy(transaction)
|
||||||
|
|
||||||
|
transaction.postings[0].amount.amount = '9001.01'
|
||||||
|
|
||||||
|
response = self._post_json('/transaction/' + transaction.id,
|
||||||
|
{'transaction': transaction}, 400)
|
||||||
|
|
||||||
|
self.assertEqual(response['error']['type'], 'LedgerNotBalanced')
|
||||||
|
|
||||||
|
response = self._get_json('/transaction/' + transaction.id)
|
||||||
|
|
||||||
|
self.assertEqual(response['transaction'], old_transaction)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Reference in a new issue