From cee4ec297d922faf7195359305ca6221fde8e329 Mon Sep 17 00:00:00 2001 From: "Adrien Peiffer (ACSONE)" Date: Tue, 30 Jun 2015 10:10:10 +0200 Subject: [PATCH] [CHG][account_move_batch_validate] Overload standard wizard --- .../test/batch_validate.yml | 18 +++- .../test/batch_validate_then_delete_move.yml | 18 +++- .../test/batch_validate_then_unmark.yml | 36 ++++++-- .../wizard/move_marker.py | 88 +++++++------------ .../wizard/move_marker_view.xml | 56 +++--------- 5 files changed, 103 insertions(+), 113 deletions(-) diff --git a/account_move_batch_validate/test/batch_validate.yml b/account_move_batch_validate/test/batch_validate.yml index e129914fa..898d0dce5 100644 --- a/account_move_batch_validate/test/batch_validate.yml +++ b/account_move_batch_validate/test/batch_validate.yml @@ -18,14 +18,26 @@ - I create a wizard - - !record {model: account.move.marker, id: wiz_marker1}: + !record {model: validate.account.move, id: wiz_marker1}: action: mark +- + I set the period and the journal on the wizard +- + !python {model: validate.account.move}: | + move = self.pool['account.move'].browse(cr, uid, ref('move1'), + context=context) + journal_ids = [(6, 0, [move.journal_id.id])] + period_ids = [(6, 0, [move.period_id.id])] + vals = {'journal_ids': journal_ids, + 'period_ids': period_ids, + } + self.write(cr, uid, ref('wiz_marker1'), vals, context=context) - I run the wizard - - !python {model: account.move.marker}: | + !python {model: validate.account.move}: | context['automated_test_execute_now'] = True - self.button_mark( + self.validate_move( cr, uid, [ref('wiz_marker1')], context=context ) - 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 index c7f1d7400..82a50cbcb 100644 --- a/account_move_batch_validate/test/batch_validate_then_delete_move.yml +++ b/account_move_batch_validate/test/batch_validate_then_delete_move.yml @@ -18,15 +18,27 @@ - I create a wizard with a long ETA - - !record {model: account.move.marker, id: wiz_marker4}: + !record {model: validate.account.move, id: wiz_marker4}: action: mark eta: 10000 +- + I set the period and the journal on the wizard +- + !python {model: validate.account.move}: | + move = self.pool['account.move'].browse(cr, uid, ref('move3'), + context=context) + journal_ids = [(6, 0, [move.journal_id.id])] + period_ids = [(6, 0, [move.period_id.id])] + vals = {'journal_ids': journal_ids, + 'period_ids': period_ids, + } + self.write(cr, uid, ref('wiz_marker4'), vals, context=context) - I run the wizard - - !python {model: account.move.marker}: | + !python {model: validate.account.move}: | context['automated_test_execute_now'] = True - self.button_mark( + self.validate_move( cr, uid, [ref('wiz_marker4')], context=context ) - diff --git a/account_move_batch_validate/test/batch_validate_then_unmark.yml b/account_move_batch_validate/test/batch_validate_then_unmark.yml index adf395107..2c71c65d7 100644 --- a/account_move_batch_validate/test/batch_validate_then_unmark.yml +++ b/account_move_batch_validate/test/batch_validate_then_unmark.yml @@ -18,27 +18,51 @@ - I create a wizard with a long ETA - - !record {model: account.move.marker, id: wiz_marker2}: + !record {model: validate.account.move, id: wiz_marker2}: action: mark eta: 10000 +- + I set the period and the journal on the wizard +- + !python {model: validate.account.move}: | + move = self.pool['account.move'].browse(cr, uid, ref('move2'), + context=context) + journal_ids = [(6, 0, [move.journal_id.id])] + period_ids = [(6, 0, [move.period_id.id])] + vals = {'journal_ids': journal_ids, + 'period_ids': period_ids, + } + self.write(cr, uid, ref('wiz_marker2'), vals, context=context) - I run the wizard - - !python {model: account.move.marker}: | + !python {model: validate.account.move}: | context['automated_test_execute_now'] = True - self.button_mark( + self.validate_move( 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}: + !record {model: validate.account.move, id: wiz_unmarker3}: action: unmark +- + I set the period and the journal on the wizard +- + !python {model: validate.account.move}: | + move = self.pool['account.move'].browse(cr, uid, ref('move2'), + context=context) + journal_ids = [(6, 0, [move.journal_id.id])] + period_ids = [(6, 0, [move.period_id.id])] + vals = {'journal_ids': journal_ids, + 'period_ids': period_ids, + } + self.write(cr, uid, ref('wiz_unmarker3'), vals, context=context) - I run the wizard - - !python {model: account.move.marker}: | - self.button_mark( + !python {model: validate.account.move}: | + self.validate_move( cr, uid, [ref('wiz_unmarker3')], context=context ) - diff --git a/account_move_batch_validate/wizard/move_marker.py b/account_move_batch_validate/wizard/move_marker.py index 496faccbb..010726feb 100644 --- a/account_move_batch_validate/wizard/move_marker.py +++ b/account_move_batch_validate/wizard/move_marker.py @@ -25,52 +25,53 @@ from openerp.addons.connector.session import ConnectorSession from openerp.addons.connector.queue.job import job -class AccountMoveMarker(orm.TransientModel): +class ValidateAccountMove(orm.TransientModel): """Wizard to mark account moves for batch posting.""" - _name = "account.move.marker" - _inherit = "account.common.report" - _description = "Mark Journal Items for batch posting" + _inherit = "validate.account.move" _columns = { - 'action': fields.selection([ - ('mark', 'Mark for posting'), - ('unmark', 'Unmark for posting'), - ], "Action", required=True), + 'action': fields.selection([('mark', 'Mark for posting'), + ('unmark', 'Unmark for posting')], + "Action", required=True), 'eta': fields.integer('Seconds to wait before starting the jobs'), - 'journal_ids': fields.many2many('account.journal', - 'account_post_journal_rel', - 'wiz_id', 'journal_id', 'Journals', - required=True), + 'asynchronous': fields.boolean('Use asynchronous validation'), } _defaults = { 'action': 'mark', - 'journal_ids': [], + 'asynchronous': True, } - def button_mark(self, cr, uid, ids, context=None): + def validate_move(self, cr, uid, ids, context=None): """Create a single job that will create one job per move. Return action. """ session = ConnectorSession(cr, uid, context=context) - for wizard_id in ids: - # to find out what _classic_write does, read the documentation. - wizard_data = self.read(cr, uid, wizard_id, context=context, - load='_classic_write') - wizard_data.pop('id') - if wizard_data.get('journal_ids'): - journals_ids_vals = [(6, False, - wizard_data.get('journal_ids'))] - wizard_data['journal_ids'] = journals_ids_vals + wizard_id = ids[0] + # to find out what _classic_write does, read the documentation. + wizard_data = self.read(cr, uid, wizard_id, context=context, + load='_classic_write') + if not wizard_data.get('asynchronous'): + return super(ValidateAccountMove, self)\ + .validate_move(cr, uid, ids, context=context) + wizard_data.pop('id') + if wizard_data.get('journal_ids'): + journals_ids_vals = [(6, False, + wizard_data.get('journal_ids'))] + wizard_data['journal_ids'] = journals_ids_vals + if wizard_data.get('period_ids'): + periods_ids_vals = [(6, False, + wizard_data.get('period_ids'))] + wizard_data['period_ids'] = periods_ids_vals - if context.get('automated_test_execute_now'): - process_wizard(session, self._name, wizard_data) - else: - process_wizard.delay(session, self._name, wizard_data) + if context.get('automated_test_execute_now'): + process_wizard(session, self._name, wizard_data) + else: + process_wizard.delay(session, self._name, wizard_data) return {'type': 'ir.actions.act_window_close'} @@ -80,34 +81,11 @@ class AccountMoveMarker(orm.TransientModel): move_obj = self.pool['account.move'] - domain = [('state', '=', 'draft')] - - if wiz.filter == 'filter_period': - period_pool = self.pool['account.period'] - period_ids = period_pool.search(cr, uid, [ - ('date_start', '>=', wiz.period_from.date_start), - ('date_stop', '<=', wiz.period_to.date_stop), - ], context=context) - - domain.append(( - 'period_id', - 'in', - period_ids - )) - elif wiz.filter == 'filter_date': - domain += [ - ('date', '>=', wiz.date_from), - ('date', '<=', wiz.date_to), - ] - - 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) + domain = [('state', '=', 'draft'), + ('journal_id', 'in', wiz.journal_ids.ids), + ('period_id', 'in', wiz.period_ids.ids)] + move_ids = move_obj.search(cr, uid, domain, order='date', + context=context) if wiz.action == 'mark': move_obj.mark_for_posting(cr, uid, move_ids, eta=wiz.eta, diff --git a/account_move_batch_validate/wizard/move_marker_view.xml b/account_move_batch_validate/wizard/move_marker_view.xml index 3f1b0ab51..4a4775b1b 100644 --- a/account_move_batch_validate/wizard/move_marker_view.xml +++ b/account_move_batch_validate/wizard/move_marker_view.xml @@ -2,58 +2,22 @@ - - Mark Jornal Items for Batch Posting - account.move.marker + + Post Journal Entries + validate.account.move + -
-
- - Mark Jornal Items for Batch Posting - ir.actions.act_window - account.move.marker - form - form - new - - - - Mark Journal Items for Batch Posting - + Post Journal Entries