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 | 649 | if notcanceled: | 649 | if notcanceled: |
6 | 650 | return False | 650 | return False |
7 | 651 | return canceled | 651 | return canceled |
10 | 652 | 652 | ||
11 | 653 | def action_ship_create(self, cr, uid, ids, *args): | 653 | def _hook_ship_create_stock_move(self, cr, uid, ids, context=None, *args, **kwargs): |
12 | 654 | ''' | ||
13 | 655 | Please copy this to your module's method also. | ||
14 | 656 | This hook belongs to the action_ship_create method from sale>sale.py | ||
15 | 657 | |||
16 | 658 | - allow to modify the data for stock move creation | ||
17 | 659 | ''' | ||
18 | 660 | move_data = kwargs['move_data'] | ||
19 | 661 | return move_data | ||
20 | 662 | |||
21 | 663 | def _hook_ship_create_procurement_order(self, cr, uid, ids, context=None, *args, **kwargs): | ||
22 | 664 | ''' | ||
23 | 665 | Please copy this to your module's method also. | ||
24 | 666 | This hook belongs to the action_ship_create method from sale>sale.py | ||
25 | 667 | |||
26 | 668 | - allow to modify the data for procurement order creation | ||
27 | 669 | ''' | ||
28 | 670 | proc_data = kwargs['proc_data'] | ||
29 | 671 | return proc_data | ||
30 | 672 | |||
31 | 673 | def _hook_ship_create_stock_picking(self, cr, uid, ids, context=None, *args, **kwargs): | ||
32 | 674 | ''' | ||
33 | 675 | Please copy this to your module's method also. | ||
34 | 676 | This hook belongs to the action_ship_create method from sale>sale.py | ||
35 | 677 | |||
36 | 678 | - allow to modify the data for stock picking creation | ||
37 | 679 | ''' | ||
38 | 680 | picking_data = kwargs['picking_data'] | ||
39 | 681 | return picking_data | ||
40 | 682 | |||
41 | 683 | def _hook_ship_create_execute_picking_workflow(self, cr, uid, ids, context=None, *args, **kwargs): | ||
42 | 684 | ''' | ||
43 | 685 | Please copy this to your module's method also. | ||
44 | 686 | This hook belongs to the action_ship_create method from sale>sale.py | ||
45 | 687 | |||
46 | 688 | - allow to avoid the stock picking workflow execution | ||
47 | 689 | ''' | ||
48 | 690 | picking_id = kwargs['picking_id'] | ||
49 | 691 | return picking_id | ||
50 | 692 | |||
51 | 693 | def _hook_ship_create_execute_specific_code_01(self, cr, uid, ids, context=None, *args, **kwargs): | ||
52 | 694 | ''' | ||
53 | 695 | Please copy this to your module's method also. | ||
54 | 696 | This hook belongs to the action_ship_create method from sale>sale.py | ||
55 | 697 | |||
56 | 698 | - allow to execute specific code at position 01 | ||
57 | 699 | ''' | ||
58 | 700 | pass | ||
59 | 701 | |||
60 | 702 | def _hook_ship_create_line_condition(self, cr, uid, ids, context=None, *args, **kwargs): | ||
61 | 703 | ''' | ||
62 | 704 | Please copy this to your module's method also. | ||
63 | 705 | This hook belongs to the action_ship_create method from sale>sale.py | ||
64 | 706 | |||
65 | 707 | - allow to customize the execution condition | ||
66 | 708 | ''' | ||
67 | 709 | line = kwargs['line'] | ||
68 | 710 | result = line.product_id and line.product_id.product_tmpl_id.type in ('product', 'consu') | ||
69 | 711 | return result | ||
70 | 712 | |||
71 | 713 | def action_ship_create(self, cr, uid, ids, context=None, *args): | ||
72 | 714 | if context is None: | ||
73 | 715 | context = {} | ||
74 | 654 | wf_service = netsvc.LocalService("workflow") | 716 | wf_service = netsvc.LocalService("workflow") |
75 | 655 | picking_id = False | 717 | picking_id = False |
76 | 656 | move_obj = self.pool.get('stock.move') | 718 | move_obj = self.pool.get('stock.move') |
77 | 657 | proc_obj = self.pool.get('procurement.order') | 719 | proc_obj = self.pool.get('procurement.order') |
78 | 658 | company = self.pool.get('res.users').browse(cr, uid, uid).company_id | 720 | company = self.pool.get('res.users').browse(cr, uid, uid).company_id |
80 | 659 | for order in self.browse(cr, uid, ids, context={}): | 721 | for order in self.browse(cr, uid, ids, context=context): |
81 | 660 | proc_ids = [] | 722 | proc_ids = [] |
82 | 661 | output_id = order.shop_id.warehouse_id.lot_output_id.id | 723 | output_id = order.shop_id.warehouse_id.lot_output_id.id |
83 | 662 | picking_id = False | 724 | picking_id = False |
84 | @@ -668,63 +730,69 @@ | |||
85 | 668 | if line.state == 'done': | 730 | if line.state == 'done': |
86 | 669 | continue | 731 | continue |
87 | 670 | move_id = False | 732 | move_id = False |
89 | 671 | if line.product_id and line.product_id.product_tmpl_id.type in ('product', 'consu'): | 733 | if self._hook_ship_create_line_condition(cr, uid, ids, context=context, line=line,): |
90 | 672 | location_id = order.shop_id.warehouse_id.lot_stock_id.id | 734 | location_id = order.shop_id.warehouse_id.lot_stock_id.id |
91 | 673 | if not picking_id: | 735 | if not picking_id: |
92 | 674 | pick_name = self.pool.get('ir.sequence').get(cr, uid, 'stock.picking.out') | 736 | pick_name = self.pool.get('ir.sequence').get(cr, uid, 'stock.picking.out') |
127 | 675 | picking_id = self.pool.get('stock.picking').create(cr, uid, { | 737 | picking_data = {'name': pick_name, |
128 | 676 | 'name': pick_name, | 738 | 'origin': order.name, |
129 | 677 | 'origin': order.name, | 739 | 'type': 'out', |
130 | 678 | 'type': 'out', | 740 | 'state': 'auto', |
131 | 679 | 'state': 'auto', | 741 | 'move_type': order.picking_policy, |
132 | 680 | 'move_type': order.picking_policy, | 742 | 'sale_id': order.id, |
133 | 681 | 'sale_id': order.id, | 743 | 'address_id': order.partner_shipping_id.id, |
134 | 682 | 'address_id': order.partner_shipping_id.id, | 744 | 'note': order.note, |
135 | 683 | 'note': order.note, | 745 | 'invoice_state': (order.order_policy=='picking' and '2binvoiced') or 'none', |
136 | 684 | 'invoice_state': (order.order_policy=='picking' and '2binvoiced') or 'none', | 746 | 'company_id': order.company_id.id, |
137 | 685 | 'company_id': order.company_id.id, | 747 | } |
138 | 686 | }) | 748 | picking_data = self._hook_ship_create_stock_picking(cr, uid, ids, context=context, picking_data=picking_data, order=order,) |
139 | 687 | move_id = self.pool.get('stock.move').create(cr, uid, { | 749 | picking_id = self.pool.get('stock.picking').create(cr, uid, picking_data, context=context) |
140 | 688 | 'name': line.name[:64], | 750 | |
141 | 689 | 'picking_id': picking_id, | 751 | move_data = {'name': line.name[:64], |
142 | 690 | 'product_id': line.product_id.id, | 752 | 'picking_id': picking_id, |
143 | 691 | 'date': date_planned, | 753 | 'product_id': line.product_id.id, |
144 | 692 | 'date_expected': date_planned, | 754 | 'date': date_planned, |
145 | 693 | 'product_qty': line.product_uom_qty, | 755 | 'date_expected': date_planned, |
146 | 694 | 'product_uom': line.product_uom.id, | 756 | 'product_qty': line.product_uom_qty, |
147 | 695 | 'product_uos_qty': line.product_uos_qty, | 757 | 'product_uom': line.product_uom.id, |
148 | 696 | 'product_uos': (line.product_uos and line.product_uos.id)\ | 758 | 'product_uos_qty': line.product_uos_qty, |
149 | 697 | or line.product_uom.id, | 759 | 'product_uos': (line.product_uos and line.product_uos.id)\ |
150 | 698 | 'product_packaging': line.product_packaging.id, | 760 | or line.product_uom.id, |
151 | 699 | 'address_id': line.address_allotment_id.id or order.partner_shipping_id.id, | 761 | 'product_packaging': line.product_packaging.id, |
152 | 700 | 'location_id': location_id, | 762 | 'address_id': line.address_allotment_id.id or order.partner_shipping_id.id, |
153 | 701 | 'location_dest_id': output_id, | 763 | 'location_id': location_id, |
154 | 702 | 'sale_line_id': line.id, | 764 | 'location_dest_id': output_id, |
155 | 703 | 'tracking_id': False, | 765 | 'sale_line_id': line.id, |
156 | 704 | 'state': 'draft', | 766 | 'tracking_id': False, |
157 | 705 | #'state': 'waiting', | 767 | 'state': 'draft', |
158 | 706 | 'note': line.notes, | 768 | #'state': 'waiting', |
159 | 707 | 'company_id': order.company_id.id, | 769 | 'note': line.notes, |
160 | 708 | }) | 770 | 'company_id': order.company_id.id, |
161 | 771 | } | ||
162 | 772 | |||
163 | 773 | # hook for stock move data modification | ||
164 | 774 | move_data = self._hook_ship_create_stock_move(cr, uid, ids, context=context, move_data=move_data, line=line, order=order,) | ||
165 | 775 | move_id = self.pool.get('stock.move').create(cr, uid, move_data, context=context) | ||
166 | 709 | 776 | ||
167 | 710 | if line.product_id: | 777 | if line.product_id: |
185 | 711 | proc_id = self.pool.get('procurement.order').create(cr, uid, { | 778 | proc_data = {'name': line.name, |
186 | 712 | 'name': line.name, | 779 | 'origin': order.name, |
187 | 713 | 'origin': order.name, | 780 | 'date_planned': date_planned, |
188 | 714 | 'date_planned': date_planned, | 781 | 'product_id': line.product_id.id, |
189 | 715 | 'product_id': line.product_id.id, | 782 | 'product_qty': line.product_uom_qty, |
190 | 716 | 'product_qty': line.product_uom_qty, | 783 | 'product_uom': line.product_uom.id, |
191 | 717 | 'product_uom': line.product_uom.id, | 784 | 'product_uos_qty': (line.product_uos and line.product_uos_qty)\ |
192 | 718 | 'product_uos_qty': (line.product_uos and line.product_uos_qty)\ | 785 | or line.product_uom_qty, |
193 | 719 | or line.product_uom_qty, | 786 | 'product_uos': (line.product_uos and line.product_uos.id)\ |
194 | 720 | 'product_uos': (line.product_uos and line.product_uos.id)\ | 787 | or line.product_uom.id, |
195 | 721 | or line.product_uom.id, | 788 | 'location_id': order.shop_id.warehouse_id.lot_stock_id.id, |
196 | 722 | 'location_id': order.shop_id.warehouse_id.lot_stock_id.id, | 789 | 'procure_method': line.type, |
197 | 723 | 'procure_method': line.type, | 790 | 'move_id': move_id, |
198 | 724 | 'move_id': move_id, | 791 | 'property_ids': [(6, 0, [x.id for x in line.property_ids])], |
199 | 725 | 'property_ids': [(6, 0, [x.id for x in line.property_ids])], | 792 | 'company_id': order.company_id.id, |
200 | 726 | 'company_id': order.company_id.id, | 793 | } |
201 | 727 | }) | 794 | proc_data = self._hook_ship_create_procurement_order(cr, uid, ids, context=context, proc_data=proc_data, line=line,) |
202 | 795 | proc_id = self.pool.get('procurement.order').create(cr, uid, proc_data) | ||
203 | 728 | proc_ids.append(proc_id) | 796 | proc_ids.append(proc_id) |
204 | 729 | self.pool.get('sale.order.line').write(cr, uid, [line.id], {'procurement_id': proc_id}) | 797 | self.pool.get('sale.order.line').write(cr, uid, [line.id], {'procurement_id': proc_id}) |
205 | 730 | if order.state == 'shipping_except': | 798 | if order.state == 'shipping_except': |
206 | @@ -739,11 +807,12 @@ | |||
207 | 739 | 807 | ||
208 | 740 | val = {} | 808 | val = {} |
209 | 741 | 809 | ||
211 | 742 | if picking_id: | 810 | if self._hook_ship_create_execute_picking_workflow(cr, uid, ids, context=context, picking_id=picking_id,): |
212 | 743 | wf_service.trg_validate(uid, 'stock.picking', picking_id, 'button_confirm', cr) | 811 | wf_service.trg_validate(uid, 'stock.picking', picking_id, 'button_confirm', cr) |
213 | 744 | 812 | ||
214 | 745 | for proc_id in proc_ids: | 813 | for proc_id in proc_ids: |
215 | 746 | wf_service.trg_validate(uid, 'procurement.order', proc_id, 'button_confirm', cr) | 814 | wf_service.trg_validate(uid, 'procurement.order', proc_id, 'button_confirm', cr) |
216 | 815 | self._hook_ship_create_execute_specific_code_01(cr, uid, ids, context=context, order=order, proc_id=proc_id,) | ||
217 | 747 | 816 | ||
218 | 748 | if order.state == 'shipping_except': | 817 | if order.state == 'shipping_except': |
219 | 749 | val['state'] = 'progress' | 818 | val['state'] = 'progress' |
220 | 750 | 819 | ||
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 | 86 | I verify that an invoice is created on the basis of shipped quantities 100 not ordered quantities 200 | 86 | I verify that an invoice is created on the basis of shipped quantities 100 not ordered quantities 200 |
226 | 87 | - | 87 | - |
227 | 88 | !python {model: account.invoice}: | | 88 | !python {model: account.invoice}: | |
241 | 89 | sale_order_obj = self.pool.get('sale.order') | 89 | modules = self.pool.get('ir.module.module') |
242 | 90 | so = sale_order_obj.browse(cr, uid, ref("sale_order_so6")) | 90 | mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])]) |
243 | 91 | picking_obj = self.pool.get('stock.picking') | 91 | if not mod_pur: |
244 | 92 | ids = picking_obj.search(cr, uid, [('origin', '=', so.name),('type','=','out'),('state','=','done')]) | 92 | sale_order_obj = self.pool.get('sale.order') |
245 | 93 | qty = qty1 = 0.0 | 93 | so = sale_order_obj.browse(cr, uid, ref("sale_order_so6")) |
246 | 94 | for pick_brw in picking_obj.browse(cr,uid, ids): | 94 | picking_obj = self.pool.get('stock.picking') |
247 | 95 | for lines in pick_brw.move_lines: | 95 | ids = picking_obj.search(cr, uid, [('origin', '=', so.name),('type','=','out'),('state','=','done')]) |
248 | 96 | qty=lines.product_qty | 96 | qty = qty1 = 0.0 |
249 | 97 | inv_id = self.search(cr, uid, [('origin', 'like', so.name)]) | 97 | for pick_brw in picking_obj.browse(cr,uid, ids): |
250 | 98 | inv_brw = self.browse(cr,uid,inv_id)[0] | 98 | for lines in pick_brw.move_lines: |
251 | 99 | for inv_lines in inv_brw.invoice_line: | 99 | qty=lines.product_qty |
252 | 100 | qty1=inv_lines.quantity | 100 | inv_id = self.search(cr, uid, [('origin', 'like', so.name)]) |
253 | 101 | assert (qty1 == qty), "Quantities are not the same" | 101 | inv_brw = self.browse(cr,uid,inv_id)[0] |
254 | 102 | for inv_lines in inv_brw.invoice_line: | ||
255 | 103 | qty1=inv_lines.quantity | ||
256 | 104 | assert (qty1 == qty), "Quantities are not the same" | ||
257 | 102 | - | 105 | - |
258 | 103 | I open the Invoice for the SO. | 106 | I open the Invoice for the SO. |
259 | 104 | - | 107 | - |
260 | 105 | 108 | ||
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 | 244 | ids = picking_obj.search(cr, uid, [('purchase_id', '=', po.id ),('state', '=', 'done')]) | 244 | ids = picking_obj.search(cr, uid, [('purchase_id', '=', po.id ),('state', '=', 'done')]) |
266 | 245 | assert(ids),"Picking is not in the done state!" | 245 | assert(ids),"Picking is not in the done state!" |
267 | 246 | - | 246 | - |
269 | 247 | Then I done the picking | 247 | Then I done the picking, if msf_outgoing module is not installed |
270 | 248 | - | 248 | - |
271 | 249 | !python {model: stock.picking }: | | 249 | !python {model: stock.picking }: | |
272 | 250 | import time | 250 | import time |
273 | 251 | modules = self.pool.get('ir.module.module') | ||
274 | 252 | mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])]) | ||
275 | 251 | sale_order_obj = self.pool.get('sale.order') | 253 | sale_order_obj = self.pool.get('sale.order') |
276 | 252 | so = sale_order_obj.browse(cr, uid, ref("sale_order_so0")) | 254 | so = sale_order_obj.browse(cr, uid, ref("sale_order_so0")) |
277 | 253 | picking_id = self.search(cr, uid, [('origin','=',so.name),('type','=','out')]) | 255 | picking_id = self.search(cr, uid, [('origin','=',so.name),('type','=','out')]) |
279 | 254 | if picking_id: | 256 | if picking_id and not mod_pur: |
280 | 255 | pick=self.browse(cr,uid,picking_id[0]) | 257 | pick=self.browse(cr,uid,picking_id[0]) |
281 | 256 | pick.force_assign(cr, uid) | 258 | pick.force_assign(cr, uid) |
282 | 257 | partial_datas = { | 259 | partial_datas = { |
283 | @@ -270,11 +272,14 @@ | |||
284 | 270 | I verify that picking for sale order is in done state. | 272 | I verify that picking for sale order is in done state. |
285 | 271 | - | 273 | - |
286 | 272 | !python {model: stock.picking }: | | 274 | !python {model: stock.picking }: | |
292 | 273 | sale_order_obj = self.pool.get('sale.order') | 275 | modules = self.pool.get('ir.module.module') |
293 | 274 | so = sale_order_obj.browse(cr, uid, ref("sale_order_so0")) | 276 | mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])]) |
294 | 275 | picking_id = self.search(cr, uid, [('origin','=',so.name),('type','=','out')]) | 277 | if not mod_pur: |
295 | 276 | pick = self.browse(cr,uid,picking_id[0]) | 278 | sale_order_obj = self.pool.get('sale.order') |
296 | 277 | assert (pick.state) =='done', "Picking for SO is not in done state." | 279 | so = sale_order_obj.browse(cr, uid, ref("sale_order_so0")) |
297 | 280 | picking_id = self.search(cr, uid, [('origin','=',so.name),('type','=','out')]) | ||
298 | 281 | pick = self.browse(cr,uid,picking_id[0]) | ||
299 | 282 | assert (pick.state) =='done', "Picking for SO is not in done state." | ||
300 | 278 | - | 283 | - |
301 | 279 | Then I done the delivery order | 284 | Then I done the delivery order |
302 | 280 | - | 285 | - |
303 | @@ -302,11 +307,14 @@ | |||
304 | 302 | I verify that delivery state is done | 307 | I verify that delivery state is done |
305 | 303 | - | 308 | - |
306 | 304 | !python {model: stock.picking }: | | 309 | !python {model: stock.picking }: | |
312 | 305 | sale_order_obj = self.pool.get('sale.order') | 310 | modules = self.pool.get('ir.module.module') |
313 | 306 | so = sale_order_obj.browse(cr, uid, ref("sale_order_so0")) | 311 | mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])]) |
314 | 307 | picking_id = self.search(cr, uid, [('origin','=',so.name)]) | 312 | if not mod_pur: |
315 | 308 | pick = self.browse(cr,uid,picking_id[0]) | 313 | sale_order_obj = self.pool.get('sale.order') |
316 | 309 | assert (pick.state) =='done', "Picking for SO is not in done state." | 314 | so = sale_order_obj.browse(cr, uid, ref("sale_order_so0")) |
317 | 315 | picking_id = self.search(cr, uid, [('origin','=',so.name)]) | ||
318 | 316 | pick = self.browse(cr,uid,picking_id[0]) | ||
319 | 317 | assert (pick.state) =='done', "Picking for SO is not in done state." | ||
320 | 310 | - | 318 | - |
321 | 311 | I verify that a "Picked" has been set to true | 319 | I verify that a "Picked" has been set to true |
322 | 312 | - | 320 | - |
323 | 313 | 321 | ||
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 | 286 | sale_order_obj = self.pool.get('sale.order') | 286 | sale_order_obj = self.pool.get('sale.order') |
329 | 287 | so = sale_order_obj.browse(cr, uid, ref("sale_order_so7")) | 287 | so = sale_order_obj.browse(cr, uid, ref("sale_order_so7")) |
330 | 288 | picking_id = self.search(cr, uid, [('origin','=',so.name)]) | 288 | picking_id = self.search(cr, uid, [('origin','=',so.name)]) |
332 | 289 | if picking_id: | 289 | modules = self.pool.get('ir.module.module') |
333 | 290 | mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])]) | ||
334 | 291 | if picking_id and not mod_pur: | ||
335 | 290 | pick = self.browse(cr,uid,picking_id[0]) | 292 | pick = self.browse(cr,uid,picking_id[0]) |
336 | 291 | assert (pick.state) =='done', "Picking for SO is not in done state." | 293 | assert (pick.state) =='done', "Picking for SO is not in done state." |
337 | 292 | - | 294 | - |
338 | 293 | 295 | ||
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 | 64 | sale_order_obj = self.pool.get('sale.order') | 64 | sale_order_obj = self.pool.get('sale.order') |
344 | 65 | so = sale_order_obj.browse(cr, uid, ref("sale_order_so8")) | 65 | so = sale_order_obj.browse(cr, uid, ref("sale_order_so8")) |
345 | 66 | picking_id = self.search(cr, uid, [('origin','=',so.name),('type','=','out')]) | 66 | picking_id = self.search(cr, uid, [('origin','=',so.name),('type','=','out')]) |
347 | 67 | if picking_id: | 67 | modules = self.pool.get('ir.module.module') |
348 | 68 | mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])]) | ||
349 | 69 | if picking_id and not mod_pur: | ||
350 | 68 | pick = self.browse(cr,uid,picking_id[0]) | 70 | pick = self.browse(cr,uid,picking_id[0]) |
351 | 69 | assert (pick.state == 'done'), "Picking for SO is not in done state." | 71 | assert (pick.state == 'done'), "Picking for SO is not in done state." |
352 | 70 | - | 72 | - |
353 | @@ -105,7 +107,9 @@ | |||
354 | 105 | sale_order_obj = self.pool.get('sale.order') | 107 | sale_order_obj = self.pool.get('sale.order') |
355 | 106 | so = sale_order_obj.browse(cr, uid, ref("sale_order_so8")) | 108 | so = sale_order_obj.browse(cr, uid, ref("sale_order_so8")) |
356 | 107 | picking_id = self.search(cr, uid, [('origin','=',so.name)]) | 109 | picking_id = self.search(cr, uid, [('origin','=',so.name)]) |
358 | 108 | if picking_id: | 110 | modules = self.pool.get('ir.module.module') |
359 | 111 | mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])]) | ||
360 | 112 | if picking_id and not mod_pur: | ||
361 | 109 | pick = self.browse(cr,uid,picking_id[0]) | 113 | pick = self.browse(cr,uid,picking_id[0]) |
362 | 110 | assert (pick.state) =='done', "Picking for SO is not in done state." | 114 | assert (pick.state) =='done', "Picking for SO is not in done state." |
363 | 111 | - | 115 | - |
364 | 112 | 116 | ||
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 | 98 | sale_order_obj = self.pool.get('sale.order') | 98 | sale_order_obj = self.pool.get('sale.order') |
370 | 99 | so = sale_order_obj.browse(cr, uid, ref("sale_order_so1")) | 99 | so = sale_order_obj.browse(cr, uid, ref("sale_order_so1")) |
371 | 100 | picking_id = self.search(cr, uid, [('origin','=',so.name),('type','=','out')]) | 100 | picking_id = self.search(cr, uid, [('origin','=',so.name),('type','=','out')]) |
373 | 101 | if picking_id: | 101 | modules = self.pool.get('ir.module.module') |
374 | 102 | mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])]) | ||
375 | 103 | if picking_id and not mod_pur: | ||
376 | 102 | pick=self.browse(cr,uid,picking_id[0]) | 104 | pick=self.browse(cr,uid,picking_id[0]) |
377 | 103 | pick.force_assign(cr, uid) | 105 | pick.force_assign(cr, uid) |
378 | 104 | partial_datas = { | 106 | partial_datas = { |
379 | @@ -117,11 +119,14 @@ | |||
380 | 117 | I verify that picking order is in done state. | 119 | I verify that picking order is in done state. |
381 | 118 | - | 120 | - |
382 | 119 | !python {model: stock.picking }: | | 121 | !python {model: stock.picking }: | |
388 | 120 | sale_order_obj = self.pool.get('sale.order') | 122 | modules = self.pool.get('ir.module.module') |
389 | 121 | so = sale_order_obj.browse(cr, uid, ref("sale_order_so1")) | 123 | mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])]) |
390 | 122 | picking_id = self.search(cr, uid, [('origin','=',so.name),('type','=','out')]) | 124 | if not mod_pur: |
391 | 123 | pick = self.browse(cr,uid,picking_id[0]) | 125 | sale_order_obj = self.pool.get('sale.order') |
392 | 124 | assert (pick.state) =='done', "Picking for SO is not in done state." | 126 | so = sale_order_obj.browse(cr, uid, ref("sale_order_so1")) |
393 | 127 | picking_id = self.search(cr, uid, [('origin','=',so.name),('type','=','out')]) | ||
394 | 128 | pick = self.browse(cr,uid,picking_id[0]) | ||
395 | 129 | assert (pick.state) =='done', "Picking for SO is not in done state." | ||
396 | 125 | - | 130 | - |
397 | 126 | I verify that a procurement has been generated for so | 131 | I verify that a procurement has been generated for so |
398 | 127 | - | 132 | - |
399 | @@ -256,11 +261,17 @@ | |||
400 | 256 | I verify that a "Picked" has been set to true | 261 | I verify that a "Picked" has been set to true |
401 | 257 | - | 262 | - |
402 | 258 | !python {model: sale.order}: | | 263 | !python {model: sale.order}: | |
405 | 259 | so = self.browse(cr, uid, ref("sale_order_so1")) | 264 | modules = self.pool.get('ir.module.module') |
406 | 260 | assert (so.shipped == True), "Picking is not done." | 265 | mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])]) |
407 | 266 | if not mod_pur: | ||
408 | 267 | so = self.browse(cr, uid, ref("sale_order_so1")) | ||
409 | 268 | assert (so.shipped == True), "Picking is not done." | ||
410 | 261 | - | 269 | - |
411 | 262 | I verify that a sale order is in done state | 270 | I verify that a sale order is in done state |
412 | 263 | - | 271 | - |
413 | 264 | !python {model: sale.order}: | | 272 | !python {model: sale.order}: | |
416 | 265 | so = self.browse(cr, uid, ref("sale_order_so1")) | 273 | modules = self.pool.get('ir.module.module') |
417 | 266 | assert (so.state == 'done'), "Sale order is not in the done state." | 274 | mod_pur = modules.search(cr, uid, [('name','=','msf_outgoing'), ('state', 'in', ['installed', 'to upgrade', 'to install'])]) |
418 | 275 | if not mod_pur: | ||
419 | 276 | so = self.browse(cr, uid, ref("sale_order_so1")) | ||
420 | 277 | assert (so.state == 'done'), "Sale order is not in the done state." | ||
421 | 267 | 278 | ||
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 | 677 | 'context': dict(context, active_ids=ids) | 677 | 'context': dict(context, active_ids=ids) |
427 | 678 | } | 678 | } |
428 | 679 | 679 | ||
430 | 680 | def _keep_prodlot_hook(self, cr, uid, id, context, *args, **kwargs): | 680 | def _erase_prodlot_hook(self, cr, uid, id, context=None, *args, **kwargs): |
431 | 681 | ''' | 681 | ''' |
432 | 682 | hook to keep the production lot when a stock move is copied | 682 | hook to keep the production lot when a stock move is copied |
433 | 683 | ''' | 683 | ''' |
434 | @@ -689,6 +689,8 @@ | |||
435 | 689 | def copy(self, cr, uid, id, default=None, context=None): | 689 | def copy(self, cr, uid, id, default=None, context=None): |
436 | 690 | if default is None: | 690 | if default is None: |
437 | 691 | default = {} | 691 | default = {} |
438 | 692 | if context is None: | ||
439 | 693 | context = {} | ||
440 | 692 | default = default.copy() | 694 | default = default.copy() |
441 | 693 | picking_obj = self.browse(cr, uid, id, context=context) | 695 | picking_obj = self.browse(cr, uid, id, context=context) |
442 | 694 | move_obj = self.pool.get('stock.move') | 696 | move_obj = self.pool.get('stock.move') |
443 | @@ -698,7 +700,7 @@ | |||
444 | 698 | default['origin'] = '' | 700 | default['origin'] = '' |
445 | 699 | default['backorder_id'] = False | 701 | default['backorder_id'] = False |
446 | 700 | res = super(stock_picking, self).copy(cr, uid, id, default, context) | 702 | res = super(stock_picking, self).copy(cr, uid, id, default, context) |
448 | 701 | if self._keep_prodlot_hook(cr, uid, id, context, res=res): | 703 | if self._erase_prodlot_hook(cr, uid, id, context=context, res=res): |
449 | 702 | picking_obj = self.browse(cr, uid, res, context=context) | 704 | picking_obj = self.browse(cr, uid, res, context=context) |
450 | 703 | for move in picking_obj.move_lines: | 705 | for move in picking_obj.move_lines: |
451 | 704 | move_obj.write(cr, uid, [move.id], {'tracking_id': False,'prodlot_id':False}) | 706 | move_obj.write(cr, uid, [move.id], {'tracking_id': False,'prodlot_id':False}) |
452 | @@ -731,16 +733,28 @@ | |||
453 | 731 | def test_auto_picking(self, cr, uid, ids): | 733 | def test_auto_picking(self, cr, uid, ids): |
454 | 732 | # TODO: Check locations to see if in the same location ? | 734 | # TODO: Check locations to see if in the same location ? |
455 | 733 | return True | 735 | return True |
456 | 736 | |||
457 | 737 | def _hook_action_assign_raise_exception(self, cr, uid, ids, context=None, *args, **kwargs): | ||
458 | 738 | ''' | ||
459 | 739 | Please copy this to your module's method also. | ||
460 | 740 | This hook belongs to the action_assign method from stock>stock.py>stock_picking class | ||
461 | 741 | |||
462 | 742 | - allow to choose wether or not an exception should be raised in case of no stock move | ||
463 | 743 | ''' | ||
464 | 744 | return True | ||
465 | 734 | 745 | ||
467 | 735 | def action_assign(self, cr, uid, ids, *args): | 746 | def action_assign(self, cr, uid, ids, context=None, *args): |
468 | 736 | """ Changes state of picking to available if all moves are confirmed. | 747 | """ Changes state of picking to available if all moves are confirmed. |
469 | 737 | @return: True | 748 | @return: True |
470 | 738 | """ | 749 | """ |
471 | 750 | if context is None: | ||
472 | 751 | context = {} | ||
473 | 739 | move_obj = self.pool.get('stock.move') | 752 | move_obj = self.pool.get('stock.move') |
474 | 740 | for pick in self.browse(cr, uid, ids): | 753 | for pick in self.browse(cr, uid, ids): |
475 | 741 | move_ids = [x.id for x in pick.move_lines if x.state == 'confirmed'] | 754 | move_ids = [x.id for x in pick.move_lines if x.state == 'confirmed'] |
476 | 742 | if not move_ids: | 755 | if not move_ids: |
478 | 743 | raise osv.except_osv(_('Warning !'),_('Not enough stock, unable to reserve the products.')) | 756 | if self._hook_action_assign_raise_exception(cr, uid, ids, context=context,): |
479 | 757 | raise osv.except_osv(_('Warning !'),_('Not enough stock, unable to reserve the products.')) | ||
480 | 744 | move_obj.action_assign(cr, uid, move_ids) | 758 | move_obj.action_assign(cr, uid, move_ids) |
481 | 745 | return True | 759 | return True |
482 | 746 | 760 |