mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[add] new test for unmark feature
This commit is contained in:
@@ -45,7 +45,8 @@
|
||||
],
|
||||
'demo_xml': [],
|
||||
'test': [
|
||||
'test/batch_validate.yml'
|
||||
'test/batch_validate.yml',
|
||||
'test/batch_validate_then_unmark.yml',
|
||||
],
|
||||
'installable': True,
|
||||
'images': [],
|
||||
|
||||
@@ -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."""
|
||||
|
||||
@@ -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'
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user