From 518fe72cd2e28a0e9a243a3d386941907eaf5b21 Mon Sep 17 00:00:00 2001 From: Leonardo Pistone Date: Mon, 13 Jan 2014 10:12:48 +0100 Subject: [PATCH] [imp] account_move_batch_validate: first (partially) working state, yey! --- account_move_batch_validate/account.py | 27 +++++++++++++++++ account_move_batch_validate/account_view.xml | 3 -- .../wizard/move_marker.py | 29 ++++++++++--------- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/account_move_batch_validate/account.py b/account_move_batch_validate/account.py index 012f3bfed..b1cf5fdb8 100644 --- a/account_move_batch_validate/account.py +++ b/account_move_batch_validate/account.py @@ -22,6 +22,9 @@ from openerp.osv import fields, orm +from openerp.addons.connector.queue.job import job +from openerp.addons.connector.session import ConnectorSessionHandler + class account_move(orm.Model): @@ -36,3 +39,27 @@ class account_move(orm.Model): help='Check this box to mark the move for batch posting' ), } + + def mark_for_posting(self, cr, uid, ids, context=None): + """.""" + session_hdl = ConnectorSessionHandler(cr.dbname, uid) + with session_hdl.session() as session: + for move_id in ids: + validate_one_move.delay(session, self._name, move_id) + print('===== PUT IN QUEUE!!!!! %s' % move_id) + # work with session + + +@job +def validate_one_move(session, model_name, move_id): + """Press the button to validate a move. Return True. + + This trivial function is there just to be called as a job with the delay + method. + + """ + return session.pool['account.move'].button_validate( + session.cr, + session.uid, + [move_id] + ) diff --git a/account_move_batch_validate/account_view.xml b/account_move_batch_validate/account_view.xml index 7fb8d1156..1f5a60af9 100644 --- a/account_move_batch_validate/account_view.xml +++ b/account_move_batch_validate/account_view.xml @@ -13,9 +13,6 @@ - - - view.move.to_post.form account.move diff --git a/account_move_batch_validate/wizard/move_marker.py b/account_move_batch_validate/wizard/move_marker.py index a6cb6ca90..2a7b7be3d 100644 --- a/account_move_batch_validate/wizard/move_marker.py +++ b/account_move_batch_validate/wizard/move_marker.py @@ -51,7 +51,21 @@ class AccountMoveMarker(orm.TransientModel): move_obj = self.pool['account.move'] if wiz.action == 'mark': - import pdb;pdb.set_trace() + domain = [] + if wiz.journal_ids: + domain.append(( + 'journal_id', + 'in', + [journal.id for journal in wiz.journal_ids] + )) + + move_ids = move_obj.search(cr, uid, domain, context=context) + + move_obj.write(cr, uid, move_ids, {'to_post': True}) + move_obj.mark_for_posting(cr, uid, move_ids, context=context) + + return {'type': 'ir.actions.act_window_close'} + elif wiz.action == 'unmark': # TODO raise NotImplementedError( @@ -62,16 +76,3 @@ class AccountMoveMarker(orm.TransientModel): raise NotImplementedError( 'Date and period filter are not implemented yet' ) - - domain = [] - if wiz.journal_ids: - domain.append(( - 'journal_id', - 'in', - [journal.id for journal in wiz.journal_ids] - )) - - move_ids = move_obj.search(cr, uid, domain, context=context) - move_obj.write - for move in move_ids: - import pdb;pdb.set_trace() \ No newline at end of file