diff --git a/account_move_batch_validate/__openerp__.py b/account_move_batch_validate/__openerp__.py index 1b18be8f4..4dedcda13 100644 --- a/account_move_batch_validate/__openerp__.py +++ b/account_move_batch_validate/__openerp__.py @@ -45,7 +45,8 @@ ], 'demo_xml': [], 'test': [ - 'test/batch_validate.yml' + 'test/batch_validate.yml', + 'test/batch_validate_then_unmark.yml', ], 'installable': True, 'images': [], diff --git a/account_move_batch_validate/account.py b/account_move_batch_validate/account.py index 9030330a8..9f0771e62 100644 --- a/account_move_batch_validate/account.py +++ b/account_move_batch_validate/account.py @@ -96,12 +96,12 @@ class account_move(orm.Model): u'Task set to Done because the user unmarked the move' )) - def mark_for_posting(self, cr, uid, move_ids, context=None): + def mark_for_posting(self, cr, uid, move_ids, eta=None, context=None): """Mark a list of moves for delayed posting, and enqueue the jobs.""" if context is None: context = {} self.write(cr, uid, move_ids, {'to_post': True}, context=context) - self._delay_post_marked(cr, uid, context=context) + self._delay_post_marked(cr, uid, eta=eta, context=context) def unmark_for_posting(self, cr, uid, move_ids, context=None): """Unmark moves for delayed posting, and cancel the jobs.""" diff --git a/account_move_batch_validate/test/batch_validate_then_unmark.yml b/account_move_batch_validate/test/batch_validate_then_unmark.yml new file mode 100644 index 000000000..0f5523f40 --- /dev/null +++ b/account_move_batch_validate/test/batch_validate_then_unmark.yml @@ -0,0 +1,62 @@ +- + I create a move +- + !record {model: account.move, id: move2}: + journal_id: account.sales_journal + line_id: + - name: Receivable line + account_id: account.a_recv + debit: 2000.0 + - name: Sales line + account_id: account.a_sale + credit: 2000.0 +- + I check that the move is still draft +- + !assert {model: account.move, id: move2}: + - state == 'draft' +- + I create a wizard with a long ETA +- + !record {model: account.move.marker, id: wiz_marker2}: + action: mark + eta: 10000 +- + I run the wizard +- + !python {model: account.move.marker}: | + self.button_mark( + cr, uid, [ref('wiz_marker2')], context=context + ) +- + Now I change my mind and I create a wizard to unmark the moves +- + !record {model: account.move.marker, id: wiz_unmarker3}: + action: unmark +- + I run the wizard +- + !python {model: account.move.marker}: | + self.button_mark( + cr, uid, [ref('wiz_unmarker3')], context=context + ) +- + Now I checked that my job is done, and the move is still draft +- + !python {model: account.move}: | + from openerp.addons.connector.queue.job import OpenERPJobStorage + from openerp.addons.connector.session import ConnectorSession + + session = ConnectorSession(cr, uid, context=context) + storage = OpenERPJobStorage(session) + + move = self.browse(cr, uid, ref('move2'), context=context) + myjob = storage.load(move.post_job_uuid) + assert myjob.state == 'done', 'Job is in state {0}, should be done'.format( + myjob.state + ) +- + I check that the move is still draft +- + !assert {model: account.move, id: move2}: + - state == 'draft' diff --git a/account_move_batch_validate/wizard/move_marker.py b/account_move_batch_validate/wizard/move_marker.py index 12a6e7d98..675882884 100644 --- a/account_move_batch_validate/wizard/move_marker.py +++ b/account_move_batch_validate/wizard/move_marker.py @@ -36,7 +36,7 @@ class AccountMoveMarker(orm.TransientModel): ('mark', 'Mark for posting'), ('unmark', 'Unmark for posting'), ], "Action", required=True), - + 'eta': fields.integer('Seconds to wait before starting the jobs') } _defaults = { @@ -68,7 +68,8 @@ class AccountMoveMarker(orm.TransientModel): move_ids = move_obj.search(cr, uid, domain, context=context) if wiz.action == 'mark': - move_obj.mark_for_posting(cr, uid, move_ids, context=context) + move_obj.mark_for_posting(cr, uid, move_ids, eta=wiz.eta, + context=context) elif wiz.action == 'unmark': move_obj.unmark_for_posting(cr, uid, move_ids, context=context)