self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final,self.stock_location),2,'You should have consumed 3 final product in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p1,self.stock_location),92,'You should have 80 products in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p2,self.stock_location),3,'You should have consumed all the 5 product in stock')
self.env['mrp.unbuild'].create({
'product_id':p_final.id,
'bom_id':bom.id,
'product_qty':2.0,
'product_uom_id':self.uom_unit.id,
}).action_unbuild()
self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final,self.stock_location),0,'You should have 0 finalproduct in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p1,self.stock_location),100,'You should have 80 products in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p2,self.stock_location),5,'You should have consumed all the 5 product in stock')
self.env['mrp.unbuild'].create({
'product_id':p_final.id,
'bom_id':bom.id,
'product_qty':5.0,
'product_uom_id':self.uom_unit.id,
}).action_unbuild()
# Check quantity in stock after last unbuild.
self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final,self.stock_location,allow_negative=True),-5,'You should have negative quantity for final product in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p1,self.stock_location),120,'You should have 80 products in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p2,self.stock_location),10,'You should have consumed all the 5 product in stock')
deftest_unbuild_with_final_lot(self):
""" This test creates a MO and then creates 3 unbuild
self.assertEqual(mo.state,'done',"Production order should be in done state.")
# Check quantity in stock before unbuild.
self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final,self.stock_location,lot_id=lot),5,'You should have the 5 final product in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p1,self.stock_location),80,'You should have 80 products in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p2,self.stock_location),0,'You should have consumed all the 5 product in stock')
# This should fail since we do not choose a lot to unbuild for final product.
withself.assertRaises(UserError):
unbuild_order.action_unbuild()
unbuild_order.lot_id=lot.id
unbuild_order.action_unbuild()
self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final,self.stock_location,lot_id=lot),2,'You should have consumed 3 final product in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p1,self.stock_location),92,'You should have 80 products in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p2,self.stock_location),3,'You should have consumed all the 5 product in stock')
self.env['mrp.unbuild'].create({
'product_id':p_final.id,
'bom_id':bom.id,
'product_qty':2.0,
'lot_id':lot.id,
'product_uom_id':self.uom_unit.id,
}).action_unbuild()
self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final,self.stock_location,lot_id=lot),0,'You should have 0 finalproduct in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p1,self.stock_location),100,'You should have 80 products in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p2,self.stock_location),5,'You should have consumed all the 5 product in stock')
self.env['mrp.unbuild'].create({
'product_id':p_final.id,
'bom_id':bom.id,
'product_qty':5.0,
'lot_id':lot.id,
'product_uom_id':self.uom_unit.id,
}).action_unbuild()
self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final,self.stock_location,lot_id=lot,allow_negative=True),-5,'You should have negative quantity for final product in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p1,self.stock_location),120,'You should have 80 products in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p2,self.stock_location),10,'You should have consumed all the 5 product in stock')
deftest_unbuild_with_comnsumed_lot(self):
""" This test creates a MO and then creates 3 unbuild
# This should fail since we do not provide the MO that we wanted to unbuild. (without MO we do not know which consumed lot we have to restore)
withself.assertRaises(UserError):
unbuild_order.action_unbuild()
self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final,self.stock_location),5,'You should have consumed 3 final product in stock')
unbuild_order.mo_id=mo.id
unbuild_order.action_unbuild()
self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final,self.stock_location),2,'You should have consumed 3 final product in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p1,self.stock_location,lot_id=lot),92,'You should have 80 products in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p2,self.stock_location),3,'You should have consumed all the 5 product in stock')
self.env['mrp.unbuild'].create({
'product_id':p_final.id,
'bom_id':bom.id,
'product_qty':2.0,
'mo_id':mo.id,
'product_uom_id':self.uom_unit.id,
}).action_unbuild()
self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final,self.stock_location),0,'You should have 0 finalproduct in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p1,self.stock_location,lot_id=lot),100,'You should have 80 products in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p2,self.stock_location),5,'You should have consumed all the 5 product in stock')
self.env['mrp.unbuild'].create({
'product_id':p_final.id,
'bom_id':bom.id,
'product_qty':5.0,
'mo_id':mo.id,
'product_uom_id':self.uom_unit.id,
}).action_unbuild()
self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final,self.stock_location,allow_negative=True),-5,'You should have negative quantity for final product in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p1,self.stock_location,lot_id=lot),120,'You should have 80 products in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p2,self.stock_location),10,'You should have consumed all the 5 product in stock')
deftest_unbuild_with_everything_tracked(self):
""" This test creates a MO and then creates 3 unbuild
self.assertEqual(mo.state,'done',"Production order should be in done state.")
# Check quantity in stock before unbuild.
self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final,self.stock_location,lot_id=lot_final),5,'You should have the 5 final product in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p1,self.stock_location,lot_id=lot_1),80,'You should have 80 products in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p2,self.stock_location,lot_id=lot_2),0,'You should have consumed all the 5 product in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final,self.stock_location,lot_id=lot_final),5,'You should have consumed 3 final product in stock')
unbuild_order.mo_id=mo.id
withself.assertRaises(UserError):
unbuild_order.action_unbuild()
self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final,self.stock_location,lot_id=lot_final),5,'You should have consumed 3 final product in stock')
unbuild_order.lot_id=lot_final.id
unbuild_order.action_unbuild()
self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final,self.stock_location,lot_id=lot_final),2,'You should have consumed 3 final product in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p1,self.stock_location,lot_id=lot_1),92,'You should have 80 products in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p2,self.stock_location,lot_id=lot_2),3,'You should have consumed all the 5 product in stock')
self.env['mrp.unbuild'].create({
'product_id':p_final.id,
'bom_id':bom.id,
'product_qty':2.0,
'mo_id':mo.id,
'lot_id':lot_final.id,
'product_uom_id':self.uom_unit.id,
}).action_unbuild()
self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final,self.stock_location,lot_id=lot_final),0,'You should have 0 finalproduct in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p1,self.stock_location,lot_id=lot_1),100,'You should have 80 products in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p2,self.stock_location,lot_id=lot_2),5,'You should have consumed all the 5 product in stock')
self.env['mrp.unbuild'].create({
'product_id':p_final.id,
'bom_id':bom.id,
'product_qty':5.0,
'mo_id':mo.id,
'lot_id':lot_final.id,
'product_uom_id':self.uom_unit.id,
}).action_unbuild()
self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final,self.stock_location,lot_id=lot_final,allow_negative=True),-5,'You should have negative quantity for final product in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p1,self.stock_location,lot_id=lot_1),120,'You should have 80 products in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p2,self.stock_location,lot_id=lot_2),10,'You should have consumed all the 5 product in stock')
deftest_unbuild_with_duplicate_move(self):
""" This test creates a MO from 3 different lot on a consumed product (p2).
self.assertEqual(mo.state,'done',"Production order should be in done state.")
# Check quantity in stock before unbuild.
self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final,self.stock_location),5,'You should have the 5 final product in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p1,self.stock_location),80,'You should have 80 products in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p2,self.stock_location,lot_id=lot_1),0,'You should have consumed all the 1 product for lot 1 in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p2,self.stock_location,lot_id=lot_2),0,'You should have consumed all the 3 product for lot 2 in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p2,self.stock_location,lot_id=lot_3),1,'You should have consumed only 1 product for lot3 in stock')
self.env['mrp.unbuild'].create({
'product_id':p_final.id,
'bom_id':bom.id,
'product_qty':5.0,
'mo_id':mo.id,
'product_uom_id':self.uom_unit.id,
}).action_unbuild()
self.assertEqual(self.env['stock.quant']._get_available_quantity(p_final,self.stock_location),0,'You should have no more final product in stock after unbuild')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p1,self.stock_location),100,'You should have 80 products in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p2,self.stock_location,lot_id=lot_1),1,'You should have get your product with lot 1 in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p2,self.stock_location,lot_id=lot_2),3,'You should have the 3 basic product for lot 2 in stock')
self.assertEqual(self.env['stock.quant']._get_available_quantity(p2,self.stock_location,lot_id=lot_3),2,'You should have get one product back for lot 3')