Merge lp:~donkirkby/openobject-addons/complete-procurement into lp:openobject-addons/5.0

Proposed by Don Kirkby
Status: Merged
Merged at revision: 2922
Proposed branch: lp:~donkirkby/openobject-addons/complete-procurement
Merge into: lp:openobject-addons/5.0
Diff against target: 164 lines (+135/-2)
3 files modified
mrp/__terp__.py (+1/-1)
mrp/mrp_test.xml (+122/-0)
purchase/purchase.py (+12/-1)
To merge this branch: bzr merge lp:~donkirkby/openobject-addons/complete-procurement
Reviewer Review Type Date Requested Status
Olivier Dony (Odoo) Approve
OpenERP Core Team Pending
Review via email: mp+20694@code.launchpad.net

Description of the change

This now fixes bug lp:532148, as well as adding a unit test that shows the problem.

To post a comment you must log in.
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Excellent, we'll merge this along with the bugfix.

I also propose to start putting the tests into a separate test/ subdirectory in each module, in case we have many of them (and we'll also put the future yaml ones there as well)

Many thanks for helping up with the regression testing!

review: Approve
Revision history for this message
Don Kirkby (donkirkby) wrote :

OK, the branch now contains a fix as well as the unit test. Please review again.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'mrp/__terp__.py'
2--- mrp/__terp__.py 2009-02-03 17:02:20 +0000
3+++ mrp/__terp__.py 2011-01-06 23:27:08 +0000
4@@ -72,7 +72,7 @@
5 'process/service_product_process.xml',
6 'process/procurement_process.xml'
7 ],
8- 'demo_xml': ['mrp_demo.xml', 'mrp_order_point.xml'],
9+ 'demo_xml': ['mrp_demo.xml', 'mrp_order_point.xml', 'mrp_test.xml'],
10 'installable': True,
11 'active': False,
12 'certificate': '0032052481373',
13
14=== added file 'mrp/mrp_test.xml'
15--- mrp/mrp_test.xml 1970-01-01 00:00:00 +0000
16+++ mrp/mrp_test.xml 2011-01-06 23:27:08 +0000
17@@ -0,0 +1,122 @@
18+<?xml version="1.0" encoding="UTF-8"?>
19+<openerp>
20+ <data>
21+
22+ <!-- ================================================================
23+ Smoke test for automated purchase process.
24+
25+ 0. Create a procurement order
26+ 1. Run the procurement
27+ 2. Check that the purchase order was created
28+ 3. Confirm the purchase order
29+ 4. Receive the goods
30+ 5. Check that the procurement order was marked as done.
31+
32+ ================================================================
33+ -->
34+
35+ <!-- ==== 0. Create a procurement order ==== -->
36+ <record id="test_procurement_1" model="mrp.procurement">
37+ <field name="product_uom" ref="product.product_uom_unit"/>
38+ <field eval="3.0" name="product_qty"/>
39+ <field name="product_uos" ref="product.product_uom_unit"/>
40+ <field name="location_id" ref="stock.stock_location_stock"/>
41+ <field eval="0" name="close_move"/>
42+ <field name="name">test</field>
43+ <field name="procure_method">make_to_order</field>
44+ <field name="product_id" ref="product.product_product_mb1"/>
45+ </record>
46+
47+ <!-- ==== 1. Run the procurement ==== -->
48+ <workflow
49+ model="mrp.procurement"
50+ ref="test_procurement_1"
51+ action="button_confirm" />
52+ <workflow
53+ model="mrp.procurement"
54+ ref="test_procurement_1"
55+ action="button_check" />
56+
57+ <!-- ==== 2. Check that the purchase order was created ==== -->
58+ <assert
59+ model="mrp.procurement"
60+ id="test_procurement_1"
61+ string="Test procurement's purchase order state">
62+ <test expr="purchase_id.state">draft</test>
63+ </assert>
64+ <assert
65+ model="mrp.procurement"
66+ id="test_procurement_1"
67+ string="Test procurement's state">
68+ <test expr="state">running</test>
69+ </assert>
70+
71+ <!-- ==== 3. Confirm the purchase order ==== -->
72+ <workflow model="purchase.order" action="purchase_confirm" >
73+ <value
74+ model="mrp.procurement"
75+ eval="obj(ref('test_procurement_1')).purchase_id.id"/>
76+ </workflow>
77+
78+ <assert
79+ model="mrp.procurement"
80+ id="test_procurement_1"
81+ string="Test procurement's purchase order state">
82+ <test expr="purchase_id.state">confirmed</test>
83+ </assert>
84+
85+ <workflow
86+ model="purchase.order"
87+ action="purchase_approve"
88+ uid="base.user_root" >
89+ <value
90+ model="mrp.procurement"
91+ eval="obj(ref('test_procurement_1')).purchase_id.id"/>
92+ </workflow>
93+
94+ <assert
95+ model="mrp.procurement"
96+ id="test_procurement_1"
97+ string="Test procurement's purchase order state">
98+ <test expr="purchase_id.state">approved</test>
99+ </assert>
100+
101+ <!-- ==== 4. Receive the goods ==== -->
102+ <!-- Do the same as in wizard_partial_picking lines 143-144
103+ (copied from purchase_unit_test.xml) -->
104+ <function model="stock.picking" name="action_move">
105+ <value
106+ model="mrp.procurement"
107+ eval="[obj(ref('test_procurement_1')).purchase_id.picking_ids[0].id]"/>
108+ </function>
109+
110+ <workflow model="stock.picking" action="button_done">
111+ <value
112+ model="mrp.procurement"
113+ eval="obj(ref('test_procurement_1')).purchase_id.picking_ids[0].id"/>
114+ </workflow>
115+
116+ <!-- ==== 5. Check that the procurement order was marked as done. ==== -->
117+ <assert
118+ model="mrp.procurement"
119+ id="test_procurement_1"
120+ string="Test procurement's purchase order's picking's state">
121+ <test expr="purchase_id.picking_ids[0].state">done</test>
122+ </assert>
123+
124+ <assert
125+ model="mrp.procurement"
126+ id="test_procurement_1"
127+ string="Test procurement's purchase order's state">
128+ <!-- not done because we didn't process the invoice. -->
129+ <test expr="purchase_id.state">approved</test>
130+ </assert>
131+
132+ <assert
133+ model="mrp.procurement"
134+ id="test_procurement_1"
135+ string="Test procurement's state">
136+ <test expr="state">done</test>
137+ </assert>
138+ </data>
139+</openerp>
140\ No newline at end of file
141
142=== modified file 'purchase/purchase.py'
143--- purchase/purchase.py 2010-09-03 10:10:26 +0000
144+++ purchase/purchase.py 2011-01-06 23:27:08 +0000
145@@ -424,7 +424,18 @@
146 'purchase_line_id': order_line.id,
147 })
148 if order_line.move_dest_id:
149- self.pool.get('stock.move').write(cr, uid, [order_line.move_dest_id.id], {'location_id':order.location_id.id})
150+ # make the procurement's stock move into a dummy move
151+ # (source == destination) and mark it as auto validate
152+ # so that the procurement will complete when the
153+ # purchase shipment arrives.
154+ self.pool.get('stock.move').write(
155+ cr,
156+ uid,
157+ [order_line.move_dest_id.id],
158+ {
159+ 'location_id': order.location_id.id,
160+ 'auto_validate': True
161+ })
162 todo_moves.append(move)
163 self.pool.get('stock.move').action_confirm(cr, uid, todo_moves)
164 self.pool.get('stock.move').force_assign(cr, uid, todo_moves)