Merge lp:~unifield-team/unifield-addons/modification-of-stock-for-shipment into lp:unifield-addons
- modification-of-stock-for-shipment
- Merge into trunk
Proposed by
Patrick Amstutz
Status: | Merged |
---|---|
Merged at revision: | 4492 |
Proposed branch: | lp:~unifield-team/unifield-addons/modification-of-stock-for-shipment |
Merge into: | lp:unifield-addons |
Diff against target: |
481 lines (+209/-98) 7 files modified
sale/sale.py (+125/-56) sale/test/invoice_on_shipped_qty.yml (+16/-13) sale/test/manual_order_policy.yml (+20/-12) sale/test/picking_order_policy.yml (+3/-1) sale/test/postpaid_order_policy.yml (+6/-2) sale/test/prepaid_order_policy.yml (+21/-10) stock/stock.py (+18/-4) |
To merge this branch: | bzr merge lp:~unifield-team/unifield-addons/modification-of-stock-for-shipment |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
UniField Dev Team | Pending | ||
Review via email: mp+76373@code.launchpad.net |
Commit message
Description of the change
ne pas oublier les tests yaml dans sale, merci.
To post a comment you must log in.
- 4494. By chloups208 <chloups208@chloups208-laptop>
-
[UF-390]one more hook for stock_picking>
action_ assign
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'sale/sale.py' |
2 | --- sale/sale.py 2011-07-07 10:50:50 +0000 |
3 | +++ sale/sale.py 2011-09-21 12:33:24 +0000 |
4 | @@ -649,14 +649,76 @@ |
5 | if notcanceled: |
6 | return False |
7 | return canceled |
8 | - |
9 | - def action_ship_create(self, cr, uid, ids, *args): |
10 | + |
11 | + def _hook_ship_create_stock_move(self, cr, uid, ids, context=None, *args, **kwargs): |
12 | + ''' |
13 | + Please copy this to your module's method also. |
14 | + This hook belongs to the action_ship_create method from sale>sale.py |
15 | + |
16 | + - allow to modify the data for stock move creation |
17 | + ''' |
18 | + move_data = kwargs['move_data'] |
19 | + return move_data |
20 | + |
21 | + def _hook_ship_create_procurement_order(self, cr, uid, ids, context=None, *args, **kwargs): |
22 | + ''' |
23 | + Please copy this to your module's method also. |
24 | + This hook belongs to the action_ship_create method from sale>sale.py |
25 | + |
26 | + - allow to modify the data for procurement order creation |
27 | + ''' |
28 | + proc_data = kwargs['proc_data'] |
29 | + return proc_data |
30 | + |
31 | + def _hook_ship_create_stock_picking(self, cr, uid, ids, context=None, *args, **kwargs): |
32 | + ''' |
33 | + Please copy this to your module's method also. |
34 | + This hook belongs to the action_ship_create method from sale>sale.py |
35 | + |
36 | + - allow to modify the data for stock picking creation |
37 | + ''' |
38 | + picking_data = kwargs['picking_data'] |
39 | + return picking_data |
40 | + |
41 | + def _hook_ship_create_execute_picking_workflow(self, cr, uid, ids, context=None, *args, **kwargs): |
42 | + ''' |
43 | + Please copy this to your module's method also. |
44 | + This hook belongs to the action_ship_create method from sale>sale.py |
45 | + |
46 | + - allow to avoid the stock picking workflow execution |
47 | + ''' |
48 | + picking_id = kwargs['picking_id'] |
49 | + return picking_id |
50 | + |
51 | + def _hook_ship_create_execute_specific_code_01(self, cr, uid, ids, context=None, *args, **kwargs): |
52 | + ''' |
53 | + Please copy this to your module's method also. |
54 | + This hook belongs to the action_ship_create method from sale>sale.py |
55 | + |
56 | + - allow to execute specific code at position 01 |
57 | + ''' |
58 | + pass |
59 | + |
60 | + def _hook_ship_create_line_condition(self, cr, uid, ids, context=None, *args, **kwargs): |
61 | + ''' |
62 | + Please copy this to your module's method also. |
63 | + This hook belongs to the action_ship_create method from sale>sale.py |
64 | + |
65 | + - allow to customize the execution condition |
66 | + ''' |
67 | + line = kwargs['line'] |
68 | + result = line.product_id and line.product_id.product_tmpl_id.type in ('product', 'consu') |
69 | + return result |
70 | + |
71 | + def action_ship_create(self, cr, uid, ids, context=None, *args): |
72 | + if context is None: |
73 | + context = {} |
74 | wf_service = netsvc.LocalService("workflow") |
75 | picking_id = False |
76 | move_obj = self.pool.get('stock.move') |
77 | proc_obj = self.pool.get('procurement.order') |
78 | company = self.pool.get('res.users').browse(cr, uid, uid).company_id |
79 | - for order in self.browse(cr, uid, ids, context={}): |
80 | + for order in self.browse(cr, uid, ids, context=context): |
81 | proc_ids = [] |
82 | output_id = order.shop_id.warehouse_id.lot_output_id.id |
83 | picking_id = False |
84 | @@ -668,63 +730,69 @@ |
85 | if line.state == 'done': |
86 | continue |
87 | move_id = False |
88 | - if line.product_id and line.product_id.product_tmpl_id.type in ('product', 'consu'): |
89 | + if self._hook_ship_create_line_condition(cr, uid, ids, context=context, line=line,): |
90 | location_id = order.shop_id.warehouse_id.lot_stock_id.id |
91 | if not picking_id: |
92 | pick_name = self.pool.get('ir.sequence').get(cr, uid, 'stock.picking.out') |
93 | - picking_id = self.pool.get('stock.picking').create(cr, uid, { |
94 | - 'name': pick_name, |
95 | - 'origin': order.name, |
96 | - 'type': 'out', |
97 | - 'state': 'auto', |
98 | - 'move_type': order.picking_policy, |
99 | - 'sale_id': order.id, |
100 | - 'address_id': order.partner_shipping_id.id, |
101 | - 'note': order.note, |
102 | - 'invoice_state': (order.order_policy=='picking' and '2binvoiced') or 'none', |
103 | - 'company_id': order.company_id.id, |
104 | - }) |
105 | - move_id = self.pool.get('stock.move').create(cr, uid, { |
106 | - 'name': line.name[:64], |
107 | - 'picking_id': picking_id, |
108 | - 'product_id': line.product_id.id, |
109 | - 'date': date_planned, |
110 | - 'date_expected': date_planned, |
111 | - 'product_qty': line.product_uom_qty, |
112 | - 'product_uom': line.product_uom.id, |
113 | - 'product_uos_qty': line.product_uos_qty, |
114 | - 'product_uos': (line.product_uos and line.product_uos.id)\ |
115 | - or line.product_uom.id, |
116 | - 'product_packaging': line.product_packaging.id, |
117 | - 'address_id': line.address_allotment_id.id or order.partner_shipping_id.id, |
118 | - 'location_id': location_id, |
119 | - 'location_dest_id': output_id, |
120 | - 'sale_line_id': line.id, |
121 | - 'tracking_id': False, |
122 | - 'state': 'draft', |
123 | - #'state': 'waiting', |
124 | - 'note': line.notes, |
125 | - 'company_id': order.company_id.id, |
126 | - }) |
127 | + picking_data = {'name': pick_name, |
128 | + 'origin': order.name, |
129 | + 'type': 'out', |
130 | + 'state': 'auto', |
131 | + 'move_type': order.picking_policy, |
132 | + 'sale_id': order.id, |
133 | + 'address_id': order.partner_shipping_id.id, |
134 | + 'note': order.note, |
135 | + 'invoice_state': (order.order_policy=='picking' and '2binvoiced') or 'none', |
136 | + 'company_id': order.company_id.id, |
137 | + } |
138 | + picking_data = self._hook_ship_create_stock_picking(cr, uid, ids, context=context, picking_data=picking_data, order=order,) |
139 | + picking_id = self.pool.get('stock.picking').create(cr, uid, picking_data, context=context) |
140 | + |
141 | + move_data = {'name': line.name[:64], |
142 | + 'picking_id': picking_id, |
143 | + 'product_id': line.product_id.id, |
144 | + 'date': date_planned, |
145 | + 'date_expected': date_planned, |
146 | + 'product_qty': line.product_uom_qty, |
147 | + 'product_uom': line.product_uom.id, |
148 | + 'product_uos_qty': line.product_uos_qty, |
149 | + 'product_uos': (line.product_uos and line.product_uos.id)\ |
150 | + or line.product_uom.id, |
151 | + 'product_packaging': line.product_packaging.id, |
152 | + 'address_id': line.address_allotment_id.id or order.partner_shipping_id.id, |
153 | + 'location_id': location_id, |
154 | + 'location_dest_id': output_id, |
155 | + 'sale_line_id': line.id, |
156 | + 'tracking_id': False, |
157 | + 'state': 'draft', |
158 | + #'state': 'waiting', |
159 | + 'note': line.notes, |
160 | + 'company_id': order.company_id.id, |
161 | + } |
162 | + |
163 | + # hook for stock move data modification |
164 | + move_data = self._hook_ship_create_stock_move(cr, uid, ids, context=context, move_data=move_data, line=line, order=order,) |
165 | + move_id = self.pool.get('stock.move').create(cr, uid, move_data, context=context) |
166 | |
167 | if line.product_id: |
168 | - proc_id = self.pool.get('procurement.order').create(cr, uid, { |
169 | - 'name': line.name, |
170 | - 'origin': order.name, |
171 | - 'date_planned': date_planned, |
172 | - 'product_id': line.product_id.id, |
173 | - 'product_qty': line.product_uom_qty, |
174 | - 'product_uom': line.product_uom.id, |
175 | - 'product_uos_qty': (line.product_uos and line.product_uos_qty)\ |
176 | - or line.product_uom_qty, |
177 | - 'product_uos': (line.product_uos and line.product_uos.id)\ |
178 | - or line.product_uom.id, |
179 | - 'location_id': order.shop_id.warehouse_id.lot_stock_id.id, |
180 | - 'procure_method': line.type, |
181 | - 'move_id': move_id, |
182 | - 'property_ids': [(6, 0, [x.id for x in line.property_ids])], |
183 | - 'company_id': order.company_id.id, |
184 | - }) |
185 | + proc_data = {'name': line.name, |
186 | + 'origin': order.name, |
187 | + 'date_planned': date_planned, |
188 | + 'product_id': line.product_id.id, |
189 | + 'product_qty': line.product_uom_qty, |
190 | + 'product_uom': line.product_uom.id, |
191 | + 'product_uos_qty': (line.product_uos and line.product_uos_qty)\ |
192 | + or line.product_uom_qty, |
193 | + 'product_uos': (line.product_uos and line.product_uos.id)\ |
194 | + or line.product_uom.id, |
195 | + 'location_id': order.shop_id.warehouse_id.lot_stock_id.id, |
196 | + 'procure_method': line.type, |
197 | + 'move_id': move_id, |
198 | + 'property_ids': [(6, 0, [x.id for x in line.property_ids])], |
199 | + 'company_id': order.company_id.id, |
200 | + } |
201 | + proc_data = self._hook_ship_create_procurement_order(cr, uid, ids, context=context, proc_data=proc_data, line=line,) |
202 | + proc_id = self.pool.get('procurement.order').create(cr, uid, proc_data) |
203 | proc_ids.append(proc_id) |
204 | self.pool.get('sale.order.line').write(cr, uid, [line.id], {'procurement_id': proc_id}) |
205 | if order.state == 'shipping_except': |
206 | @@ -739,11 +807,12 @@ |
207 | |
208 | val = {} |
209 | |
210 | - if picking_id: |
211 | + if self._hook_ship_create_execute_picking_workflow(cr, uid, ids, context=context, picking_id=picking_id,): |
212 | wf_service.trg_validate(uid, 'stock.picking', picking_id, 'button_confirm', cr) |
213 | |
214 | for proc_id in proc_ids: |
215 | wf_service.trg_validate(uid, 'procurement.order', proc_id, 'button_confirm', cr) |
216 | + self._hook_ship_create_execute_specific_code_01(cr, uid, ids, context=context, order=order, proc_id=proc_id,) |
217 | |
218 | if order.state == 'shipping_except': |
219 | val['state'] = 'progress' |
220 | |
221 | === modified file 'sale/test/invoice_on_shipped_qty.yml' |
222 | --- sale/test/invoice_on_shipped_qty.yml 2011-01-14 00:11:01 +0000 |
223 | +++ sale/test/invoice_on_shipped_qty.yml 2011-09-21 12:33:24 +0000 |
224 | @@ -86,19 +86,22 @@ |
225 | I verify that an invoice is created on the basis of shipped quantities 100 not ordered quantities 200 |
226 | - |
227 | !python {model: account.invoice}: | |
228 | - sale_order_obj = self.pool.get('sale.order') |
229 | - so = sale_order_obj.browse(cr, uid, ref("sale_order_so6")) |
230 | - picking_obj = self.pool.get('stock.picking') |
231 | - ids = picking_obj.search(cr, uid, [('origin', '=', so.name),('type','=','out'),('state','=','done')]) |
232 | - qty = qty1 = 0.0 |
233 | - for pick_brw in picking_obj.browse(cr,uid, ids): |
234 | - for lines in pick_brw.move_lines: |
235 | - qty=lines.product_qty |
236 | - inv_id = self.search(cr, uid, [('origin', 'like', so.name)]) |
237 | - inv_brw = self.browse(cr,uid,inv_id)[0] |
238 | - for inv_lines in inv_brw.invoice_line: |
239 | - qty1=inv_lines.quantity |
240 | - assert (qty1 == qty), "Quantities are not the same" |
241 | + modules = self.pool.get('ir.module.module') |
242 | + mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])]) |
243 | + if not mod_pur: |
244 | + sale_order_obj = self.pool.get('sale.order') |
245 | + so = sale_order_obj.browse(cr, uid, ref("sale_order_so6")) |
246 | + picking_obj = self.pool.get('stock.picking') |
247 | + ids = picking_obj.search(cr, uid, [('origin', '=', so.name),('type','=','out'),('state','=','done')]) |
248 | + qty = qty1 = 0.0 |
249 | + for pick_brw in picking_obj.browse(cr,uid, ids): |
250 | + for lines in pick_brw.move_lines: |
251 | + qty=lines.product_qty |
252 | + inv_id = self.search(cr, uid, [('origin', 'like', so.name)]) |
253 | + inv_brw = self.browse(cr,uid,inv_id)[0] |
254 | + for inv_lines in inv_brw.invoice_line: |
255 | + qty1=inv_lines.quantity |
256 | + assert (qty1 == qty), "Quantities are not the same" |
257 | - |
258 | I open the Invoice for the SO. |
259 | - |
260 | |
261 | === modified file 'sale/test/manual_order_policy.yml' |
262 | --- sale/test/manual_order_policy.yml 2011-01-14 00:11:01 +0000 |
263 | +++ sale/test/manual_order_policy.yml 2011-09-21 12:33:24 +0000 |
264 | @@ -244,14 +244,16 @@ |
265 | ids = picking_obj.search(cr, uid, [('purchase_id', '=', po.id ),('state', '=', 'done')]) |
266 | assert(ids),"Picking is not in the done state!" |
267 | - |
268 | - Then I done the picking |
269 | + Then I done the picking, if msf_outgoing module is not installed |
270 | - |
271 | !python {model: stock.picking }: | |
272 | import time |
273 | + modules = self.pool.get('ir.module.module') |
274 | + mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])]) |
275 | sale_order_obj = self.pool.get('sale.order') |
276 | so = sale_order_obj.browse(cr, uid, ref("sale_order_so0")) |
277 | picking_id = self.search(cr, uid, [('origin','=',so.name),('type','=','out')]) |
278 | - if picking_id: |
279 | + if picking_id and not mod_pur: |
280 | pick=self.browse(cr,uid,picking_id[0]) |
281 | pick.force_assign(cr, uid) |
282 | partial_datas = { |
283 | @@ -270,11 +272,14 @@ |
284 | I verify that picking for sale order is in done state. |
285 | - |
286 | !python {model: stock.picking }: | |
287 | - sale_order_obj = self.pool.get('sale.order') |
288 | - so = sale_order_obj.browse(cr, uid, ref("sale_order_so0")) |
289 | - picking_id = self.search(cr, uid, [('origin','=',so.name),('type','=','out')]) |
290 | - pick = self.browse(cr,uid,picking_id[0]) |
291 | - assert (pick.state) =='done', "Picking for SO is not in done state." |
292 | + modules = self.pool.get('ir.module.module') |
293 | + mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])]) |
294 | + if not mod_pur: |
295 | + sale_order_obj = self.pool.get('sale.order') |
296 | + so = sale_order_obj.browse(cr, uid, ref("sale_order_so0")) |
297 | + picking_id = self.search(cr, uid, [('origin','=',so.name),('type','=','out')]) |
298 | + pick = self.browse(cr,uid,picking_id[0]) |
299 | + assert (pick.state) =='done', "Picking for SO is not in done state." |
300 | - |
301 | Then I done the delivery order |
302 | - |
303 | @@ -302,11 +307,14 @@ |
304 | I verify that delivery state is done |
305 | - |
306 | !python {model: stock.picking }: | |
307 | - sale_order_obj = self.pool.get('sale.order') |
308 | - so = sale_order_obj.browse(cr, uid, ref("sale_order_so0")) |
309 | - picking_id = self.search(cr, uid, [('origin','=',so.name)]) |
310 | - pick = self.browse(cr,uid,picking_id[0]) |
311 | - assert (pick.state) =='done', "Picking for SO is not in done state." |
312 | + modules = self.pool.get('ir.module.module') |
313 | + mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])]) |
314 | + if not mod_pur: |
315 | + sale_order_obj = self.pool.get('sale.order') |
316 | + so = sale_order_obj.browse(cr, uid, ref("sale_order_so0")) |
317 | + picking_id = self.search(cr, uid, [('origin','=',so.name)]) |
318 | + pick = self.browse(cr,uid,picking_id[0]) |
319 | + assert (pick.state) =='done', "Picking for SO is not in done state." |
320 | - |
321 | I verify that a "Picked" has been set to true |
322 | - |
323 | |
324 | === modified file 'sale/test/picking_order_policy.yml' |
325 | --- sale/test/picking_order_policy.yml 2011-01-14 00:11:01 +0000 |
326 | +++ sale/test/picking_order_policy.yml 2011-09-21 12:33:24 +0000 |
327 | @@ -286,7 +286,9 @@ |
328 | sale_order_obj = self.pool.get('sale.order') |
329 | so = sale_order_obj.browse(cr, uid, ref("sale_order_so7")) |
330 | picking_id = self.search(cr, uid, [('origin','=',so.name)]) |
331 | - if picking_id: |
332 | + modules = self.pool.get('ir.module.module') |
333 | + mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])]) |
334 | + if picking_id and not mod_pur: |
335 | pick = self.browse(cr,uid,picking_id[0]) |
336 | assert (pick.state) =='done', "Picking for SO is not in done state." |
337 | - |
338 | |
339 | === modified file 'sale/test/postpaid_order_policy.yml' |
340 | --- sale/test/postpaid_order_policy.yml 2011-01-14 00:11:01 +0000 |
341 | +++ sale/test/postpaid_order_policy.yml 2011-09-21 12:33:24 +0000 |
342 | @@ -64,7 +64,9 @@ |
343 | sale_order_obj = self.pool.get('sale.order') |
344 | so = sale_order_obj.browse(cr, uid, ref("sale_order_so8")) |
345 | picking_id = self.search(cr, uid, [('origin','=',so.name),('type','=','out')]) |
346 | - if picking_id: |
347 | + modules = self.pool.get('ir.module.module') |
348 | + mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])]) |
349 | + if picking_id and not mod_pur: |
350 | pick = self.browse(cr,uid,picking_id[0]) |
351 | assert (pick.state == 'done'), "Picking for SO is not in done state." |
352 | - |
353 | @@ -105,7 +107,9 @@ |
354 | sale_order_obj = self.pool.get('sale.order') |
355 | so = sale_order_obj.browse(cr, uid, ref("sale_order_so8")) |
356 | picking_id = self.search(cr, uid, [('origin','=',so.name)]) |
357 | - if picking_id: |
358 | + modules = self.pool.get('ir.module.module') |
359 | + mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])]) |
360 | + if picking_id and not mod_pur: |
361 | pick = self.browse(cr,uid,picking_id[0]) |
362 | assert (pick.state) =='done', "Picking for SO is not in done state." |
363 | - |
364 | |
365 | === modified file 'sale/test/prepaid_order_policy.yml' |
366 | --- sale/test/prepaid_order_policy.yml 2011-01-14 00:11:01 +0000 |
367 | +++ sale/test/prepaid_order_policy.yml 2011-09-21 12:33:24 +0000 |
368 | @@ -98,7 +98,9 @@ |
369 | sale_order_obj = self.pool.get('sale.order') |
370 | so = sale_order_obj.browse(cr, uid, ref("sale_order_so1")) |
371 | picking_id = self.search(cr, uid, [('origin','=',so.name),('type','=','out')]) |
372 | - if picking_id: |
373 | + modules = self.pool.get('ir.module.module') |
374 | + mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])]) |
375 | + if picking_id and not mod_pur: |
376 | pick=self.browse(cr,uid,picking_id[0]) |
377 | pick.force_assign(cr, uid) |
378 | partial_datas = { |
379 | @@ -117,11 +119,14 @@ |
380 | I verify that picking order is in done state. |
381 | - |
382 | !python {model: stock.picking }: | |
383 | - sale_order_obj = self.pool.get('sale.order') |
384 | - so = sale_order_obj.browse(cr, uid, ref("sale_order_so1")) |
385 | - picking_id = self.search(cr, uid, [('origin','=',so.name),('type','=','out')]) |
386 | - pick = self.browse(cr,uid,picking_id[0]) |
387 | - assert (pick.state) =='done', "Picking for SO is not in done state." |
388 | + modules = self.pool.get('ir.module.module') |
389 | + mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])]) |
390 | + if not mod_pur: |
391 | + sale_order_obj = self.pool.get('sale.order') |
392 | + so = sale_order_obj.browse(cr, uid, ref("sale_order_so1")) |
393 | + picking_id = self.search(cr, uid, [('origin','=',so.name),('type','=','out')]) |
394 | + pick = self.browse(cr,uid,picking_id[0]) |
395 | + assert (pick.state) =='done', "Picking for SO is not in done state." |
396 | - |
397 | I verify that a procurement has been generated for so |
398 | - |
399 | @@ -256,11 +261,17 @@ |
400 | I verify that a "Picked" has been set to true |
401 | - |
402 | !python {model: sale.order}: | |
403 | - so = self.browse(cr, uid, ref("sale_order_so1")) |
404 | - assert (so.shipped == True), "Picking is not done." |
405 | + modules = self.pool.get('ir.module.module') |
406 | + mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])]) |
407 | + if not mod_pur: |
408 | + so = self.browse(cr, uid, ref("sale_order_so1")) |
409 | + assert (so.shipped == True), "Picking is not done." |
410 | - |
411 | I verify that a sale order is in done state |
412 | - |
413 | !python {model: sale.order}: | |
414 | - so = self.browse(cr, uid, ref("sale_order_so1")) |
415 | - assert (so.state == 'done'), "Sale order is not in the done state." |
416 | + modules = self.pool.get('ir.module.module') |
417 | + mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])]) |
418 | + if not mod_pur: |
419 | + so = self.browse(cr, uid, ref("sale_order_so1")) |
420 | + assert (so.state == 'done'), "Sale order is not in the done state." |
421 | |
422 | === modified file 'stock/stock.py' |
423 | --- stock/stock.py 2011-09-20 12:14:48 +0000 |
424 | +++ stock/stock.py 2011-09-21 12:33:24 +0000 |
425 | @@ -677,7 +677,7 @@ |
426 | 'context': dict(context, active_ids=ids) |
427 | } |
428 | |
429 | - def _keep_prodlot_hook(self, cr, uid, id, context, *args, **kwargs): |
430 | + def _erase_prodlot_hook(self, cr, uid, id, context=None, *args, **kwargs): |
431 | ''' |
432 | hook to keep the production lot when a stock move is copied |
433 | ''' |
434 | @@ -689,6 +689,8 @@ |
435 | def copy(self, cr, uid, id, default=None, context=None): |
436 | if default is None: |
437 | default = {} |
438 | + if context is None: |
439 | + context = {} |
440 | default = default.copy() |
441 | picking_obj = self.browse(cr, uid, id, context=context) |
442 | move_obj = self.pool.get('stock.move') |
443 | @@ -698,7 +700,7 @@ |
444 | default['origin'] = '' |
445 | default['backorder_id'] = False |
446 | res = super(stock_picking, self).copy(cr, uid, id, default, context) |
447 | - if self._keep_prodlot_hook(cr, uid, id, context, res=res): |
448 | + if self._erase_prodlot_hook(cr, uid, id, context=context, res=res): |
449 | picking_obj = self.browse(cr, uid, res, context=context) |
450 | for move in picking_obj.move_lines: |
451 | move_obj.write(cr, uid, [move.id], {'tracking_id': False,'prodlot_id':False}) |
452 | @@ -731,16 +733,28 @@ |
453 | def test_auto_picking(self, cr, uid, ids): |
454 | # TODO: Check locations to see if in the same location ? |
455 | return True |
456 | + |
457 | + def _hook_action_assign_raise_exception(self, cr, uid, ids, context=None, *args, **kwargs): |
458 | + ''' |
459 | + Please copy this to your module's method also. |
460 | + This hook belongs to the action_assign method from stock>stock.py>stock_picking class |
461 | + |
462 | + - allow to choose wether or not an exception should be raised in case of no stock move |
463 | + ''' |
464 | + return True |
465 | |
466 | - def action_assign(self, cr, uid, ids, *args): |
467 | + def action_assign(self, cr, uid, ids, context=None, *args): |
468 | """ Changes state of picking to available if all moves are confirmed. |
469 | @return: True |
470 | """ |
471 | + if context is None: |
472 | + context = {} |
473 | move_obj = self.pool.get('stock.move') |
474 | for pick in self.browse(cr, uid, ids): |
475 | move_ids = [x.id for x in pick.move_lines if x.state == 'confirmed'] |
476 | if not move_ids: |
477 | - raise osv.except_osv(_('Warning !'),_('Not enough stock, unable to reserve the products.')) |
478 | + if self._hook_action_assign_raise_exception(cr, uid, ids, context=context,): |
479 | + raise osv.except_osv(_('Warning !'),_('Not enough stock, unable to reserve the products.')) |
480 | move_obj.action_assign(cr, uid, move_ids) |
481 | return True |
482 |