Merge lp:~extra-addons-commiter/e-commerce-addons/7.0-sale-exceptions-migr into lp:~extra-addons-commiter/e-commerce-addons/7.0
- 7.0-sale-exceptions-migr
- Merge into 7.0
Status: | Merged |
---|---|
Merged at revision: | 284 |
Proposed branch: | lp:~extra-addons-commiter/e-commerce-addons/7.0-sale-exceptions-migr |
Merge into: | lp:~extra-addons-commiter/e-commerce-addons/7.0 |
Diff against target: |
790 lines (+473/-92) 8 files modified
sale_exceptions/__init__.py (+2/-2) sale_exceptions/i18n/fr.po (+177/-0) sale_exceptions/i18n/sale_exceptions.pot (+177/-0) sale_exceptions/sale.py (+79/-51) sale_exceptions/sale_view.xml (+6/-10) sale_exceptions/wizard/__init__.py (+2/-1) sale_exceptions/wizard/sale_exception_confirm.py (+27/-20) sale_exceptions/wizard/sale_exception_confirm_view.xml (+3/-8) |
To merge this branch: | bzr merge lp:~extra-addons-commiter/e-commerce-addons/7.0-sale-exceptions-migr |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Sébastien BEAU - http://www.akretion.com | code review | Approve | |
Nicolas Bessi - Camptocamp (community) | code review + functional tests | Approve | |
Review via email: mp+175571@code.launchpad.net |
Commit message
[MIGR] migration of sale_exceptions for OpenERP 7
Description of the change
Migration of the module 'sale_exceptions' for OpenERP V7.
* removed / replaced deprecated things
* pep8
* improved a bit the views
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote : | # |
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote : | # |
Hello,
Thanks for the port:
Not in diff but it would be nice to use explicit import in __init__.py
Pylint just warn me about this line:
assert len(sale_id) == 1, "Only 1 ID accepted, received %r" % ids
ids does not exist in default_get of sale.exception.
Except that It seems good to me.
I also tested module in a functional way is works fine.
- 294. By Guewen Baconnier @ Camptocamp
-
[FIX] use absolute import
- 295. By Guewen Baconnier @ Camptocamp
-
[FIX] usage of a undeclared variable
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote : | # |
> Hello,
>
> Thanks for the port:
>
> Not in diff but it would be nice to use explicit import in __init__.py
>
> Pylint just warn me about this line:
>
> assert len(sale_id) == 1, "Only 1 ID accepted, received %r" % ids
>
> ids does not exist in default_get of sale.exception.
>
Thanks for the review.
I changed that.
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote : | # |
LGTM
- 296. By Guewen Baconnier @ Camptocamp
-
[FIX] fr_FR.po files not loaded, should be named fr.po
Sébastien BEAU - http://www.akretion.com (sebastien.beau) wrote : | # |
As usual => "Good work" the code is really cleaner.
I am ok for the merge. I will propose some other improvement this week (better pop up, extraction of an abstract module for managing exception) but I will do it after the merge of your work in the branch.
Thanks
Preview Diff
1 | === modified file 'sale_exceptions/__init__.py' |
2 | --- sale_exceptions/__init__.py 2012-02-24 09:31:32 +0000 |
3 | +++ sale_exceptions/__init__.py 2013-09-25 09:07:30 +0000 |
4 | @@ -19,7 +19,7 @@ |
5 | # |
6 | ############################################################################## |
7 | |
8 | -import sale |
9 | -import wizard |
10 | +from . import sale |
11 | +from . import wizard |
12 | # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
13 | |
14 | |
15 | === added directory 'sale_exceptions/i18n' |
16 | === added file 'sale_exceptions/i18n/fr.po' |
17 | --- sale_exceptions/i18n/fr.po 1970-01-01 00:00:00 +0000 |
18 | +++ sale_exceptions/i18n/fr.po 2013-09-25 09:07:30 +0000 |
19 | @@ -0,0 +1,177 @@ |
20 | +# Translation of OpenERP Server. |
21 | +# This file contains the translation of the following modules: |
22 | +# * sale_exceptions |
23 | +# |
24 | +msgid "" |
25 | +msgstr "" |
26 | +"Project-Id-Version: OpenERP Server 7.0\n" |
27 | +"Report-Msgid-Bugs-To: \n" |
28 | +"POT-Creation-Date: 2013-05-02 06:57+0000\n" |
29 | +"PO-Revision-Date: 2013-05-02 06:57+0000\n" |
30 | +"Last-Translator: <>\n" |
31 | +"Language-Team: \n" |
32 | +"MIME-Version: 1.0\n" |
33 | +"Content-Type: text/plain; charset=UTF-8\n" |
34 | +"Content-Transfer-Encoding: \n" |
35 | +"Plural-Forms: \n" |
36 | + |
37 | +#. module: sale_exceptions |
38 | +#: model:ir.model,name:sale_exceptions.model_sale_exception_confirm |
39 | +msgid "sale.exception.confirm" |
40 | +msgstr "" |
41 | + |
42 | +#. module: sale_exceptions |
43 | +#: selection:sale.exception,model:0 |
44 | +msgid "Sale Order Line" |
45 | +msgstr "Ligne de commande" |
46 | + |
47 | +#. module: sale_exceptions |
48 | +#: field:sale.exception,model:0 |
49 | +msgid "Apply on" |
50 | +msgstr "Appliquer sur" |
51 | + |
52 | +#. module: sale_exceptions |
53 | +#: model:sale.exception,name:sale_exceptions.excep_no_stock |
54 | +msgid "Not Enough Virtual Stock" |
55 | +msgstr "Pas assez de quantité de stock prévue" |
56 | + |
57 | +#. module: sale_exceptions |
58 | +#: field:sale.exception,description:0 |
59 | +msgid "Description" |
60 | +msgstr "Description" |
61 | + |
62 | +#. module: sale_exceptions |
63 | +#: help:sale.exception,sequence:0 |
64 | +msgid "Gives the sequence order when applying the test" |
65 | +msgstr "Définit l'ordre d'application des contrôles" |
66 | + |
67 | +#. module: sale_exceptions |
68 | +#: view:sale.exception.confirm:0 |
69 | +msgid "Sale Exceptions On Sale Order" |
70 | +msgstr "Restrictions sur la commande" |
71 | + |
72 | +#. module: sale_exceptions |
73 | +#: field:sale.exception.confirm,exception_ids:0 |
74 | +msgid "Exceptions to resolve" |
75 | +msgstr "Restrictions à résoudre" |
76 | + |
77 | +#. module: sale_exceptions |
78 | +#: view:sale.exception.confirm:0 |
79 | +msgid "_Ok" |
80 | +msgstr "_Ok" |
81 | + |
82 | +#. module: sale_exceptions |
83 | +#: view:sale.exception:0 |
84 | +#: view:sale.exception.confirm:0 |
85 | +msgid "Sale Exception" |
86 | +msgstr "Restriction de vente" |
87 | + |
88 | +#. module: sale_exceptions |
89 | +#: view:sale.order:0 |
90 | +msgid "TO FIX" |
91 | +msgstr "A CORRIGER" |
92 | + |
93 | +#. module: sale_exceptions |
94 | +#: help:sale.exception,code:0 |
95 | +msgid "Python code executed to check if the exception apply or not. The code must apply block = True to apply the exception." |
96 | +msgstr "Code Python exécuté pour déterminer si la restriction s'applique. The bloc de code doit retourner block = True pour appliquer la restriction." |
97 | + |
98 | +#. module: sale_exceptions |
99 | +#: view:sale.order:0 |
100 | +msgid "Exception" |
101 | +msgstr "Restriction" |
102 | + |
103 | +#. module: sale_exceptions |
104 | +#: view:sale.order:0 |
105 | +msgid "Error:" |
106 | +msgstr "Erreur :" |
107 | + |
108 | +#. module: sale_exceptions |
109 | +#: selection:sale.exception,model:0 |
110 | +msgid "Sale Order" |
111 | +msgstr "Bon de commande" |
112 | + |
113 | +#. module: sale_exceptions |
114 | +#: field:sale.exception.confirm,sale_id:0 |
115 | +msgid "Sale" |
116 | +msgstr "Commande" |
117 | + |
118 | +#. module: sale_exceptions |
119 | +#: field:sale.exception,active:0 |
120 | +msgid "Active" |
121 | +msgstr "Actif" |
122 | + |
123 | +#. module: sale_exceptions |
124 | +#: field:sale.exception,name:0 |
125 | +msgid "Exception Name" |
126 | +msgstr "Nom de la restriction" |
127 | + |
128 | +#. module: sale_exceptions |
129 | +#: field:sale.order,exceptions_ids:0 |
130 | +msgid "Exceptions" |
131 | +msgstr "Restrictions" |
132 | + |
133 | +#. module: sale_exceptions |
134 | +#: model:ir.actions.act_window,name:sale_exceptions.action_sale_exception_confirm |
135 | +#: model:ir.model,name:sale_exceptions.model_sale_exception |
136 | +#: view:sale.exception.confirm:0 |
137 | +msgid "Sale Exceptions" |
138 | +msgstr "Restrictions de vente" |
139 | + |
140 | +#. module: sale_exceptions |
141 | +#: model:ir.actions.act_window,name:sale_exceptions.action_sale_test_tree |
142 | +#: model:ir.ui.menu,name:sale_exceptions.menu_sale_test |
143 | +msgid "Exception Rules" |
144 | +msgstr "Règles de restriction" |
145 | + |
146 | +#. module: sale_exceptions |
147 | +#: model:ir.model,name:sale_exceptions.model_sale_order |
148 | +msgid "Sales Order" |
149 | +msgstr "Bon de commande" |
150 | + |
151 | +#. module: sale_exceptions |
152 | +#: field:sale.exception,sequence:0 |
153 | +msgid "Sequence" |
154 | +msgstr "Séquence" |
155 | + |
156 | +#. module: sale_exceptions |
157 | +#: field:sale.exception,code:0 |
158 | +msgid "Python Code" |
159 | +msgstr "Code Python" |
160 | + |
161 | +#. module: sale_exceptions |
162 | +#: view:sale.order:0 |
163 | +msgid "Sales" |
164 | +msgstr "Bons de commande" |
165 | + |
166 | +#. module: sale_exceptions |
167 | +#: model:sale.exception,name:sale_exceptions.excep_no_zip |
168 | +msgid "No ZIP code on destination" |
169 | +msgstr "Code postal manquant sur la destination" |
170 | + |
171 | +#. module: sale_exceptions |
172 | +#: view:sale.exception:0 |
173 | +msgid "Sale Exception Setup" |
174 | +msgstr "Configuration des restrictions de vente" |
175 | + |
176 | +#. module: sale_exceptions |
177 | +#: view:sale.exception:0 |
178 | +msgid "Affected Sales Orders" |
179 | +msgstr "Bons de commande affectés" |
180 | + |
181 | +#. module: sale_exceptions |
182 | +#: field:sale.exception,sale_order_ids:0 |
183 | +msgid "Sale Orders" |
184 | +msgstr "Bons de commande" |
185 | + |
186 | +#. module: sale_exceptions |
187 | +#: field:sale.exception.confirm,ignore:0 |
188 | +#: field:sale.order,ignore_exceptions:0 |
189 | +msgid "Ignore Exceptions" |
190 | +msgstr "Ignorer la restriction" |
191 | + |
192 | +#. module: sale_exceptions |
193 | +#: field:sale.order,main_exception_id:0 |
194 | +msgid "Main Exception" |
195 | +msgstr "Restriction principale" |
196 | + |
197 | |
198 | === added file 'sale_exceptions/i18n/sale_exceptions.pot' |
199 | --- sale_exceptions/i18n/sale_exceptions.pot 1970-01-01 00:00:00 +0000 |
200 | +++ sale_exceptions/i18n/sale_exceptions.pot 2013-09-25 09:07:30 +0000 |
201 | @@ -0,0 +1,177 @@ |
202 | +# Translation of OpenERP Server. |
203 | +# This file contains the translation of the following modules: |
204 | +# * sale_exceptions |
205 | +# |
206 | +msgid "" |
207 | +msgstr "" |
208 | +"Project-Id-Version: OpenERP Server 7.0\n" |
209 | +"Report-Msgid-Bugs-To: \n" |
210 | +"POT-Creation-Date: 2013-05-02 06:57+0000\n" |
211 | +"PO-Revision-Date: 2013-05-02 06:57+0000\n" |
212 | +"Last-Translator: <>\n" |
213 | +"Language-Team: \n" |
214 | +"MIME-Version: 1.0\n" |
215 | +"Content-Type: text/plain; charset=UTF-8\n" |
216 | +"Content-Transfer-Encoding: \n" |
217 | +"Plural-Forms: \n" |
218 | + |
219 | +#. module: sale_exceptions |
220 | +#: model:ir.model,name:sale_exceptions.model_sale_exception_confirm |
221 | +msgid "sale.exception.confirm" |
222 | +msgstr "" |
223 | + |
224 | +#. module: sale_exceptions |
225 | +#: selection:sale.exception,model:0 |
226 | +msgid "Sale Order Line" |
227 | +msgstr "" |
228 | + |
229 | +#. module: sale_exceptions |
230 | +#: field:sale.exception,model:0 |
231 | +msgid "Apply on" |
232 | +msgstr "" |
233 | + |
234 | +#. module: sale_exceptions |
235 | +#: model:sale.exception,name:sale_exceptions.excep_no_stock |
236 | +msgid "Not Enough Virtual Stock" |
237 | +msgstr "" |
238 | + |
239 | +#. module: sale_exceptions |
240 | +#: field:sale.exception,description:0 |
241 | +msgid "Description" |
242 | +msgstr "" |
243 | + |
244 | +#. module: sale_exceptions |
245 | +#: help:sale.exception,sequence:0 |
246 | +msgid "Gives the sequence order when applying the test" |
247 | +msgstr "" |
248 | + |
249 | +#. module: sale_exceptions |
250 | +#: view:sale.exception.confirm:0 |
251 | +msgid "Sale Exceptions On Sale Order" |
252 | +msgstr "" |
253 | + |
254 | +#. module: sale_exceptions |
255 | +#: field:sale.exception.confirm,exception_ids:0 |
256 | +msgid "Exceptions to resolve" |
257 | +msgstr "" |
258 | + |
259 | +#. module: sale_exceptions |
260 | +#: view:sale.exception.confirm:0 |
261 | +msgid "_Ok" |
262 | +msgstr "" |
263 | + |
264 | +#. module: sale_exceptions |
265 | +#: view:sale.exception:0 |
266 | +#: view:sale.exception.confirm:0 |
267 | +msgid "Sale Exception" |
268 | +msgstr "" |
269 | + |
270 | +#. module: sale_exceptions |
271 | +#: view:sale.order:0 |
272 | +msgid "TO FIX" |
273 | +msgstr "" |
274 | + |
275 | +#. module: sale_exceptions |
276 | +#: help:sale.exception,code:0 |
277 | +msgid "Python code executed to check if the exception apply or not. The code must apply block = True to apply the exception." |
278 | +msgstr "" |
279 | + |
280 | +#. module: sale_exceptions |
281 | +#: view:sale.order:0 |
282 | +msgid "Exception" |
283 | +msgstr "" |
284 | + |
285 | +#. module: sale_exceptions |
286 | +#: view:sale.order:0 |
287 | +msgid "Error:" |
288 | +msgstr "" |
289 | + |
290 | +#. module: sale_exceptions |
291 | +#: selection:sale.exception,model:0 |
292 | +msgid "Sale Order" |
293 | +msgstr "" |
294 | + |
295 | +#. module: sale_exceptions |
296 | +#: field:sale.exception.confirm,sale_id:0 |
297 | +msgid "Sale" |
298 | +msgstr "" |
299 | + |
300 | +#. module: sale_exceptions |
301 | +#: field:sale.exception,active:0 |
302 | +msgid "Active" |
303 | +msgstr "" |
304 | + |
305 | +#. module: sale_exceptions |
306 | +#: field:sale.exception,name:0 |
307 | +msgid "Exception Name" |
308 | +msgstr "" |
309 | + |
310 | +#. module: sale_exceptions |
311 | +#: field:sale.order,exceptions_ids:0 |
312 | +msgid "Exceptions" |
313 | +msgstr "" |
314 | + |
315 | +#. module: sale_exceptions |
316 | +#: model:ir.actions.act_window,name:sale_exceptions.action_sale_exception_confirm |
317 | +#: model:ir.model,name:sale_exceptions.model_sale_exception |
318 | +#: view:sale.exception.confirm:0 |
319 | +msgid "Sale Exceptions" |
320 | +msgstr "" |
321 | + |
322 | +#. module: sale_exceptions |
323 | +#: model:ir.actions.act_window,name:sale_exceptions.action_sale_test_tree |
324 | +#: model:ir.ui.menu,name:sale_exceptions.menu_sale_test |
325 | +msgid "Exception Rules" |
326 | +msgstr "" |
327 | + |
328 | +#. module: sale_exceptions |
329 | +#: model:ir.model,name:sale_exceptions.model_sale_order |
330 | +msgid "Sales Order" |
331 | +msgstr "" |
332 | + |
333 | +#. module: sale_exceptions |
334 | +#: field:sale.exception,sequence:0 |
335 | +msgid "Sequence" |
336 | +msgstr "" |
337 | + |
338 | +#. module: sale_exceptions |
339 | +#: field:sale.exception,code:0 |
340 | +msgid "Python Code" |
341 | +msgstr "" |
342 | + |
343 | +#. module: sale_exceptions |
344 | +#: view:sale.order:0 |
345 | +msgid "Sales" |
346 | +msgstr "" |
347 | + |
348 | +#. module: sale_exceptions |
349 | +#: model:sale.exception,name:sale_exceptions.excep_no_zip |
350 | +msgid "No ZIP code on destination" |
351 | +msgstr "" |
352 | + |
353 | +#. module: sale_exceptions |
354 | +#: view:sale.exception:0 |
355 | +msgid "Sale Exception Setup" |
356 | +msgstr "" |
357 | + |
358 | +#. module: sale_exceptions |
359 | +#: view:sale.exception:0 |
360 | +msgid "Affected Sales Orders" |
361 | +msgstr "" |
362 | + |
363 | +#. module: sale_exceptions |
364 | +#: field:sale.exception,sale_order_ids:0 |
365 | +msgid "Sale Orders" |
366 | +msgstr "" |
367 | + |
368 | +#. module: sale_exceptions |
369 | +#: field:sale.exception.confirm,ignore:0 |
370 | +#: field:sale.order,ignore_exceptions:0 |
371 | +msgid "Ignore Exceptions" |
372 | +msgstr "" |
373 | + |
374 | +#. module: sale_exceptions |
375 | +#: field:sale.order,main_exception_id:0 |
376 | +msgid "Main Exception" |
377 | +msgstr "" |
378 | + |
379 | |
380 | === modified file 'sale_exceptions/sale.py' |
381 | --- sale_exceptions/sale.py 2012-12-26 13:05:09 +0000 |
382 | +++ sale_exceptions/sale.py 2013-09-25 09:07:30 +0000 |
383 | @@ -22,32 +22,35 @@ |
384 | ############################################################################## |
385 | |
386 | import time |
387 | -import netsvc |
388 | - |
389 | -from openerp.osv.orm import Model |
390 | -from openerp.osv import fields |
391 | -from openerp.osv.osv import except_osv |
392 | -from tools.safe_eval import safe_eval as eval |
393 | -from tools.translate import _ |
394 | - |
395 | -class sale_exception(Model): |
396 | + |
397 | +from openerp.osv import orm, fields |
398 | +from openerp.tools.safe_eval import safe_eval |
399 | +from openerp.tools.translate import _ |
400 | + |
401 | + |
402 | +class sale_exception(orm.Model): |
403 | _name = "sale.exception" |
404 | _description = "Sale Exceptions" |
405 | - _order="active desc, sequence asc" |
406 | + _order = "active desc, sequence asc" |
407 | _columns = { |
408 | - 'name': fields.char('Exception Name', size=64, required=True, translate=True), |
409 | + 'name': fields.char('Exception Name', required=True, translate=True), |
410 | 'description': fields.text('Description', translate=True), |
411 | - 'sequence': fields.integer('Sequence', help="Gives the sequence order when applying the test"), |
412 | + 'sequence': fields.integer( |
413 | + 'Sequence', |
414 | + help="Gives the sequence order when applying the test"), |
415 | 'model': fields.selection([('sale.order', 'Sale Order'), |
416 | ('sale.order.line', 'Sale Order Line')], |
417 | string='Apply on', required=True), |
418 | 'active': fields.boolean('Active'), |
419 | - 'code': fields.text('Python Code', |
420 | - help="Python code executed to check if the exception apply or not. " \ |
421 | - "The code must apply block = True to apply the exception."), |
422 | - 'sale_order_ids': fields.many2many('sale.order', 'sale_order_exception_rel', |
423 | - 'exception_id', 'sale_order_id', |
424 | - string='Sale Orders', readonly=True), |
425 | + 'code': fields.text( |
426 | + 'Python Code', |
427 | + help="Python code executed to check if the exception apply or not. " \ |
428 | + "The code must apply block = True to apply the exception."), |
429 | + 'sale_order_ids': fields.many2many( |
430 | + 'sale.order', |
431 | + 'sale_order_exception_rel', 'exception_id', 'sale_order_id', |
432 | + string='Sale Orders', |
433 | + readonly=True), |
434 | } |
435 | |
436 | _defaults = { |
437 | @@ -64,7 +67,8 @@ |
438 | """ |
439 | } |
440 | |
441 | -class sale_order(Model): |
442 | + |
443 | +class sale_order(orm.Model): |
444 | _inherit = "sale.order" |
445 | |
446 | _order = 'main_exception_id asc, date_order desc, name desc' |
447 | @@ -79,25 +83,30 @@ |
448 | return res |
449 | |
450 | _columns = { |
451 | - 'main_exception_id': fields.function(_get_main_error, |
452 | - type='many2one', |
453 | - relation="sale.exception", |
454 | - string='Main Exception', |
455 | - store={ |
456 | - 'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['exceptions_ids', 'state'], 10), |
457 | - }), |
458 | - 'exceptions_ids': fields.many2many('sale.exception', 'sale_order_exception_rel', |
459 | - 'sale_order_id', 'exception_id', |
460 | - string='Exceptions'), |
461 | + 'main_exception_id': fields.function( |
462 | + _get_main_error, |
463 | + type='many2one', |
464 | + relation="sale.exception", |
465 | + string='Main Exception', |
466 | + store={ |
467 | + 'sale.order': (lambda self, cr, uid, ids, c=None: ids, |
468 | + ['exceptions_ids', 'state'], 10), |
469 | + }), |
470 | + 'exceptions_ids': fields.many2many( |
471 | + 'sale.exception', |
472 | + 'sale_order_exception_rel', 'sale_order_id', 'exception_id', |
473 | + string='Exceptions'), |
474 | 'ignore_exceptions': fields.boolean('Ignore Exceptions'), |
475 | } |
476 | |
477 | def test_all_draft_orders(self, cr, uid, context=None): |
478 | - ids = self.search(cr, uid, [('state', '=', 'draft')]) |
479 | - self.test_exceptions(cr, uid, ids) |
480 | + ids = self.search(cr, uid, [('state', '=', 'draft')], context=context) |
481 | + self.test_exceptions(cr, uid, ids, context=context) |
482 | return True |
483 | |
484 | def _popup_exceptions(self, cr, uid, order_id, context=None): |
485 | + if context is None: |
486 | + context = {} |
487 | model_data_obj = self.pool.get('ir.model.data') |
488 | list_obj = self.pool.get('sale.exception.confirm') |
489 | ctx = context.copy() |
490 | @@ -107,7 +116,7 @@ |
491 | view_id = model_data_obj.get_object_reference( |
492 | cr, uid, 'sale_exceptions', 'view_sale_exception_confirm')[1] |
493 | action = { |
494 | - 'name': _("Exceptions On Sale Order"), |
495 | + 'name': _("Blocked in draft due to exceptions"), |
496 | 'type': 'ir.actions.act_window', |
497 | 'view_type': 'form', |
498 | 'view_mode': 'form', |
499 | @@ -124,7 +133,8 @@ |
500 | if exception_ids: |
501 | return self._popup_exceptions(cr, uid, ids[0], context=context) |
502 | else: |
503 | - return super(sale_order, self).action_button_confirm(cr, uid, ids, context=context) |
504 | + return super(sale_order, self).action_button_confirm(cr, uid, ids, |
505 | + context=context) |
506 | |
507 | def test_exceptions(self, cr, uid, ids, context=None): |
508 | """ |
509 | @@ -137,28 +147,40 @@ |
510 | |
511 | def detect_exceptions(self, cr, uid, ids, context=None): |
512 | exception_obj = self.pool.get('sale.exception') |
513 | - order_exception_ids = exception_obj.search(cr, uid, |
514 | - [('model', '=', 'sale.order')], context=context) |
515 | - line_exception_ids = exception_obj.search(cr, uid, |
516 | - [('model', '=', 'sale.order.line')], context=context) |
517 | + order_exception_ids = exception_obj.search( |
518 | + cr, uid, |
519 | + [('model', '=', 'sale.order')], |
520 | + context=context) |
521 | + line_exception_ids = exception_obj.search( |
522 | + cr, uid, |
523 | + [('model', '=', 'sale.order.line')], |
524 | + context=context) |
525 | |
526 | - order_exceptions = exception_obj.browse(cr, uid, order_exception_ids, context=context) |
527 | - line_exceptions = exception_obj.browse(cr, uid, line_exception_ids, context=context) |
528 | + order_exceptions = exception_obj.browse(cr, uid, order_exception_ids, |
529 | + context=context) |
530 | + line_exceptions = exception_obj.browse(cr, uid, line_exception_ids, |
531 | + context=context) |
532 | |
533 | exception_ids = False |
534 | - for order in self.browse(cr, uid, ids): |
535 | + for order in self.browse(cr, uid, ids, context=context): |
536 | if order.ignore_exceptions: |
537 | continue |
538 | - exception_ids = self._detect_exceptions(cr, uid, order, |
539 | - order_exceptions, line_exceptions, context=context) |
540 | + exception_ids = self._detect_exceptions(cr, uid, |
541 | + order, |
542 | + order_exceptions, |
543 | + line_exceptions, |
544 | + context=context) |
545 | |
546 | - self.write(cr, uid, [order.id], {'exceptions_ids': [(6, 0, exception_ids)]}) |
547 | + self.write(cr, uid, [order.id], |
548 | + {'exceptions_ids': [(6, 0, exception_ids)]}, |
549 | + context=context) |
550 | return exception_ids |
551 | |
552 | def _exception_rule_eval_context(self, cr, uid, obj_name, obj, context=None): |
553 | if context is None: |
554 | context = {} |
555 | |
556 | + user = self.pool.get('res.users').browse(cr, uid, uid, context=context) |
557 | return {obj_name: obj, |
558 | 'self': self.pool.get(obj._name), |
559 | 'object': obj, |
560 | @@ -166,24 +188,29 @@ |
561 | 'pool': self.pool, |
562 | 'cr': cr, |
563 | 'uid': uid, |
564 | - 'user': self.pool.get('res.users').browse(cr, uid, uid), |
565 | + 'user': user, |
566 | 'time': time, |
567 | # copy context to prevent side-effects of eval |
568 | - 'context': dict(context),} |
569 | + 'context': context.copy()} |
570 | |
571 | def _rule_eval(self, cr, uid, rule, obj_name, obj, context): |
572 | expr = rule.code |
573 | space = self._exception_rule_eval_context(cr, uid, obj_name, obj, |
574 | context=context) |
575 | try: |
576 | - eval(expr, space, |
577 | - mode='exec', nocopy=True) # nocopy allows to return 'result' |
578 | + safe_eval(expr, |
579 | + space, |
580 | + mode='exec', |
581 | + nocopy=True) # nocopy allows to return 'result' |
582 | except Exception, e: |
583 | - raise except_osv(_('Error'), _('Error when evaluating the sale exception rule :\n %s \n(%s)') % |
584 | - (rule.name, e)) |
585 | + raise orm.except_orm( |
586 | + _('Error'), |
587 | + _('Error when evaluating the sale exception ' |
588 | + 'rule:\n %s \n(%s)') % (rule.name, e)) |
589 | return space.get('failed', False) |
590 | |
591 | - def _detect_exceptions(self, cr, uid, order, order_exceptions, line_exceptions, context=None): |
592 | + def _detect_exceptions(self, cr, uid, order, order_exceptions, |
593 | + line_exceptions, context=None): |
594 | exception_ids = [] |
595 | for rule in order_exceptions: |
596 | if self._rule_eval(cr, uid, rule, 'order', order, context): |
597 | @@ -192,8 +219,9 @@ |
598 | for order_line in order.order_line: |
599 | for rule in line_exceptions: |
600 | if rule.id in exception_ids: |
601 | - continue # we do not matter if the exception as already been |
602 | + # we do not matter if the exception as already been |
603 | # found for an order line of this order |
604 | + continue |
605 | if self._rule_eval(cr, uid, rule, 'line', order_line, context): |
606 | exception_ids.append(rule.id) |
607 | |
608 | |
609 | === modified file 'sale_exceptions/sale_view.xml' |
610 | --- sale_exceptions/sale_view.xml 2012-12-26 13:19:13 +0000 |
611 | +++ sale_exceptions/sale_view.xml 2013-09-25 09:07:30 +0000 |
612 | @@ -5,7 +5,6 @@ |
613 | <record id="view_sale_exception_tree" model="ir.ui.view"> |
614 | <field name="name">sale.exception.tree</field> |
615 | <field name="model">sale.exception</field> |
616 | - <field name="type">tree</field> |
617 | <field name="arch" type="xml"> |
618 | <tree string="Sale Exception"> |
619 | <field name="active"/> |
620 | @@ -20,7 +19,6 @@ |
621 | <record id="view_sale_exception_form" model="ir.ui.view"> |
622 | <field name="name">sale.exception.form</field> |
623 | <field name="model">sale.exception</field> |
624 | - <field name="type">form</field> |
625 | <field name="arch" type="xml"> |
626 | <form string="Sale Exception Setup"> |
627 | <group colspan="4" col="2"> |
628 | @@ -59,13 +57,14 @@ |
629 | <record id="view_order_form" model="ir.ui.view"> |
630 | <field name="name">sale_exceptions.view_order_form</field> |
631 | <field name="model">sale.order</field> |
632 | - <field name="type">form</field> |
633 | - <field name="priority">100</field> |
634 | <field name="inherit_id" ref="sale.view_order_form"/> |
635 | <field name="arch" type="xml"> |
636 | <field name="name" position="after"> |
637 | - <field name="main_exception_id" nolabel="1" |
638 | + <group> |
639 | + <field name="main_exception_id" options='{"no_open": True}' |
640 | + class="oe_inline" string="Error:" |
641 | attrs="{'invisible':[('main_exception_id','=', False)]}"/> |
642 | + </group> |
643 | </field> |
644 | <xpath expr="//page[@string='Other Information']/group" |
645 | position="inside"> |
646 | @@ -80,7 +79,6 @@ |
647 | <record id="view_order_tree" model="ir.ui.view"> |
648 | <field name="name">sale_exceptions.view_order_tree</field> |
649 | <field name="model">sale.order</field> |
650 | - <field name="type">tree</field> |
651 | <field name="inherit_id" ref="sale.view_order_tree"/> |
652 | <field name="arch" type="xml"> |
653 | <field name="state" position="after"> |
654 | @@ -93,12 +91,10 @@ |
655 | <field name="name">sale_exceptions.view_sales_order_filter</field> |
656 | <field name="model">sale.order</field> |
657 | <field name="inherit_id" ref="sale.view_sales_order_filter" /> |
658 | - <field name="type">search</field> |
659 | - <field eval="32" name="priority"/> |
660 | <field name="arch" type="xml"> |
661 | - <filter icon="terp-check" string="Sales" position="after"> |
662 | + <filter name="sales" position="after"> |
663 | <separator orientation="vertical"/> |
664 | - <filter icon="terp-emblem-important" name="tofix" string="TO FIX" domain="[('main_exception_id','!=',False)]"/> |
665 | + <filter icon="terp-emblem-important" name="tofix" string="Blocked in draft" domain="[('main_exception_id','!=',False)]"/> |
666 | </filter> |
667 | </field> |
668 | </record> |
669 | |
670 | === modified file 'sale_exceptions/wizard/__init__.py' |
671 | --- sale_exceptions/wizard/__init__.py 2012-02-24 09:31:32 +0000 |
672 | +++ sale_exceptions/wizard/__init__.py 2013-09-25 09:07:30 +0000 |
673 | @@ -1,1 +1,2 @@ |
674 | -import sale_exception_confirm |
675 | +# -*- coding: utf-8 -*- |
676 | +from . import sale_exception_confirm |
677 | |
678 | === modified file 'sale_exceptions/wizard/sale_exception_confirm.py' |
679 | --- sale_exceptions/wizard/sale_exception_confirm.py 2012-05-16 12:53:59 +0000 |
680 | +++ sale_exceptions/wizard/sale_exception_confirm.py 2013-09-25 09:07:30 +0000 |
681 | @@ -1,4 +1,4 @@ |
682 | -# -*- encoding: utf-8 -*- |
683 | +# -*- coding: utf-8 -*- |
684 | ############################################################################## |
685 | # |
686 | # Copyright Camptocamp SA |
687 | @@ -19,38 +19,45 @@ |
688 | # |
689 | ############################################################################## |
690 | |
691 | -import netsvc |
692 | - |
693 | -from osv import osv, fields |
694 | - |
695 | - |
696 | -class SaleExceptionConfirm(osv.osv_memory): |
697 | +from openerp.osv import orm, fields |
698 | + |
699 | + |
700 | +class SaleExceptionConfirm(orm.TransientModel): |
701 | |
702 | _name = 'sale.exception.confirm' |
703 | |
704 | _columns = { |
705 | 'sale_id': fields.many2one('sale.order', 'Sale'), |
706 | - 'exception_ids': fields.many2many('sale.exception', string='Exceptions to resolve', readonly=True), |
707 | + 'exception_ids': fields.many2many('sale.exception', |
708 | + string='Exceptions to resolve', |
709 | + readonly=True), |
710 | 'ignore': fields.boolean('Ignore Exceptions'), |
711 | } |
712 | |
713 | def default_get(self, cr, uid, fields, context=None): |
714 | - res = super(SaleExceptionConfirm, self).default_get(cr, uid, fields, context=context) |
715 | + if context is None: |
716 | + context = {} |
717 | + res = super(SaleExceptionConfirm, self).default_get( |
718 | + cr, uid, fields, context=context) |
719 | order_obj = self.pool.get('sale.order') |
720 | - sale_id = context.get('active_id', False) |
721 | - if sale_id: |
722 | - sale = order_obj.browse(cr, uid, sale_id, context=context) |
723 | - exception_ids = [e.id for e in sale.exceptions_ids] |
724 | - res.update({'exception_ids': [(6, 0, exception_ids)]}) |
725 | - |
726 | + sale_id = context.get('active_ids') |
727 | + assert len(sale_id) == 1, "Only 1 ID accepted, got %r" % sale_id |
728 | + sale_id = sale_id[0] |
729 | + sale = order_obj.browse(cr, uid, sale_id, context=context) |
730 | + exception_ids = [e.id for e in sale.exceptions_ids] |
731 | + res.update({'exception_ids': [(6, 0, exception_ids)]}) |
732 | res.update({'sale_id': sale_id}) |
733 | return res |
734 | |
735 | def action_confirm(self, cr, uid, ids, context=None): |
736 | - form = self.browse(cr, uid, ids[0], context=context) |
737 | + if hasattr(ids, '__iter__'): |
738 | + assert len(ids) == 1, "Only 1 ID accepted, got %r" % ids |
739 | + ids = ids[0] |
740 | + form = self.browse(cr, uid, ids, context=context) |
741 | if form.ignore: |
742 | - self.pool.get('sale.order').write(cr, uid, form.sale_id.id, |
743 | - {'ignore_exceptions': True}, context=context) |
744 | + self.pool.get('sale.order').write( |
745 | + cr, uid, |
746 | + form.sale_id.id, |
747 | + {'ignore_exceptions': True}, |
748 | + context=context) |
749 | return {'type': 'ir.actions.act_window_close'} |
750 | - |
751 | -SaleExceptionConfirm() |
752 | |
753 | === modified file 'sale_exceptions/wizard/sale_exception_confirm_view.xml' |
754 | --- sale_exceptions/wizard/sale_exception_confirm_view.xml 2012-12-26 09:30:24 +0000 |
755 | +++ sale_exceptions/wizard/sale_exception_confirm_view.xml 2013-09-25 09:07:30 +0000 |
756 | @@ -5,15 +5,10 @@ |
757 | <record id="view_sale_exception_confirm" model="ir.ui.view"> |
758 | <field name="name">Sale Exceptions</field> |
759 | <field name="model">sale.exception.confirm</field> |
760 | - <field name="type">form</field> |
761 | <field name="arch" type="xml"> |
762 | - <form string="Sale Exceptions On Sale Order" version="7.0"> |
763 | + <form string="Blocked in draft due to exceptions" version="7.0"> |
764 | <group> |
765 | <field name="exception_ids" nolabel="1" colspan="4"> |
766 | - <form string="Sale Exception"> |
767 | - <field name="name" colspan="4"/> |
768 | - <field name="description" colspan="4"/> |
769 | - </form> |
770 | <tree string="Sale Exceptions"> |
771 | <field name="name"/> |
772 | <field name="description"/> |
773 | @@ -23,7 +18,7 @@ |
774 | <field name="ignore" groups='base.group_sale_manager'/> |
775 | </group> |
776 | <footer> |
777 | - <button name="action_confirm" string="_Ok" |
778 | + <button name="action_confirm" string="_Close" |
779 | colspan="1" type="object" icon="gtk-ok" /> |
780 | </footer> |
781 | </form> |
782 | @@ -31,7 +26,7 @@ |
783 | </record> |
784 | |
785 | <record id="action_sale_exception_confirm" model="ir.actions.act_window"> |
786 | - <field name="name">Sale Exceptions</field> |
787 | + <field name="name">Blocked in draft due to exceptions</field> |
788 | <field name="type">ir.actions.act_window</field> |
789 | <field name="res_model">sale.exception.confirm</field> |
790 | <field name="view_type">form</field> |
Hi,
Can I have some reviews on this one please? This will be necessary for the release of the new Magento Connector ;-)