Merge lp:~camptocamp/account-financial-tools/7.0-batch_validate-delay-delaying-second-attempt-lep into lp:~account-core-editors/account-financial-tools/7.0

Proposed by Leonardo Pistone
Status: Merged
Approved by: Yannick Vaucher @ Camptocamp
Approved revision: 165
Merged at revision: 166
Proposed branch: lp:~camptocamp/account-financial-tools/7.0-batch_validate-delay-delaying-second-attempt-lep
Merge into: lp:~account-core-editors/account-financial-tools/7.0
Diff against target: 141 lines (+53/-7)
5 files modified
account_move_batch_validate/account.py (+8/-4)
account_move_batch_validate/test/batch_validate.yml (+1/-0)
account_move_batch_validate/test/batch_validate_then_delete_move.yml (+1/-0)
account_move_batch_validate/test/batch_validate_then_unmark.yml (+1/-0)
account_move_batch_validate/wizard/move_marker.py (+42/-3)
To merge this branch: bzr merge lp:~camptocamp/account-financial-tools/7.0-batch_validate-delay-delaying-second-attempt-lep
Reviewer Review Type Date Requested Status
Alexandre Fayolle - camptocamp Approve
Frederic Clementi - Camptocamp (community) functional Approve
Nicolas Bessi - Camptocamp (community) no test, code review Approve
Guewen Baconnier @ Camptocamp code review Approve
Review via email: mp+208614@code.launchpad.net

Description of the change

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!

To post a comment you must log in.
162. By Leonardo Pistone

[imp] move_batch_validate: better job message

163. By Leonardo Pistone

[imp] account_move_batch_validate: if creating the jobs takes long, at least commit while marking moves to be validated. that way users will see the flag somewhat sooner.

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

LGTM

review: Approve (code review)
Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

This one is funny :)
LGTM

review: Approve (no test, code review)
Revision history for this message
Frederic Clementi - Camptocamp (frederic-clementi) wrote :

Test OK on customer instance.

review: Approve (functional)
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

please delete the test files (or better fix them) rather than commenting them out in __openerp__.py

review: Needs Fixing
Revision history for this message
Leonardo Pistone (lepistone) wrote :

They had to go Alexandre, as I do not know how to run all enqueued jobs synchronously, while I wait.

But one day...

(thanks to all for reviewing)

164. By Leonardo Pistone

[imp] account_move_batch_validate: with a little trick, tests are back!

Revision history for this message
Leonardo Pistone (lepistone) wrote :

Ok Alexandre, you're right: fixing those tests was not at all impossible. We're green again.

Thanks!

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

> Ok Alexandre, you're right: fixing those tests was not at all impossible.
> We're green again.
>
> Thanks!

Great!

165. By Leonardo Pistone

[merge] upstream

Revision history for this message
Leonardo Pistone (lepistone) wrote :

