[FIX] mrp_subcontracting_purchase: verify ressuply + mto flow
This commit adds a test on the following flow: A subcontracted product has its component having the three route - ressuply on order - buy - MTO Receiving the subcontracted product will create a delivery for the component to the subcontractor, then a purchase order to buy it. Confirming this very PO should create a receipt stock move linked to this delivery. closes odoo/odoo#147344 X-original-commit: 0044fd8bb6966011bd3943bff0bd58bcd111338f Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
@@ -26,6 +26,10 @@ class MrpSubcontractingPurchaseTest(TestMrpSubcontractingCommon):
|
||||
'name': 'Component',
|
||||
'type': 'consu',
|
||||
}])
|
||||
self.vendor = self.env['res.partner'].create({
|
||||
'name': 'Vendor',
|
||||
'company_id': self.env.ref('base.main_company').id,
|
||||
})
|
||||
|
||||
self.bom_finished2 = self.env['mrp.bom'].create({
|
||||
'product_tmpl_id': self.finished2.product_tmpl_id.id,
|
||||
@@ -280,21 +284,22 @@ class MrpSubcontractingPurchaseTest(TestMrpSubcontractingCommon):
|
||||
|
||||
# Receive Products
|
||||
receipt = po.picking_ids
|
||||
receipt.move_lines.quantity_done = 10
|
||||
receipt.move_ids.quantity = 10
|
||||
receipt.move_ids.picked = True
|
||||
receipt.button_validate()
|
||||
|
||||
self.assertEqual(po.order_line.qty_received, 10.0)
|
||||
|
||||
# Return Products
|
||||
return_form = Form(self.env['stock.return.picking'].with_context(active_id=receipt.id, active_model='stock.picking'))
|
||||
with return_form.product_return_moves.edit(0) as line:
|
||||
line.quantity = 3
|
||||
line.to_refund = True
|
||||
return_wizard = return_form.save()
|
||||
return_wizard.product_return_moves.quantity = 3
|
||||
return_wizard.product_return_moves.to_refund = True
|
||||
return_id, _ = return_wizard._create_returns()
|
||||
|
||||
return_picking = self.env['stock.picking'].browse(return_id)
|
||||
return_picking.move_lines.quantity_done = 3
|
||||
return_picking.move_ids.quantity = 3
|
||||
return_picking.move_ids.picked = True
|
||||
return_picking.button_validate()
|
||||
|
||||
self.assertEqual(po.order_line.qty_received, 7.0)
|
||||
@@ -564,3 +569,50 @@ class MrpSubcontractingPurchaseTest(TestMrpSubcontractingCommon):
|
||||
"Lead time = Manufacturing lead time + Days to Purchase + Purchase security lead time + DTPMO on BOM")
|
||||
for component in bom_data['components']:
|
||||
self.assertEqual(component['availability_state'], 'available')
|
||||
|
||||
def test_resupply_order_buy_mto(self):
|
||||
""" Test a subcontract component can has resupply on order + buy + mto route"""
|
||||
mto_route = self.env.ref('stock.route_warehouse0_mto')
|
||||
mto_route.active = True
|
||||
resupply_sub_on_order_route = self.env['stock.route'].search([('name', '=', 'Resupply Subcontractor on Order')])
|
||||
(self.comp1 + self.comp2).write({
|
||||
'route_ids': [
|
||||
Command.link(resupply_sub_on_order_route.id),
|
||||
Command.link(self.env.ref('purchase_stock.route_warehouse0_buy').id),
|
||||
Command.link(mto_route.id)],
|
||||
'seller_ids': [Command.create({
|
||||
'partner_id': self.vendor.id,
|
||||
})],
|
||||
})
|
||||
|
||||
po = self.env['purchase.order'].create({
|
||||
'partner_id': self.subcontractor_partner1.id,
|
||||
'order_line': [Command.create({
|
||||
'name': 'finished',
|
||||
'product_id': self.finished.id,
|
||||
'product_qty': 1.0,
|
||||
'product_uom': self.finished.uom_id.id,
|
||||
'price_unit': 50.0}
|
||||
)],
|
||||
})
|
||||
|
||||
po.button_confirm()
|
||||
ressuply_pick = self.env['stock.picking'].search([('location_dest_id', '=', self.env.company.subcontracting_location_id.id)])
|
||||
self.assertEqual(len(ressuply_pick.move_ids), 2)
|
||||
self.assertEqual(ressuply_pick.move_ids.mapped('product_id'), self.comp1 | self.comp2)
|
||||
|
||||
# should have create a purchase order for the components
|
||||
comp_po = self.env['purchase.order'].search([('partner_id', '=', self.vendor.id)])
|
||||
self.assertEqual(len(comp_po.order_line), 2)
|
||||
self.assertEqual(comp_po.order_line.mapped('product_id'), self.comp1 | self.comp2)
|
||||
# confirm the po should create stock moves linked to the resupply
|
||||
comp_po.button_confirm()
|
||||
comp_receipt = comp_po.picking_ids
|
||||
self.assertEqual(comp_receipt.move_ids.move_dest_ids, ressuply_pick.move_ids)
|
||||
|
||||
# validate the comp receipt should reserve the resupply
|
||||
self.assertEqual(ressuply_pick.state, 'waiting')
|
||||
comp_receipt.move_ids.quantity = 1
|
||||
comp_receipt.move_ids.picked = True
|
||||
comp_receipt.button_validate()
|
||||
self.assertEqual(ressuply_pick.state, 'assigned')
|
||||
|
||||
Reference in New Issue
Block a user