[FIX] stock: add extra tests for lots and fix problem subtracting remaining qties
In this test, we set the incoming picking type not to require any lots. The outgoing picking requires lots and should convert the stock without lot into stock with lot.
This commit is contained in:
@@ -2538,6 +2538,8 @@ class stock_move(osv.osv):
|
||||
quants = quant_obj.quants_get_preferred_domain(cr, uid, qty, move_rec, ops=ops, lot_id=lot, domain=domain,
|
||||
preferred_domain_list=preferred_domain_list, context=context)
|
||||
move_quants_dict[lot] += quants
|
||||
lot_qty[lot] -= qty
|
||||
lot_move_qty[move] -= qty
|
||||
|
||||
#Move all the quants related to that lot/move
|
||||
if move_quants_dict[lot]:
|
||||
|
||||
@@ -18,6 +18,7 @@ class TestStockCommon(common.TransactionCase):
|
||||
self.MoveObj = self.env['stock.move']
|
||||
self.InvObj = self.env['stock.inventory']
|
||||
self.InvLineObj = self.env['stock.inventory.line']
|
||||
self.LotObj = self.env['stock.production.lot']
|
||||
|
||||
# Model Data
|
||||
self.partner_agrolite_id = self.ModelDataObj.xmlid_to_res_id('base.res_partner_2')
|
||||
|
||||
@@ -1166,4 +1166,72 @@ class TestStockFlow(TestStockCommon):
|
||||
self.assertEqual(total_qty, 10, 'Expecting 0 units lot of lotproduct, but we got %.4f on location stock!' % (total_qty))
|
||||
quants = self.StockQuantObj.search([('product_id', '=', lotproduct.id), ('location_id', '=', self.stock_location), ('lot_id', '=', False)])
|
||||
total_qty = sum([quant.qty for quant in quants])
|
||||
self.assertEqual(total_qty, 0, 'Expecting 0 units lot of lotproduct, but we got %.4f on location stock!' % (total_qty))
|
||||
self.assertEqual(total_qty, 0, 'Expecting 0 units lot of lotproduct, but we got %.4f on location stock!' % (total_qty))
|
||||
|
||||
|
||||
def test_30_check_with_no_incoming_lot(self):
|
||||
""" Picking in without lots and picking out with"""
|
||||
|
||||
# Change basic picking type not to get lots
|
||||
# Create product with lot tracking
|
||||
picking_in = self.env['stock.picking.type'].browse(self.picking_type_in)
|
||||
picking_in.use_create_lots = False
|
||||
self.productA.tracking = 'lot'
|
||||
picking_in = self.PickingObj.create({
|
||||
'partner_id': self.partner_delta_id,
|
||||
'picking_type_id': self.picking_type_in,
|
||||
'location_id': self.supplier_location,
|
||||
'location_dest_id': self.stock_location})
|
||||
self.MoveObj.create({
|
||||
'name': self.productA.name,
|
||||
'product_id': self.productA.id,
|
||||
'product_uom_qty': 4,
|
||||
'product_uom': self.productA.uom_id.id,
|
||||
'picking_id': picking_in.id,
|
||||
'location_id': self.supplier_location,
|
||||
'location_dest_id': self.stock_location})
|
||||
|
||||
# Check incoming shipment move lines state.
|
||||
for move in picking_in.move_lines:
|
||||
self.assertEqual(move.state, 'draft', 'Wrong state of move line.')
|
||||
# Confirm incoming shipment.
|
||||
picking_in.action_confirm()
|
||||
# Check incoming shipment move lines state.
|
||||
for move in picking_in.move_lines:
|
||||
self.assertEqual(move.state, 'assigned', 'Wrong state of move line.')
|
||||
|
||||
picking_in.do_transfer()
|
||||
|
||||
picking_out = self.PickingObj.create({
|
||||
'partner_id': self.partner_agrolite_id,
|
||||
'name': 'testpicking',
|
||||
'picking_type_id': self.picking_type_out,
|
||||
'location_id': self.stock_location,
|
||||
'location_dest_id': self.customer_location})
|
||||
self.MoveObj.create({
|
||||
'name': self.productA.name,
|
||||
'product_id': self.productA.id,
|
||||
'product_uom_qty': 3,
|
||||
'product_uom': self.productA.uom_id.id,
|
||||
'picking_id': picking_out.id,
|
||||
'location_id': self.stock_location,
|
||||
'location_dest_id': self.customer_location})
|
||||
picking_out.action_confirm()
|
||||
picking_out.action_assign()
|
||||
pack_opt = self.StockPackObj.search([('picking_id', '=', picking_out.id)], limit=1)
|
||||
lot1 = self.LotObj.create({'product_id': self.productA.id, 'name': 'LOT1'})
|
||||
lot2 = self.LotObj.create({'product_id': self.productA.id, 'name': 'LOT2'})
|
||||
lot3 = self.LotObj.create({'product_id': self.productA.id, 'name': 'LOT3'})
|
||||
self.env['stock.pack.operation.lot'].create({'operation_id': pack_opt.id, 'lot_id': lot1.id, 'qty': 1.0})
|
||||
self.env['stock.pack.operation.lot'].create({'operation_id': pack_opt.id,'lot_id': lot2.id, 'qty': 1.0})
|
||||
self.env['stock.pack.operation.lot'].create({'operation_id': pack_opt.id, 'lot_id': lot3.id, 'qty': 2.0})
|
||||
pack_opt.qty_done = 4.0
|
||||
picking_out.do_new_transfer()
|
||||
quants = self.StockQuantObj.search([('product_id', '=', self.productA.id), ('location_id', '=', self.stock_location)])
|
||||
self.assertFalse(quants, 'Should not have any quants in stock anymore')
|
||||
quants = self.StockQuantObj.search([('product_id', '=', self.productA.id), ('location_id', '=', self.customer_location)])
|
||||
self.assertEqual(sum([x.qty for x in quants]), 4, 'Wrong total sum of quants')
|
||||
self.assertEqual(sum([x.qty for x in quants if not x.lot_id]), 0.0, 'Wrong sum of quants with no lot')
|
||||
self.assertEqual(sum([x.qty for x in quants if x.lot_id.id == lot1.id]), 1.0, 'Wrong sum of quants with lot 1')
|
||||
self.assertEqual(sum([x.qty for x in quants if x.lot_id.id == lot2.id]), 1.0, 'Wrong sum of quants with lot 2')
|
||||
self.assertEqual(sum([x.qty for x in quants if x.lot_id.id == lot3.id]), 2.0, 'Wrong sum of quants with lot 3')
|
||||
Reference in New Issue
Block a user