From 846bb0b5d40a61a1c7eef634c25b2f8eb56dd2fc Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Wed, 26 Feb 2014 14:12:54 +0100 Subject: [PATCH] [fix] when a the move we want to validate is not there anymore, close the job silently, with an appropriate message. I provide a test for that. --- account_move_batch_validate/__openerp__.py | 1 + account_move_batch_validate/account.py | 14 +++-- .../test/batch_validate_then_delete_move.yml | 51 +++++++++++++++++++ 3 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 account_move_batch_validate/test/batch_validate_then_delete_move.yml diff --git a/account_move_batch_validate/__openerp__.py b/account_move_batch_validate/__openerp__.py index e2d3fba83..7279201fe 100644 --- a/account_move_batch_validate/__openerp__.py +++ b/account_move_batch_validate/__openerp__.py @@ -73,6 +73,7 @@ 'test': [ 'test/batch_validate.yml', 'test/batch_validate_then_unmark.yml', + 'test/batch_validate_then_delete_move.yml', ], 'installable': True, 'images': [], diff --git a/account_move_batch_validate/account.py b/account_move_batch_validate/account.py index ea0620418..c29f22379 100644 --- a/account_move_batch_validate/account.py +++ b/account_move_batch_validate/account.py @@ -127,8 +127,12 @@ class account_move(orm.Model): @job def validate_one_move(session, model_name, move_id): """Validate a move, and leave the job reference in place.""" - session.pool['account.move'].button_validate( - session.cr, - session.uid, - [move_id] - ) + move_pool = session.pool['account.move'] + if move_pool.exists(session.cr, session.uid, [move_id]): + move_pool.button_validate( + session.cr, + session.uid, + [move_id] + ) + else: + return _(u'Nothing to do because the record has been deleted') diff --git a/account_move_batch_validate/test/batch_validate_then_delete_move.yml b/account_move_batch_validate/test/batch_validate_then_delete_move.yml new file mode 100644 index 000000000..be8389fd5 --- /dev/null +++ b/account_move_batch_validate/test/batch_validate_then_delete_move.yml @@ -0,0 +1,51 @@ +- + I create a move +- + !record {model: account.move, id: move3}: + journal_id: account.sales_journal + line_id: + - name: Receivable line + account_id: account.a_recv + debit: 3000.0 + - name: Sales line + account_id: account.a_sale + credit: 3000.0 +- + I check that the move is still draft +- + !assert {model: account.move, id: move3}: + - state == 'draft' +- + I create a wizard with a long ETA +- + !record {model: account.move.marker, id: wiz_marker4}: + action: mark + eta: 10000 +- + I run the wizard +- + !python {model: account.move.marker}: | + self.button_mark( + cr, uid, [ref('wiz_marker4')], context=context + ) +- + I read the UUID from the move, delete the move, then dequeue the job and run it. + It should raise no exceptions. +- + !python {model: account.move}: | + from openerp.addons.connector.queue.job import OpenERPJobStorage + from openerp.addons.connector.session import ConnectorSession + + move = self.browse(cr, uid, ref('move3'), context=context) + uuid = move.post_job_uuid + + assert uuid, 'The Job has not been created.' + self.unlink(cr, uid, ref('move3'), context=context) + + session = ConnectorSession(cr, uid, context=context) + storage = OpenERPJobStorage(session) + + myjob = storage.load(uuid) + myjob.perform(session) + + assert myjob.result == u'Nothing to do because the record has been deleted'