I merged upstream and resolved the conflicts.

Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_move_batch_validate/account.py'
2--- account_move_batch_validate/account.py 2014-02-28 10:09:38 +0000
3+++ account_move_batch_validate/account.py 2014-02-28 13:16:56 +0000
4@@ -70,7 +70,10 @@
5 ('post_job_uuid', '=', False),
6 ('state', '=', 'draft'),
7 ], context=context)
8+ name = self._name
9
10+ # maybe not creating too many dictionaries will make us a bit faster
11+ values = {'post_job_uuid': None}
12 _logger.info(
13 u'{0} jobs for posting moves have been created.'.format(
14 len(move_ids)
15@@ -78,11 +81,10 @@
16 )
17
18 for move_id in move_ids:
19- job_uuid = validate_one_move.delay(session, self._name, move_id,
20+ job_uuid = validate_one_move.delay(session, name, move_id,
21 eta=eta)
22- self.write(cr, uid, [move_id], {
23- 'post_job_uuid': job_uuid
24- })
25+ values['post_job_uuid'] = job_uuid
26+ self.write(cr, uid, [move_id], values)
27
28 def _cancel_jobs(self, cr, uid, context=None):
29 """Find moves where the mark has been removed and cancel the jobs.
30@@ -129,6 +131,8 @@
31 move_ids[start:start + BLOCK_SIZE],
32 {'to_post': True},
33 context=context)
34+ # users like to see the flag sooner rather than later
35+ cr.commit()
36 self._delay_post_marked(cr, uid, eta=eta, context=context)
37
38 def unmark_for_posting(self, cr, uid, move_ids, context=None):
39
40=== modified file 'account_move_batch_validate/test/batch_validate.yml'
41--- account_move_batch_validate/test/batch_validate.yml 2014-01-13 18:58:18 +0000
42+++ account_move_batch_validate/test/batch_validate.yml 2014-02-28 13:16:56 +0000
43@@ -24,6 +24,7 @@
44 I run the wizard
45 -
46 !python {model: account.move.marker}: |
47+ context['automated_test_execute_now'] = True
48 self.button_mark(
49 cr, uid, [ref('wiz_marker1')], context=context
50 )
51
52=== modified file 'account_move_batch_validate/test/batch_validate_then_delete_move.yml'
53--- account_move_batch_validate/test/batch_validate_then_delete_move.yml 2014-02-26 13:12:54 +0000
54+++ account_move_batch_validate/test/batch_validate_then_delete_move.yml 2014-02-28 13:16:56 +0000
55@@ -25,6 +25,7 @@
56 I run the wizard
57 -
58 !python {model: account.move.marker}: |
59+ context['automated_test_execute_now'] = True
60 self.button_mark(
61 cr, uid, [ref('wiz_marker4')], context=context
62 )
63
64=== modified file 'account_move_batch_validate/test/batch_validate_then_unmark.yml'
65--- account_move_batch_validate/test/batch_validate_then_unmark.yml 2014-01-14 12:40:39 +0000
66+++ account_move_batch_validate/test/batch_validate_then_unmark.yml 2014-02-28 13:16:56 +0000
67@@ -25,6 +25,7 @@
68 I run the wizard
69 -
70 !python {model: account.move.marker}: |
71+ context['automated_test_execute_now'] = True
72 self.button_mark(
73 cr, uid, [ref('wiz_marker2')], context=context
74 )
75
76=== modified file 'account_move_batch_validate/wizard/move_marker.py'
77--- account_move_batch_validate/wizard/move_marker.py 2014-01-14 14:33:52 +0000
78+++ account_move_batch_validate/wizard/move_marker.py 2014-02-28 13:16:56 +0000
79@@ -21,6 +21,8 @@
80 """Wizards for batch posting."""
81
82 from openerp.osv import fields, orm
83+from openerp.addons.connector.session import ConnectorSession
84+from openerp.addons.connector.queue.job import job
85
86
87 class AccountMoveMarker(orm.TransientModel):
88@@ -44,8 +46,27 @@
89 }
90
91 def button_mark(self, cr, uid, ids, context=None):
92- """Mark/unmark lines and update the queue. Return action."""
93-
94+ """Create a single job that will create one job per move.
95+
96+ Return action.
97+
98+ """
99+ session = ConnectorSession(cr, uid, context=context)
100+ for wizard_id in ids:
101+ # to find out what _classic_write does, read the documentation.
102+ wizard_data = self.read(cr, uid, wizard_id, context=context,
103+ load='_classic_write')
104+ wizard_data.pop('id')
105+
106+ if context.get('automated_test_execute_now'):
107+ process_wizard(session, self._name, wizard_data)
108+ else:
109+ process_wizard.delay(session, self._name, wizard_data)
110+
111+ return {'type': 'ir.actions.act_window_close'}
112+
113+ def process_wizard(self, cr, uid, ids, context=None):
114+ """Choose the correct list of moves to mark and then validate."""
115 for wiz in self.browse(cr, uid, ids, context=context):
116
117 move_obj = self.pool['account.move']
118@@ -86,4 +107,22 @@
119 elif wiz.action == 'unmark':
120 move_obj.unmark_for_posting(cr, uid, move_ids, context=context)
121
122- return {'type': 'ir.actions.act_window_close'}
123+
124+@job
125+def process_wizard(session, model_name, wizard_data):
126+ """Create jobs to validate Journal Entries."""
127+
128+ wiz_obj = session.pool[model_name]
129+ new_wiz_id = wiz_obj.create(
130+ session.cr,
131+ session.uid,
132+ wizard_data,
133+ session.context
134+ )
135+
136+ wiz_obj.process_wizard(
137+ session.cr,
138+ session.uid,
139+ ids=[new_wiz_id],
140+ context=session.context,
141+ )

Subscribers

People subscribed via source and target branches