def test_flow_5(self): """ Check that the correct BoM is chosen accordingly to the partner """ # We create a second partner of type subcontractor main_partner_2 = self.env['res.partner'].create( {'name': 'main_partner'}) subcontractor_partner2 = self.env['res.partner'].create({ 'name': 'subcontractor_partner', 'parent_id': main_partner_2.id, 'company_id': self.env.ref('base.main_company').id }) # We create a different BoM for the same product comp3 = self.env['product.product'].create({ 'name': 'Component1', 'type': 'product', 'categ_id': self.env.ref('product.product_category_all').id, }) bom_form = Form(self.env['mrp.bom']) bom_form.type = 'subcontract' bom_form.product_tmpl_id = self.finished.product_tmpl_id with bom_form.bom_line_ids.new() as bom_line: bom_line.product_id = self.comp1 bom_line.product_qty = 1 with bom_form.bom_line_ids.new() as bom_line: bom_line.product_id = comp3 bom_line.product_qty = 1 bom2 = bom_form.save() # We assign the second BoM to the new partner self.bom.write( {'subcontractor_ids': [(4, self.subcontractor_partner1.id, None)]}) bom2.write( {'subcontractor_ids': [(4, subcontractor_partner2.id, None)]}) # Create a receipt picking from the subcontractor1 picking_form = Form(self.env['stock.picking']) picking_form.picking_type_id = self.env.ref('stock.picking_type_in') picking_form.partner_id = self.subcontractor_partner1 with picking_form.move_ids_without_package.new() as move: move.product_id = self.finished move.product_uom_qty = 1 picking_receipt1 = picking_form.save() picking_receipt1.action_confirm() # Create a receipt picking from the subcontractor2 picking_form = Form(self.env['stock.picking']) picking_form.picking_type_id = self.env.ref('stock.picking_type_in') picking_form.partner_id = subcontractor_partner2 with picking_form.move_ids_without_package.new() as move: move.product_id = self.finished move.product_uom_qty = 1 picking_receipt2 = picking_form.save() picking_receipt2.action_confirm() mo_pick1 = picking_receipt1.move_lines.mapped( 'move_orig_ids.production_id') mo_pick2 = picking_receipt2.move_lines.mapped( 'move_orig_ids.production_id') self.assertEquals(len(mo_pick1), 1) self.assertEquals(len(mo_pick2), 1) self.assertEquals(mo_pick1.bom_id, self.bom) self.assertEquals(mo_pick2.bom_id, bom2)
def setUp(self): super(TestBom, self).setUp() self.Product = self.env['product.product'] self.Bom = self.env['mrp.bom'] self.Routing = self.env['mrp.routing'] self.operation = self.env['mrp.routing.workcenter'] # Products. self.dining_table = self._create_product('Dining Table', 1000) self.table_head = self._create_product('Table Head', 300) self.screw = self._create_product('Screw', 10) self.leg = self._create_product('Leg', 25) self.glass = self._create_product('Glass', 100) # Unit of Measure. self.unit = self.env.ref("uom.product_uom_unit") self.dozen = self.env.ref("uom.product_uom_dozen") # Bills Of Materials. # ------------------------------------------------------------------------------- # Cost of BoM (Dining Table 1 Unit) # Component Cost = Table Head 1 Unit * 300 = 300 (468.75 from it's components) # Screw 5 Unit * 10 = 50 # Leg 4 Unit * 25 = 100 # Glass 1 Unit * 100 = 100 # Total = 550 [718.75 if components of Table Head considered] (for 1 Unit) # ------------------------------------------------------------------------------- bom_form = Form(self.Bom) bom_form.product_id = self.dining_table bom_form.product_tmpl_id = self.dining_table.product_tmpl_id bom_form.product_qty = 1.0 bom_form.product_uom_id = self.unit bom_form.type = 'normal' with bom_form.bom_line_ids.new() as line: line.product_id = self.table_head line.product_qty = 1 with bom_form.bom_line_ids.new() as line: line.product_id = self.screw line.product_qty = 5 with bom_form.bom_line_ids.new() as line: line.product_id = self.leg line.product_qty = 4 with bom_form.bom_line_ids.new() as line: line.product_id = self.glass line.product_qty = 1 self.bom_1 = bom_form.save() # Table Head's components. self.plywood_sheet = self._create_product('Plywood Sheet', 200) self.bolt = self._create_product('Bolt', 10) self.colour = self._create_product('Colour', 100) self.corner_slide = self._create_product('Corner Slide', 25) # ----------------------------------------------------------------- # Cost of BoM (Table Head 1 Dozen) # Component Cost = Plywood Sheet 12 Unit * 200 = 2400 # Bolt 60 Unit * 10 = 600 # Colour 12 Unit * 100 = 1200 # Corner Slide 57 Unit * 25 = 1425 # Total = 5625 # 1 Unit price (5625/12) = 468.75 # ----------------------------------------------------------------- bom_form2 = Form(self.Bom) bom_form2.product_id = self.table_head bom_form2.product_tmpl_id = self.table_head.product_tmpl_id bom_form2.product_qty = 1.0 bom_form2.product_uom_id = self.dozen bom_form2.type = 'phantom' with bom_form2.bom_line_ids.new() as line: line.product_id = self.plywood_sheet line.product_qty = 12 with bom_form2.bom_line_ids.new() as line: line.product_id = self.bolt line.product_qty = 60 with bom_form2.bom_line_ids.new() as line: line.product_id = self.colour line.product_qty = 12 with bom_form2.bom_line_ids.new() as line: line.product_id = self.corner_slide line.product_qty = 57 self.bom_2 = bom_form2.save()