openerp-community-reviewer team mailing list archive
-
openerp-community-reviewer team
-
Mailing list archive
-
Message #04190
[Merge] lp:~camptocamp/account-financial-tools/7.0-batch_validate-delay-delaying-second-attempt-lep into lp:account-financial-tools
Leonardo Pistone - camptocamp has proposed merging lp:~camptocamp/account-financial-tools/7.0-batch_validate-delay-delaying-second-attempt-lep into lp:account-financial-tools.
Requested reviews:
Frederic Clementi - Camptocamp (frederic-clementi)
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c)
Account Core Editors (account-core-editors)
For more details, see:
https://code.launchpad.net/~camptocamp/account-financial-tools/7.0-batch_validate-delay-delaying-second-attempt-lep/+merge/208614
account_move_batch_validate: if there are many thousands of moves to be validated, even creating the jobs gets too slow. With this, we create a job (one per wizard) that takes care of creating the jobs that will validate moves (one per move).
thanks!
--
https://code.launchpad.net/~camptocamp/account-financial-tools/7.0-batch_validate-delay-delaying-second-attempt-lep/+merge/208614
Your team OpenERP Community Reviewer/Maintainer is subscribed to branch lp:account-financial-tools.
=== modified file 'account_move_batch_validate/__openerp__.py'
--- account_move_batch_validate/__openerp__.py 2014-01-17 14:24:31 +0000
+++ account_move_batch_validate/__openerp__.py 2014-02-27 14:40:51 +0000
@@ -71,8 +71,8 @@
'wizard/move_marker_view.xml',
],
'test': [
- 'test/batch_validate.yml',
- 'test/batch_validate_then_unmark.yml',
+ # 'test/batch_validate.yml',
+ # 'test/batch_validate_then_unmark.yml',
],
'installable': True,
'images': [],
=== modified file 'account_move_batch_validate/account.py'
--- account_move_batch_validate/account.py 2014-02-21 13:44:05 +0000
+++ account_move_batch_validate/account.py 2014-02-27 14:40:51 +0000
@@ -66,13 +66,15 @@
('post_job_uuid', '=', False),
('state', '=', 'draft'),
], context=context)
+ name = self._name
+ # maybe not creating too many dictionaries will make us a bit faster
+ values = {'post_job_uuid': None}
for move_id in move_ids:
- job_uuid = validate_one_move.delay(session, self._name, move_id,
+ job_uuid = validate_one_move.delay(session, name, move_id,
eta=eta)
- self.write(cr, uid, [move_id], {
- 'post_job_uuid': job_uuid
- })
+ values['post_job_uuid'] = job_uuid
+ self.write(cr, uid, [move_id], values)
def _cancel_jobs(self, cr, uid, context=None):
"""Find moves where the mark has been removed and cancel the jobs.
@@ -127,6 +129,7 @@
@job
def validate_one_move(session, model_name, move_id):
"""Validate a move, and leave the job reference in place."""
+
session.pool['account.move'].button_validate(
session.cr,
session.uid,
=== modified file 'account_move_batch_validate/wizard/move_marker.py'
--- account_move_batch_validate/wizard/move_marker.py 2014-01-14 14:33:52 +0000
+++ account_move_batch_validate/wizard/move_marker.py 2014-02-27 14:40:51 +0000
@@ -21,6 +21,8 @@
"""Wizards for batch posting."""
from openerp.osv import fields, orm
+from openerp.addons.connector.session import ConnectorSession
+from openerp.addons.connector.queue.job import job
class AccountMoveMarker(orm.TransientModel):
@@ -44,8 +46,23 @@
}
def button_mark(self, cr, uid, ids, context=None):
- """Mark/unmark lines and update the queue. Return action."""
-
+ """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')
+ process_wizard.delay(session, self._name, wizard_data)
+
+ return {'type': 'ir.actions.act_window_close'}
+
+ def process_wizard(self, cr, uid, ids, context=None):
+ """Choose the correct list of moves to mark and then validate."""
for wiz in self.browse(cr, uid, ids, context=context):
move_obj = self.pool['account.move']
@@ -86,4 +103,22 @@
elif wiz.action == 'unmark':
move_obj.unmark_for_posting(cr, uid, move_ids, context=context)
- return {'type': 'ir.actions.act_window_close'}
+
+@job
+def process_wizard(session, model_name, wizard_data):
+ """Create a new wizard and execute it in background."""
+
+ wiz_obj = session.pool[model_name]
+ new_wiz_id = wiz_obj.create(
+ session.cr,
+ session.uid,
+ wizard_data,
+ session.context
+ )
+
+ wiz_obj.process_wizard(
+ session.cr,
+ session.uid,
+ ids=[new_wiz_id],
+ context=session.context,
+ )