[IMP] sale_mrp: bom and property tests

-Test the function _bom_find to check that it searches the bom corresponding
	 to the properties passed or takes the bom with the smallest sequence.
	For this commit: d357667df4279070b51af58cad55ef314688d69f

	- Test the function _bom_explode to check that it only takes the lines with the
	 right properties.
	For this commit: 6b6e71a3e0c86aa8a9b8c4f20eaa61b17c64ce7b
This commit is contained in:
Goffin Simon 2015-04-27 12:20:04 +02:00
parent 8a7993958d
commit 4775c24af7
2 changed files with 81 additions and 1 deletions

View File

@ -454,6 +454,25 @@
<field name="type">normal</field>
</record>
<record id="mrp_bom_property_0" model="mrp.bom">
<field name="name">PC Assemble + DDR 512MB</field>
<field name="product_tmpl_id" ref="product.product_product_3_product_template"/>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="sequence">5</field>
<field name="type">normal</field>
<field name="property_ids" eval="[(6,0,[ref('mrp_property_0')])]"/>
</record>
<record id="mrp_bom_property_line" model="mrp.bom">
<field name="name">RAM SR2 PLUS</field>
<field name="product_id" ref="product.product_product_14"/>
<field name="product_tmpl_id" ref="product.product_product_14_product_template"/>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="sequence">5</field>
<field name="type">phantom</field>
<field name="property_ids" eval="[(6,0,[ref('mrp_property_0')])]"/>
</record>
<record id="mrp_bom_line_17" model="mrp.bom.line">
<field name="product_id" ref="product.product_product_6"/>
<field name="product_qty">1</field>
@ -641,6 +660,35 @@
<field name="bom_id" ref="mrp_bom_11"/>
</record>
<record id="mrp_bom_line_prop_1" model="mrp.bom.line">
<field name="product_id" ref="product.product_product_13"/>
<field name="product_qty">1</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="sequence">1</field>
<field name="type">normal</field>
<field name="property_ids" eval="[(6,0,[ref('mrp_property_8')])]"/>
<field name="bom_id" ref="mrp_bom_property_line"/>
</record>
<record id="mrp_bom_line_prop_2" model="mrp.bom.line">
<field name="product_id" ref="product.product_product_12"/>
<field name="product_qty">1</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="sequence">1</field>
<field name="type">normal</field>
<field name="property_ids" eval="[(6,0,[ref('mrp_property_0')])]"/>
<field name="bom_id" ref="mrp_bom_property_line"/>
</record>
<record id="mrp_bom_line_prop_3" model="mrp.bom.line">
<field name="product_id" ref="product.product_product_11"/>
<field name="product_qty">1</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="sequence">1</field>
<field name="type">normal</field>
<field name="bom_id" ref="mrp_bom_property_line"/>
</record>
<record id="mrp_production_1" model="mrp.production">
<field name="product_id" ref="product.product_product_3"/>

View File

@ -33,6 +33,7 @@ class TestMoveExplode(common.TransactionCase):
self.sale_order_line = self.registry('sale.order.line')
self.sale_order = self.registry('sale.order')
self.mrp_bom = self.registry('mrp.bom')
self.product = self.registry('product.product')
#product that has a phantom bom
self.product_bom_id = self.ir_model_data.get_object_reference(cr, uid, 'product', 'product_product_3')[1]
@ -40,9 +41,24 @@ class TestMoveExplode(common.TransactionCase):
self.bom_id = self.ir_model_data.get_object_reference(cr, uid, 'mrp', 'mrp_bom_9')[1]
#partner agrolait
self.partner_id = self.ir_model_data.get_object_reference(cr, uid, 'base', 'res_partner_1')[1]
#bom: PC Assemble (with property: DDR 512MB)
self.bom_prop_id = self.ir_model_data.get_object_reference(cr, uid, 'mrp', 'mrp_bom_property_0')[1]
self.template_id = self.ir_model_data.get_object_reference(cr, uid, 'product', 'product_product_3_product_template')[1]
#property: DDR 512MB
self.mrp_property_id = self.ir_model_data.get_object_reference(cr, uid, 'mrp', 'mrp_property_0')[1]
#product: RAM SR2
self.product_bom_prop_id = self.ir_model_data.get_object_reference(cr, uid, 'product', 'product_product_14')[1]
#phantom bom for RAM SR2 with three lines containing properties
self.bom_prop_line_id = self.ir_model_data.get_object_reference(cr, uid, 'mrp', 'mrp_bom_property_line')[1]
#product: iPod included in the phantom bom
self.product_A_id = self.ir_model_data.get_object_reference(cr, uid, 'product', 'product_product_11')[1]
#product: Mouse, Wireless included in the phantom bom
self.product_B_id = self.ir_model_data.get_object_reference(cr, uid, 'product', 'product_product_12')[1]
def test_00_sale_move_explode(self):
"""check that when creating a sale order with a product that has a phantom BoM, move explode into content of the
"""check that when creating a sale order with a product that has a phantom BoM, move explode into content of the
BoM"""
cr, uid, context = self.cr, self.uid, {}
#create sale order with one sale order line containing product with a phantom bom
@ -57,3 +73,19 @@ class TestMoveExplode(common.TransactionCase):
bom = self.mrp_bom.browse(cr, uid, self.bom_id, context=context)
bom_component_length = self.mrp_bom._bom_explode(cr, uid, bom, self.product_bom_id, 1, [])
self.assertEqual(len(move_ids), len(bom_component_length[0]))
def test_00_bom_find(self):
"""Check that _bom_find searches the bom corresponding to the properties passed or takes the bom with the smallest
sequence."""
cr, uid, context = self.cr, self.uid, {}
res_id = self.mrp_bom._bom_find(cr, uid, product_tmpl_id=self.template_id, product_id=None, properties=[self.mrp_property_id], context=context)
self.assertEqual(res_id, self.bom_prop_id)
def test_00_bom_explode(self):
"""Check that _bom_explode only takes the lines with the right properties."""
cr, uid, context = self.cr, self.uid, {}
bom = self.mrp_bom.browse(cr, uid, self.bom_prop_line_id)
product = self.product.browse(cr, uid, self.product_bom_prop_id)
res = self.mrp_bom._bom_explode(cr, uid, bom, product, 1, properties=[self.mrp_property_id], context=context)
res = set([p['product_id'] for p in res[0]])
self.assertEqual(res, set([self.product_A_id, self.product_B_id]))