[add] new test for unmark feature

This commit is contained in:
Leonardo Pistone
2014-01-14 13:40:39 +01:00
parent 1cc40f9c91
commit b863f798aa
4 changed files with 69 additions and 5 deletions

View File

@@ -45,7 +45,8 @@
],
'demo_xml': [],
'test': [
'test/batch_validate.yml'
'test/batch_validate.yml',
'test/batch_validate_then_unmark.yml',
],
'installable': True,
'images': [],

View File

@@ -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."""

View File

@@ -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'

View File

@@ -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)