Merge lp:~zaber/openobject-addons/phantom-bom-moves into lp:openobject-addons/5.0

Proposed by Don Kirkby
Status: Needs review
Proposed branch: lp:~zaber/openobject-addons/phantom-bom-moves
Merge into: lp:openobject-addons/5.0
Diff against target: 381 lines (+264/-22)
5 files modified
mrp/mrp.py (+6/-7)
mrp/mrp_demo.xml (+2/-15)
mrp_jit/test/mrp_jit_test.xml (+108/-0)
product/product_demo.xml (+2/-0)
sale/test/sale_test.xml (+146/-0)
To merge this branch: bzr merge lp:~zaber/openobject-addons/phantom-bom-moves
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+45582@code.launchpad.net

Description of the change

Test and bug fix for bug lp:700154.

To post a comment you must log in.

Unmerged revisions

2881. By Don Kirkby

[FIX] Link move_dest_id to original phantom product move for bug lp:700154.

2880. By Don Kirkby

[FIX] Call action_confirm() to fix part of bug lp:700154.

2879. By Don Kirkby

[IMP] Add failing test for bug lp:700154 phantom BOM sales order

2878. By Don Kirkby

[MERGE] tweak demo data so that we can sell a product with a phantom BOM (PC0). Merged from phantom-bom-workflow branch.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'mrp/mrp.py'
--- mrp/mrp.py 2010-12-30 06:18:22 +0000
+++ mrp/mrp.py 2011-01-07 23:47:54 +0000
@@ -1208,9 +1208,6 @@
1208 factor = move.product_qty1208 factor = move.product_qty
1209 bom_point = self.pool.get('mrp.bom').browse(cr, uid, bis[0])1209 bom_point = self.pool.get('mrp.bom').browse(cr, uid, bis[0])
1210 res = self.pool.get('mrp.bom')._bom_explode(cr, uid, bom_point, factor, [])1210 res = self.pool.get('mrp.bom')._bom_explode(cr, uid, bom_point, factor, [])
1211 state = 'confirmed'
1212 if move.state=='assigned':
1213 state='assigned'
1214 for line in res[0]:1211 for line in res[0]:
1215 valdef = {1212 valdef = {
1216 'picking_id': move.picking_id.id,1213 'picking_id': move.picking_id.id,
@@ -1219,13 +1216,15 @@
1219 'product_qty': line['product_qty'],1216 'product_qty': line['product_qty'],
1220 'product_uos': line['product_uos'],1217 'product_uos': line['product_uos'],
1221 'product_uos_qty': line['product_uos_qty'],1218 'product_uos_qty': line['product_uos_qty'],
1222 'state': state,1219 'state': 'draft',
1223 'name': line['name'],1220 'name': line['name'],
1221 'move_dest_id': move.id,
1224 'move_history_ids': [(6,0,[move.id])],1222 'move_history_ids': [(6,0,[move.id])],
1225 'move_history_ids2': [(6,0,[])],1223 'move_history_ids2': [(6,0,[])],
1226 'procurements': []1224 'procurements': []
1227 }1225 }
1228 mid = self.pool.get('stock.move').copy(cr, uid, move.id, default=valdef)1226 mid = self.pool.get('stock.move').copy(cr, uid, move.id, default=valdef)
1227 self.action_confirm(cr, uid, [mid], context)
1229 prodobj = self.pool.get('product.product').browse(cr, uid, line['product_id'], context=context)1228 prodobj = self.pool.get('product.product').browse(cr, uid, line['product_id'], context=context)
1230 proc_id = self.pool.get('mrp.procurement').create(cr, uid, {1229 proc_id = self.pool.get('mrp.procurement').create(cr, uid, {
1231 'name': (move.picking_id.origin or ''),1230 'name': (move.picking_id.origin or ''),
@@ -1272,10 +1271,10 @@
1272 #1271 #
1273 # Explode picking by replacing phantom BoMs1272 # Explode picking by replacing phantom BoMs
1274 #1273 #
1275 def action_explode(self, cr, uid, picks, *args):1274 def action_explode(self, cr, uid, moves, *args):
1276 for move in self.pool.get('stock.move').browse(cr, uid, picks):1275 for move in self.pool.get('stock.move').browse(cr, uid, moves):
1277 self.pool.get('stock.move')._action_explode(cr, uid, move)1276 self.pool.get('stock.move')._action_explode(cr, uid, move)
1278 return picks1277 return moves
12791278
1280StockPicking()1279StockPicking()
12811280
12821281
=== modified file 'mrp/mrp_demo.xml'
--- mrp/mrp_demo.xml 2010-02-17 12:18:07 +0000
+++ mrp/mrp_demo.xml 2011-01-07 23:47:54 +0000
@@ -238,12 +238,6 @@
238 <field name="name">Complete PC with peripherals</field>238 <field name="name">Complete PC with peripherals</field>
239 <field name="product_uom" ref="product.product_uom_unit"/>239 <field name="product_uom" ref="product.product_uom_unit"/>
240 <field name="product_qty">1.0</field>240 <field name="product_qty">1.0</field>
241 <field model="product.product" name="product_id" ref="product.product_product_23"/>
242 </record>
243 <record id="mrp_bom_11" model="mrp.bom">
244 <field name="name">RAM on demand</field>
245 <field name="product_uom" ref="product.product_uom_unit"/>
246 <field name="product_qty">1.0</field>
247 <field name="type">phantom</field>241 <field name="type">phantom</field>
248 <field model="product.product" name="product_id" ref="product.product_product_23"/>242 <field model="product.product" name="product_id" ref="product.product_product_23"/>
249 </record>243 </record>
@@ -260,9 +254,9 @@
260 <field name="name">Kit Mouse</field>254 <field name="name">Kit Mouse</field>
261 <field name="product_uom" ref="product.product_uom_unit"/>255 <field name="product_uom" ref="product.product_uom_unit"/>
262 <field name="product_qty">1.0</field>256 <field name="product_qty">1.0</field>
263 <field name="type">normal</field>257 <field name="type">phantom</field>
264 <field name="bom_id" ref="mrp_bom_10"/>258 <field name="bom_id" ref="mrp_bom_10"/>
265 <field model="product.product" name="product_id" ref="product.product_product_25"/>259 <field model="product.product" name="product_id" ref="product.product_product_26"/>
266 </record>260 </record>
267 <record id="mrp_bom_clavier" model="mrp.bom">261 <record id="mrp_bom_clavier" model="mrp.bom">
268 <field name="name">Keyboard</field>262 <field name="name">Keyboard</field>
@@ -306,13 +300,6 @@
306 <field name="bom_id" ref="mrp_bom_13"/>300 <field name="bom_id" ref="mrp_bom_13"/>
307 <field model="product.product" name="product_id" ref="product.product_product_fan"/>301 <field model="product.product" name="product_id" ref="product.product_product_fan"/>
308 </record>302 </record>
309 <record id="mrp_bom_23" model="mrp.bom">
310 <field name="name">DDR 256MB PC333</field>
311 <field name="product_uom" ref="product.product_uom_unit"/>
312 <field name="product_qty">1.0</field>
313 <field name="bom_id" ref="mrp_bom_11"/>
314 <field model="product.product" name="product_id" ref="product.product_product_ram"/>
315 </record>
316 <record id="mrp_bom_1901" model="mrp.bom">303 <record id="mrp_bom_1901" model="mrp.bom">
317 <field name="name">DDR 512MB PC400</field>304 <field name="name">DDR 512MB PC400</field>
318 <field name="product_uom" ref="product.product_uom_unit"/>305 <field name="product_uom" ref="product.product_uom_unit"/>
319306
=== modified file 'mrp_jit/test/mrp_jit_test.xml'
--- mrp_jit/test/mrp_jit_test.xml 2010-03-11 13:05:02 +0000
+++ mrp_jit/test/mrp_jit_test.xml 2011-01-07 23:47:54 +0000
@@ -166,6 +166,114 @@
166 <assert id="smoke_test_sale_order" model="sale.order" string="the sale order is now done">166 <assert id="smoke_test_sale_order" model="sale.order" string="the sale order is now done">
167 <test expr="state">done</test>167 <test expr="state">done</test>
168 </assert>168 </assert>
169
170
171
172 <!-- ================================================================
173 Test phantom bill of materials with MRP-JIT installed,
174 based on a similar smoke test in 'sale' module
175
176 0. Check that the set product is configured correctly
177 1. creates a simple sale order with 1 line using a set product
178 2. confirms the sale order
179 3. Check that a chained move got created for each component
180 4. Check that no production order is created
181
182 ================================================================
183 -->
184
185 <!-- ==== 0. Check that the set product is configured correctly ==== -->
186 <assert
187 id="product.product_product_23"
188 model="product.product"
189 string="The PC with peripherals product is configured as a set.">
190 <test expr="name">Complete PC With Peripherals</test>
191 <test expr="code">PC0</test>
192 <test expr="supply_method">produce</test>
193 <test expr="procure_method">make_to_order</test>
194 </assert>
195 <assert
196 id="mrp.mrp_bom_10"
197 model="mrp.bom"
198 string="The PC with peripherals product has a phantom BOM.">
199 <test expr="type">phantom</test>
200 <test expr="product_id.code">PC0</test>
201 </assert>
202 <assert
203 id="product.product_product_26"
204 model="product.product"
205 string="The keyboard + mouse product is configured as a set.">
206 <test expr="name">Kit Keyboard + Mouse</test>
207 <test expr="code">KIT0</test>
208 <test expr="supply_method">produce</test>
209 <test expr="procure_method">make_to_order</test>
210 </assert>
211 <assert
212 id="mrp.mrp_bom_kit"
213 model="mrp.bom"
214 string="The keyboard + mouse product has a phantom BOM.">
215 <test expr="type">phantom</test>
216 <test expr="product_id.code">KIT0</test>
217 </assert>
218
219 <!-- ==== 1. creates a simple sale order with 1 line using a set product ==== -->
220 <!-- Resource: sale.order -->
221 <record id="phantom_sale_order" model="sale.order">
222 <field name="shop_id" ref="sale.shop"/>
223 <field model="product.pricelist" name="pricelist_id" search="[]"/>
224 <field name="user_id" ref="base.user_root"/>
225 <field model="res.partner" name="partner_id" search="[]"/>
226 <field name="order_policy">manual</field> <!-- force manual invoicing -->
227 <field name="picking_policy">one</field> <!-- full delivery only -->
228 <field name="invoice_quantity">order</field> <!-- invoice based on ordered quantities -->
229 <field model="res.partner.address" name="partner_invoice_id" search="[]"/>
230 <field model="res.partner.address" name="partner_shipping_id" search="[]"/>
231 <field model="res.partner.address" name="partner_order_id" search="[]"/>
232 <field name="name">SO-PHANTOM-JIT</field>
233 </record>
234 <record id="phantom_sale_order_line_1" model="sale.order.line">
235 <field name="order_id" ref="phantom_sale_order"/>
236 <field name="name">[PC0] Complete PC With Peripherals</field>
237 <field name="product_id" ref="product.product_product_23"/>
238 <field name="product_uom" ref="product.product_uom_unit"/>
239 <field name="price_unit">750</field>
240 <field name="product_uom_qty">1</field>
241 <field name="product_uos_qty">1</field>
242 <field name="type">make_to_order</field>
243 </record>
244
245 <!-- ==== 2. confirms the sale order ==== -->
246 <workflow action="order_confirm" model="sale.order" ref="phantom_sale_order"/>
247
248 <assert
249 id="phantom_sale_order"
250 model="sale.order"
251 string="the sale order is now in 'Manual in progress' state">
252 <test expr="state">manual</test>
253 </assert>
254
255 <!-- ==== 3. Check that both packing lists contain set contents ==== -->
256 <assert
257 model="sale.order"
258 id="phantom_sale_order"
259 string="stock moves for phantom product (stock to output and output to cust)">
260 <test expr="str(len(order_line[0].move_ids)) + ' stock moves'">7 stock moves</test>
261 <test expr="order_line[0].move_ids[0].product_id.code">PC0</test>
262 <test expr="order_line[0].move_ids[1].product_id.code + ' - ' + order_line[0].move_ids[1].picking_id.type">KEYA - out</test>
263 <test expr="order_line[0].move_ids[2].product_id.code + ' - ' + order_line[0].move_ids[2].picking_id.type">KEYA - delivery</test>
264 <test expr="order_line[0].move_ids[3].product_id.code + ' - ' + order_line[0].move_ids[3].picking_id.type">MOU - out</test>
265 <test expr="order_line[0].move_ids[4].product_id.code + ' - ' + order_line[0].move_ids[4].picking_id.type">MOU - delivery</test>
266 <test expr="order_line[0].move_ids[5].product_id.code + ' - ' + order_line[0].move_ids[5].picking_id.type">PC1 - out</test>
267 <test expr="order_line[0].move_ids[6].product_id.code + ' - ' + order_line[0].move_ids[6].picking_id.type">PC1 - delivery</test>
268 </assert>
269
270 <!-- ==== 4. Check that no production order is created ==== -->
271 <assert
272 model="mrp.production"
273 search="[('product_id', '=', ref('product.product_product_23'))]"
274 string="There should not be any production orders for the set product">
275 <test expr="False"/>
276 </assert>
169 </data>277 </data>
170 278
171 <data>279 <data>
172280
=== modified file 'product/product_demo.xml'
--- product/product_demo.xml 2010-04-23 13:26:04 +0000
+++ product/product_demo.xml 2011-01-07 23:47:54 +0000
@@ -349,6 +349,7 @@
349 <record id="product_product_23" model="product.product">349 <record id="product_product_23" model="product.product">
350 <field name="default_code">PC0</field>350 <field name="default_code">PC0</field>
351 <field name="supply_method">produce</field>351 <field name="supply_method">produce</field>
352 <field name="procure_method">make_to_order</field>
352 <field name="list_price">750.0</field>353 <field name="list_price">750.0</field>
353 <field name="standard_price">500.0</field>354 <field name="standard_price">500.0</field>
354 <field name="uom_id" ref="product_uom_unit"/>355 <field name="uom_id" ref="product_uom_unit"/>
@@ -378,6 +379,7 @@
378 <record id="product_product_26" model="product.product">379 <record id="product_product_26" model="product.product">
379 <field name="default_code">KIT0</field>380 <field name="default_code">KIT0</field>
380 <field name="supply_method">produce</field>381 <field name="supply_method">produce</field>
382 <field name="procure_method">make_to_order</field>
381 <field name="list_price">7.0</field>383 <field name="list_price">7.0</field>
382 <field name="standard_price">5.0</field>384 <field name="standard_price">5.0</field>
383 <field name="uom_id" ref="product_uom_unit"/>385 <field name="uom_id" ref="product_uom_unit"/>
384386
=== modified file 'sale/test/sale_test.xml'
--- sale/test/sale_test.xml 2010-06-10 13:40:19 +0000
+++ sale/test/sale_test.xml 2011-01-07 23:47:54 +0000
@@ -173,6 +173,152 @@
173 <assert id="smoke_test_sale_order" model="sale.order" string="the sale order is now done">173 <assert id="smoke_test_sale_order" model="sale.order" string="the sale order is now done">
174 <test expr="state">done</test>174 <test expr="state">done</test>
175 </assert>175 </assert>
176
177
178 <!-- ================================================================
179 Test phantom bill of materials
180
181 0. Check that the set product is configured correctly
182 1. creates a simple sale order with 1 line using a set product
183 2. confirms the sale order
184 3. Check that a chained move got created for each component
185 4. Check that no production order is created
186 5. Picking: check availability
187 6. Make the delivery
188 7. Verify that everything is done
189
190 ================================================================
191 -->
192
193 <!-- ==== 0. Check that the set product is configured correctly ==== -->
194 <assert
195 id="product.product_product_23"
196 model="product.product"
197 string="The PC with peripherals product is configured as a set.">
198 <test expr="name">Complete PC With Peripherals</test>
199 <test expr="code">PC0</test>
200 <test expr="supply_method">produce</test>
201 <test expr="procure_method">make_to_order</test>
202 </assert>
203 <assert
204 id="mrp.mrp_bom_10"
205 model="mrp.bom"
206 string="The PC with peripherals product has a phantom BOM.">
207 <test expr="type">phantom</test>
208 <test expr="product_id.code">PC0</test>
209 </assert>
210 <assert
211 id="product.product_product_26"
212 model="product.product"
213 string="The keyboard + mouse product is configured as a set.">
214 <test expr="name">Kit Keyboard + Mouse</test>
215 <test expr="code">KIT0</test>
216 <test expr="supply_method">produce</test>
217 <test expr="procure_method">make_to_order</test>
218 </assert>
219 <assert
220 id="mrp.mrp_bom_kit"
221 model="mrp.bom"
222 string="The keyboard + mouse product has a phantom BOM.">
223 <test expr="type">phantom</test>
224 <test expr="product_id.code">KIT0</test>
225 </assert>
226
227 <!-- ==== 1. creates a simple sale order with 1 line using a set product ==== -->
228 <!-- Resource: sale.order -->
229 <record id="phantom_sale_order" model="sale.order">
230 <field name="shop_id" ref="shop"/>
231 <field model="product.pricelist" name="pricelist_id" search="[]"/>
232 <field name="user_id" ref="base.user_root"/>
233 <field model="res.partner" name="partner_id" search="[]"/>
234 <field name="order_policy">manual</field> <!-- force manual invoicing -->
235 <field name="picking_policy">one</field> <!-- full delivery only -->
236 <field name="invoice_quantity">order</field> <!-- invoice based on ordered quantities -->
237 <field model="res.partner.address" name="partner_invoice_id" search="[]"/>
238 <field model="res.partner.address" name="partner_shipping_id" search="[]"/>
239 <field model="res.partner.address" name="partner_order_id" search="[]"/>
240 <field name="name">SO-PHANTOM</field>
241 </record>
242 <record id="phantom_sale_order_line_1" model="sale.order.line">
243 <field name="order_id" ref="phantom_sale_order"/>
244 <field name="name">[PC0] Complete PC With Peripherals</field>
245 <field name="product_id" ref="product.product_product_23"/>
246 <field name="product_uom" ref="product.product_uom_unit"/>
247 <field name="price_unit">750</field>
248 <field name="product_uom_qty">1</field>
249 <field name="product_uos_qty">1</field>
250 <field name="type">make_to_order</field>
251 </record>
252
253 <!-- ==== 2. confirms the sale order ==== -->
254 <workflow action="order_confirm" model="sale.order" ref="phantom_sale_order"/>
255
256 <assert
257 id="phantom_sale_order"
258 model="sale.order"
259 string="the sale order is now in 'Manual in progress' state">
260 <test expr="state">manual</test>
261 </assert>
262
263 <!-- ==== 3. Check that a chained move got created for each component ==== -->
264 <assert
265 model="sale.order"
266 id="phantom_sale_order"
267 string="stock moves for phantom product (stock to output and output to cust)">
268 <test expr="str(len(order_line[0].move_ids)) + ' stock moves'">7 stock moves</test>
269 <test expr="order_line[0].move_ids[0].product_id.code">PC0</test>
270 <test expr="order_line[0].move_ids[1].product_id.code + ' - ' + order_line[0].move_ids[1].picking_id.type">KEYA - out</test>
271 <test expr="order_line[0].move_ids[2].product_id.code + ' - ' + order_line[0].move_ids[2].picking_id.type">KEYA - delivery</test>
272 <test expr="order_line[0].move_ids[3].product_id.code + ' - ' + order_line[0].move_ids[3].picking_id.type">MOU - out</test>
273 <test expr="order_line[0].move_ids[4].product_id.code + ' - ' + order_line[0].move_ids[4].picking_id.type">MOU - delivery</test>
274 <test expr="order_line[0].move_ids[5].product_id.code + ' - ' + order_line[0].move_ids[5].picking_id.type">PC1 - out</test>
275 <test expr="order_line[0].move_ids[6].product_id.code + ' - ' + order_line[0].move_ids[6].picking_id.type">PC1 - delivery</test>
276 </assert>
277
278 <!-- ==== 4. Check that no production order is created ==== -->
279 <assert
280 model="mrp.production"
281 search="[('product_id', '=', ref('product.product_product_23'))]"
282 string="There should not be any production orders for the set product">
283 <test expr="False"/>
284 </assert>
285 <!-- ==== 5. Picking: check availability ==== -->
286 <!-- Here we need to directly call the function tag because action_assign is a method of stock_picking and not part of the workflow -->
287 <function model="stock.picking" name="action_assign">
288 <value eval="[obj(ref('phantom_sale_order')).picking_ids[0].id]" model="sale.order"/>
289 </function>
290 <assert id="phantom_sale_order" model="sale.order" severity="error" string="the sale order's picking is now assigned">
291 <test expr="picking_ids[0].state">assigned</test>
292 </assert>
293
294 <!-- The above step could also be replaced by the following call to the mrp schedulers: -->
295 <!-- <function model="mrp.procurement" name="run_scheduler"/> -->
296
297 <!-- ==== 6. Make the delivery ==== -->
298 <!-- See wizard_picking_make or wizard_partial_picking in stock module. -->
299 <function model="stock.picking" name="action_move">
300 <value eval="[obj(ref('phantom_sale_order')).picking_ids[0].id]" model="sale.order"/>
301 </function>
302 <workflow action="button_done" model="stock.picking">
303 <value eval="obj(ref('phantom_sale_order')).picking_ids[0].id" model="sale.order"/>
304 </workflow>
305 <function model="stock.picking" name="action_move">
306 <value eval="[obj(ref('phantom_sale_order')).order_line[0].move_ids[6].picking_id.id]" model="sale.order"/>
307 </function>
308 <workflow action="button_done" model="stock.picking">
309 <value eval="obj(ref('phantom_sale_order')).order_line[0].move_ids[6].picking_id.id" model="sale.order"/>
310 </workflow>
311
312
313 <!-- ==== 7. Verify that everything is done ==== -->
314 <assert id="phantom_sale_order" model="sale.order" string="the main procurement is now done">
315 <test expr="order_line[0].procurement_id.state">done</test>
316 </assert>
317 <assert id="phantom_sale_order" model="sale.order" string="the sale order's picking is now done">
318 <test expr="picking_ids[0].state">done</test>
319 <test expr="order_line[0].move_ids[3].picking_id.state">done</test>
320 <test expr="shipped == True"/>
321 </assert>
176 </data>322 </data>
177 323
178 324