[REF] stock: adapt exising tests to new implementation

This commit is contained in:
Simon Lejeune
2017-07-14 17:08:21 +02:00
parent 10efaa91bc
commit 2ba12efb2c
8 changed files with 452 additions and 460 deletions
+3
View File
@@ -65,6 +65,9 @@
'data/stock_sequence_data.xml',
'data/web_planner_data.xml',
],
'qweb': [
'static/src/xml/stock_traceability_report_backend.xml',
],
'test': [
'test/procrule.yml',
'test/stock_users.yml',
+31 -43
View File
@@ -26,11 +26,11 @@
location_id: stock_location_suppliers
location_dest_id: stock_location_stock
-
Confirm and assign picking and prepare partial
Confirm and assign picking
-
!python {model: stock.picking, id: pick1}: |
self.action_confirm()
self.do_prepare_partial()
self.action_assign()
-
Put 120 pieces on Pallet 1 (package), 120 pieces on Pallet 2 with lot A and 60 pieces on Pallet 3
-
@@ -46,14 +46,14 @@
package3 = stock_quant_pack.create({'name': 'Pallet 3'})
#Create package for each line and assign it as result_package_id
#create pack operation
self.pack_operation_ids[0].write({'result_package_id': package1.id, 'product_qty': 120})
self.pack_operation_ids[0].write({'result_package_id': package1.id, 'qty_done': 120})
new_pack1 = stock_pack.create({
'product_id': ref('product1'),
'product_uom_id': ref('product.product_uom_unit'),
'picking_id': ref('pick1'),
'pack_lot_ids': [(0, 0, {'lot_id': lot_a.id, 'qty': 120})],
'lot_id': lot_a.id,
'qty_done': 120,
'result_package_id': package2.id,
'product_qty': 120,
'location_id': ref('stock_location_suppliers'),
'location_dest_id': ref('stock_location_stock')
})
@@ -62,7 +62,7 @@
'product_uom_id': ref('product.product_uom_unit'),
'picking_id': ref('pick1'),
'result_package_id': package3.id,
'product_qty': 60,
'qty_done': 60,
'location_id': ref('stock_location_suppliers'),
'location_dest_id': ref('stock_location_stock')
})
@@ -70,7 +70,7 @@
Transfer the receipt
-
!python {model: stock.picking, id: pick1}: |
self.do_transfer()
self.action_done()
-
Check the system created 3 quants one with 120 pieces on pallet 1, one with 120 pieces on pallet 2 with lot A and 60 pieces on pallet 3
-
@@ -79,11 +79,11 @@
assert len(quants.ids) == 3, "The number of quants created is not correct"
for quant in quants:
if quant.package_id.name == 'Pallet 1':
assert quant.qty == 120, "Should have 120 pieces on pallet 1"
assert quant.quantity == 120, "Should have 120 pieces on pallet 1"
elif quant.package_id.name == 'Pallet 2':
assert quant.qty == 120, "Should have 120 pieces on pallet 2"
assert quant.quantity == 120, "Should have 120 pieces on pallet 2"
elif quant.package_id.name == 'Pallet 3':
assert quant.qty == 60, "Should have 60 pieces on pallet 3"
assert quant.quantity == 60, "Should have 60 pieces on pallet 3"
-
Check there is no backorder or extra moves created
-
@@ -114,44 +114,28 @@
Instead of doing the 300 pieces, you decide to take pallet 1 (do not mention product in operation here) and 20 pieces from lot A and 10 pieces from pallet 3
-
!python {model: stock.picking, id: delivery_order1}: |
stock_pack = self.env['stock.pack.operation']
self.do_prepare_partial()
for rec in self.pack_operation_ids:
if rec.package_id.name == 'Pallet 1':
rec.qty_done = 120
if rec.package_id.name == 'Pallet 2':
lot = self.env["stock.production.lot"].search([('product_id', '=', ref('product1')), ('name','=','Lot A')], limit=1)
rec.write({
'product_id': ref('product1'),
'product_qty': 20,
'pack_lot_ids': [(0, 0, {'lot_id': lot.id, 'qty': 20})],
'product_uom_id': ref('product.product_uom_unit')
})
rec.qty_done = 20
if rec.package_id.name == 'Pallet 3':
rec.write({
'product_id': ref('product1'),
'product_qty': 10,
'product_uom_id': ref('product.product_uom_unit')
})
-
rec.qty_done = 10
-
Process this picking
-
!python {model: stock.picking, id: delivery_order1 }: |
self.do_transfer()
self.action_done()
-
Check the quants that you have 120 pieces pallet 1 in customers, 100 pieces pallet 2 in stock and 20 with customers and 50 in stock, 10 in customers from pallet 3
Check the quants that you have 100 pieces of pallet 2 and 50 pieces of pallet 3 in stock
-
!python {model: stock.quant, id: False}: |
records = self.search([('product_id','=',ref('product1'))])
for rec in records:
if rec.package_id.name == 'Pallet 1' and rec.location_id.id == ref('stock_location_customers'):
assert rec.qty == 120, "Should have 120 pieces on pallet 1, got " + str(rec.qty)
elif rec.package_id.name == 'Pallet 2' and rec.location_id.id == ref('stock_location_stock'):
assert rec.qty == 100, "Should have 100 pieces in stock on pallet 2, got " + str(rec.qty)
elif rec.lot_id.name == 'Lot A' and rec.location_id.id == ref('stock_location_customers'):
assert (rec.qty == 20 and not rec.package_id), "Should have 20 pieces in customer location from pallet 2"
if rec.package_id.name == 'Pallet 2' and rec.location_id.id == ref('stock_location_stock'):
assert rec.quantity == 100, "Should have 100 pieces in stock on pallet 2, got " + str(rec.quantity)
elif rec.package_id.name == 'Pallet 3' and rec.location_id.id == ref('stock_location_stock'):
assert rec.qty == 50, "Should have 50 pieces in stock on pallet 3"
elif not rec.package_id and not rec.lot_id and rec.location_id.id == ref('stock_location_customers'):
assert rec.qty == 10, "Should have 10 pieces in customer location from pallet 3"
assert rec.quantity == 50, "Should have 50 pieces in stock on pallet 3"
else:
assert False, "Unrecognized quant"
-
@@ -161,21 +145,25 @@
backorders = self.search([('backorder_id', '=', ref('delivery_order1'))])
assert backorders, "Backorder should have been created"
backorders.action_assign()
backorders.do_prepare_partial()
picking = backorders[0]
assert len(picking.pack_operation_ids) == 2, "Wrong number of pack operation"
for pack_op in picking.pack_operation_ids:
assert pack_op.product_qty == 1, "Wrong quantity in pack operation (%s found instead of 1)" % (pack_op.product_qty)
assert pack_op.package_id.name in ('Pallet 2', 'Pallet 3'), "Wrong pallet info in pack operation (%s found)" % (pack_op.package_id.name)
backorders.do_transfer()
-
Check there are still 0 pieces in stock
-
if pack_op.package_id.name == 'Pallet 2':
assert pack_op.product_qty == 100
pack_op.qty_done = 100
elif pack_op.package_id.name == 'Pallet 3':
assert pack_op.product_qty == 50
pack_op.qty_done = 50
backorders.action_done()
-
Check there are still 0 pieces in stock
-
!python {model: stock.quant, id: False}: |
records = self.search([('product_id','=',ref('product1')), ('location_id', '=', ref('stock_location_stock'))])
total_qty = 0
for rec in records:
total_qty += rec.qty
total_qty += rec.quantity
product = self.env["product.product"].browse(ref('product1'))
assert total_qty == 0, "Total quantity in stock should be 0 as the backorder took everything out of stock"
assert product.qty_available == 0, "Quantity available should be 0 too"
+35 -47
View File
@@ -26,11 +26,12 @@
location_id: stock_location_suppliers
location_dest_id: stock_location_stock
-
Confirm and assign picking and prepare partial
Confirm and assign picking
-
!python {model: stock.picking, id: pick_neg}: |
self.action_confirm()
-
self.action_assign()
-
Put 120 pieces on Palneg 1 (package), 120 pieces on Palneg 2 with lot A and 60 pieces on Palneg 3
-
!python {model: stock.picking, id: pick_neg}: |
@@ -45,14 +46,14 @@
package3 = stock_quant_pack.create({'name': 'Palneg 3'})
#Create package for each line and assign it as result_package_id
#create pack operation
self.pack_operation_ids[0].write({'result_package_id': package1.id, 'product_qty': 120})
self.pack_operation_ids[0].write({'result_package_id': package1.id, 'qty_done': 120})
new_pack1 = stock_pack.create({
'product_id': ref('product_neg'),
'product_uom_id': ref('product.product_uom_unit'),
'picking_id': ref('pick_neg'),
'pack_lot_ids': [(0, 0, {'lot_id': lot_a.id, 'qty': 120})],
'lot_id': lot_a.id,
'qty_done': 120,
'result_package_id': package2.id,
'product_qty': 120,
'location_id': ref('stock_location_suppliers'),
'location_dest_id': ref('stock_location_stock')
})
@@ -61,7 +62,7 @@
'product_uom_id': ref('product.product_uom_unit'),
'picking_id': ref('pick_neg'),
'result_package_id': package3.id,
'product_qty': 60,
'qty_done': 60,
'location_id': ref('stock_location_suppliers'),
'location_dest_id': ref('stock_location_stock')
})
@@ -82,60 +83,48 @@
product_uom_qty: 300.00
location_id: stock_location_stock
location_dest_id: stock_location_customers
-
-
Assign and confirm
-
-
!python {model: stock.picking, id: delivery_order_neg}: |
self.action_confirm()
self.action_assign()
-
-
Instead of doing the 300 pieces, you decide to take pallet 1 (do not mention product in operation here) and 140 pieces from lot A/pallet 2 and 10 pieces from pallet 3
-
-
!python {model: stock.picking, id: delivery_order_neg}: |
for rec in self.pack_operation_ids:
if rec.package_id.name == 'Palneg 2':
lot_id = self.env["stock.production.lot"].search([('product_id', '=', ref('product_neg')), ('name','=','Lot neg')], limit=1).id
if rec.package_id.name == 'Palneg 1':
rec.qty_done = rec.product_qty
elif rec.package_id.name == 'Palneg 2' and rec.lot_id.name == 'Lot neg' :
rec.write({
'product_id': ref('product_neg'),
'product_qty': 140,
'pack_lot_ids': [(0, 0, {'lot_id': lot_id, 'qty': 140})],
'product_uom_id': ref('product.product_uom_unit')
'qty_done': 140,
})
if rec.package_id.name == 'Palneg 3':
rec.write({
'product_id': ref('product_neg'),
'product_qty': 10,
'product_uom_id': ref('product.product_uom_unit')
})
-
elif rec.package_id.name == 'Palneg 3':
rec.qty_done = 10
-
Process this picking
-
-
!python {model: stock.picking, id: delivery_order_neg}: |
self.do_transfer()
-
Check the quants that you have 120 pieces pallet 1 in customers, -20 pieces pallet 2 in stock, 120 + 20 pieces 2 in customer with lot, and a total quantity of 50 in stock from pallet 3 (should be 20+30, as it has been split by reservation), finally 10 in customers from pallet 3
-
-
Check the quants that you have -20 pieces pallet 2 in stock, and a total quantity of 50 in stock from pallet 3 (should be 20+30, as it has been split by reservation)
-
!python {model: stock.quant, id: False}: |
records = self.search([('product_id','=',ref('product_neg'))])
pallet_3_stock_qty = 0
for rec in records:
if rec.package_id.name == 'Palneg 1' and rec.location_id.id == ref('stock_location_customers'):
assert rec.qty == 120, "Should have 120 pieces on pallet 1"
elif rec.package_id.name == 'Palneg 2' and rec.location_id.id == ref('stock_location_stock'):
assert rec.qty == -20, "Should have -20 pieces in stock on pallet 2. Got " + str(rec.qty)
if rec.package_id.name == 'Palneg 2' and rec.location_id.id == ref('stock_location_stock'):
assert rec.quantity == -20, "Should have -20 pieces in stock on pallet 2. Got " + str(rec.quantity)
assert rec.lot_id.name == 'Lot neg', "It should have kept its Lot"
elif rec.lot_id.name == 'Lot neg' and rec.location_id.id == ref('stock_location_customers'):
assert ((rec.qty == 20 or rec.qty == 120) and not rec.package_id), "Should have 140 pieces (120+20) in customer location from pallet 2 and lot A"
elif rec.package_id.name == 'Palneg 3' and rec.location_id.id == ref('stock_location_stock'):
pallet_3_stock_qty += rec.qty
elif not rec.package_id and not rec.lot_id and rec.location_id.id == ref('stock_location_customers'):
assert rec.qty == 10, "Should have 10 pieces in customer location from pallet 3"
pallet_3_stock_qty += rec.quantity
else:
assert False, "Unrecognized quant"
assert pallet_3_stock_qty == 50, "Should have 50 pieces in stock on pallet 3"
-
-
Create a picking for reconciling the negative quant
-
-
!record {model: stock.picking, id: delivery_reconcile}:
name: reconciling_delivery
partner_id: base.res_partner_4
@@ -145,27 +134,26 @@
product_uom_qty: 20.0
location_id: stock_location_suppliers
location_dest_id: stock_location_stock
-
-
Receive 20 products with lot neg in stock with a new incoming shipment that should be on pallet 2
-
-
!python {model: stock.picking, id: delivery_reconcile}: |
self.action_confirm()
pack_obj = self.env["stock.quant.package"]
lot = self.env["stock.production.lot"].search([('product_id', '=', ref('product_neg')), ('name','=','Lot neg')], limit=1)
pack = pack_obj.search([('name', '=', 'Palneg 2')], limit=1)
self.pack_operation_ids[0].write({'pack_lot_ids': {'lot_id': lot.id, 'qty': 20.0}, 'result_package_id': pack.id})
self.pack_operation_ids[0].write({'lot_id': lot.id, 'qty_done': 20.0, 'result_package_id': pack.id})
self.do_transfer()
-
Check the negative quant was reconciled and the 20 pieces of lot neg at customers have the incoming shipments in the history_ids
-
-
Check the negative quant was reconciled
-
!python {model: stock.quant, id: False}: |
neg_quants = self.search([('product_id','=', ref('product_neg')), ('qty', '<', 0)])
neg_quants = self.search([('product_id','=', ref('product_neg')), ('quantity', '<', 0)])
assert len(neg_quants.ids) == 0, "Negative quants should have been reconciled"
pick = self.env['stock.picking'].browse(ref('delivery_reconcile'))
customer_quant = self.search([
('product_id', '=', ref('product_neg')),
('location_id', '=', ref('stock_location_customers')),
('lot_id.name','=', 'Lot neg'),
('qty','=', 20)
('quantity','=', 20)
])
assert pick.move_lines[0].id in [x.id for x in customer_quant[0].history_ids]
+1 -1
View File
@@ -49,6 +49,6 @@
('product_id', '=', ref('product.product_product_3')),
('location_id', '=', ref('stock.stock_location_stock')),
('location_dest_id', '=', ref('stock.stock_location_output')),
('move_dest_id', '=', picking.move_lines[0].id)
('move_dest_ids', 'in', [picking.move_lines[0].id])
])
assert len(moves.ids) == 1, "It should have created a picking from Stock to Output with the original picking as destination"
+38 -16
View File
@@ -24,9 +24,9 @@
-
!python {model: stock.picking, id: pick1_wise}: |
self.action_confirm()
self.do_prepare_partial()
-
Put 6 pieces in shelf1 and 4 pieces in shelf2
self.action_assign()
-
Put 4 pieces in shelf1 and 6 pieces in shelf2
-
!python {model: stock.picking, id: pick1_wise}: |
stock_pack = self.env['stock.pack.operation']
@@ -34,14 +34,14 @@
package1 = stock_quant_pack.create({'name': 'Pack 1'})
self.pack_operation_ids[0].write({
'result_package_id': package1.id,
'product_qty': 4,
'qty_done': 4,
'location_dest_id': ref('stock_location_components')
})
new_pack1 = stock_pack.create({
'product_id': ref('product_wise'),
'product_uom_id': ref('product.product_uom_unit'),
'picking_id': ref('pick1_wise'),
'product_qty': 6.0,
'qty_done': 6.0,
'location_id': ref('stock_location_suppliers'),
'location_dest_id': ref('stock_location_14')
})
@@ -74,6 +74,7 @@
!python {model: stock.picking, id: delivery_order_wise1}: |
self.action_confirm()
self.action_assign()
assert self.state == 'assigned'
-
Make a delivery order of 5 pieces to the customer
-
@@ -92,22 +93,43 @@
!python {model: stock.picking, id: delivery_order_wise2}: |
self.action_confirm()
self.action_assign()
assert self.state == 'assigned'
-
The operator is a wise guy and decides to do the opposite of what Odoo proposes. He uses the products reserved on picking 1 on picking 2 and vice versa
-
!python {model: stock.picking, id: False}: |
stock_pack = self.env['stock.pack.operation']
picking1 = self.browse(ref('delivery_order_wise1'))
picking2 = self.browse(ref('delivery_order_wise2'))
pack_ids1 = [x.id for x in picking1.pack_operation_ids]
pack_ids2 = [x.id for x in picking2.pack_operation_ids]
self.env['stock.pack.operation'].browse(pack_ids1).write({'picking_id': picking2.id})
self.env['stock.pack.operation'].browse(pack_ids2).write({'picking_id': picking1.id})
link_obj = self.env['stock.move.operation.link']
# The recompute remaining qtys does not take into account that pack operations change picking
links = link_obj.search([('operation_id', 'in', pack_ids1 + pack_ids2)])
links.unlink()
-
move1 = picking1.move_lines[0]
move2 = picking2.move_lines[0]
pack_ids1 = picking1.pack_operation_ids
pack_ids2 = picking2.pack_operation_ids
assert pack_ids1.location_id.id == ref('stock_location_14')
assert set(pack_ids2.mapped('location_id.id')) == set([ref('stock_location_components'), ref('stock_location_14')])
# put the move lines from picking2 into picking1
for pack_id2 in pack_ids2:
new_pack_id1 = pack_id2.copy(default={'picking_id': picking1.id, 'move_id': move1.id})
new_pack_id1.qty_done = new_pack_id1.product_qty
new_pack_id1.with_context(bypass_reservation_update=True).product_uom_qty = 0
new_move_lines = picking1.pack_operation_ids.filtered(lambda p: p.qty_done)
assert sum(new_move_lines.mapped('product_qty')) == 0
assert sum(new_move_lines.mapped('qty_done')) == 5
assert set(new_move_lines.mapped('location_id.id')) == set([ref('stock_location_components'), ref('stock_location_14')])
# put the move line from picking1 into picking2
new_pack_id2 = pack_ids1.copy(default={'picking_id': picking2.id, 'move_id': move2.id})
new_pack_id2.qty_done = new_pack_id2.product_qty
new_pack_id2.with_context(bypass_reservation_update=True).product_uom_qty = 0
new_move_lines = picking2.pack_operation_ids.filtered(lambda p: p.qty_done)
assert len(new_move_lines) == 1
assert sum(new_move_lines.mapped('product_qty')) == 0
assert sum(new_move_lines.mapped('qty_done')) == 5
assert new_move_lines.location_id.id == ref('stock_location_14')
-
Process this picking
-
!python {model: stock.picking, id: delivery_order_wise1}: |
@@ -116,7 +138,7 @@
Check there was no negative quant created by this picking
-
!python {model: stock.quant, id: False}: |
records = self.search([('product_id','=',ref('product_wise')), ('qty', '<', 0.0)])
records = self.search([('product_id','=',ref('product_wise')), ('quantity', '<', 0.0)])
assert len(records.ids) == 0, 'This should not have created a negative quant'
-
Check the other delivery order has changed its state back to partially available
-8
View File
@@ -85,11 +85,3 @@ class TestStockCommon(common.TestProductCommon):
# Existing data
cls.existing_inventories = cls.env['stock.inventory'].search([])
cls.existing_quants = cls.env['stock.quant'].search([])
# Inventory
inventory_wizard = cls.env['stock.change.product.qty'].create({
'product_id': cls.product_1.id,
'new_quantity': 50.0,
'location_id': cls.warehouse_1.lot_stock_id.id,
})
inventory_wizard.change_product_qty()
File diff suppressed because it is too large Load Diff
+61 -63
View File
@@ -3,10 +3,16 @@
from odoo.addons.stock.tests.common2 import TestStockCommon
class TestInventory(TestStockCommon):
class TestWarehouse(TestStockCommon):
def test_inventory_product(self):
# TDE NOTE: replaces test/inventory.yml present until saas-10
self.product_1.type = 'product'
inventory_wizard = self.env['stock.change.product.qty'].create({
'product_id': self.product_1.id,
'new_quantity': 50.0,
'location_id': self.warehouse_1.lot_stock_id.id,
})
inventory_wizard.change_product_qty()
inventory = self.env['stock.inventory'].sudo(self.user_stock_manager).create({
'name': 'Starting for product_1',
'filter': 'product',
@@ -14,7 +20,6 @@ class TestInventory(TestStockCommon):
'product_id': self.product_1.id,
})
inventory.prepare_inventory()
# As done in common.py, there is already an inventory line existing
self.assertEqual(len(inventory.line_ids), 1)
self.assertEqual(inventory.line_ids.theoretical_qty, 50.0)
@@ -31,18 +36,25 @@ class TestInventory(TestStockCommon):
self.assertEqual(inventory.move_ids.location_id, self.warehouse_1.lot_stock_id)
self.assertEqual(inventory.move_ids.location_dest_id, self.env.ref('stock.location_inventory')) # Inventory loss
self.assertEqual(inventory.move_ids.state, 'done')
self.assertEqual(inventory.move_ids.quant_ids.location_id, self.env.ref('stock.location_inventory')) # Inventory loss
self.assertEqual(inventory.move_ids.quant_ids.qty, 15.0)
self.assertEqual(inventory.move_ids.quant_ids.history_ids[0].product_qty, 50.0)
quants = self.env['stock.quant']._gather(self.product_1, self.env.ref('stock.location_inventory'))
self.assertEqual(len(quants), 0) # No quant created for inventory loss
# Check quantity of product in various locations: current, its parent, brother and other
self.assertEqual(self.product_1.with_context(location=self.warehouse_1.lot_stock_id.id).qty_available, 35.0)
self.assertEqual(self.product_1.with_context(location=self.warehouse_1.lot_stock_id.location_id.id).qty_available, 35.0)
self.assertEqual(self.product_1.with_context(location=self.warehouse_1.view_location_id.id).qty_available, 35.0)
self.assertEqual(self.product_1.with_context(location=self.warehouse_1.wh_input_stock_loc_id.id).qty_available, 0.0)
self.assertEqual(self.product_1.with_context(location=self.env.ref('stock.stock_location_stock').id).qty_available, 0.0)
self.assertEqual(self.env['stock.quant']._gather(self.product_1, self.warehouse_1.lot_stock_id).quantity, 35.0)
self.assertEqual(self.env['stock.quant']._gather(self.product_1, self.warehouse_1.lot_stock_id.location_id).quantity, 35.0)
self.assertEqual(self.env['stock.quant']._gather(self.product_1, self.warehouse_1.view_location_id).quantity, 35.0)
self.assertEqual(self.env['stock.quant']._gather(self.product_1, self.warehouse_1.wh_input_stock_loc_id).quantity, 0.0)
self.assertEqual(self.env['stock.quant']._gather(self.product_1, self.env.ref('stock.stock_location_stock')).quantity, 0.0)
def test_inventory_wizard(self):
self.product_1.type = 'product'
inventory_wizard = self.env['stock.change.product.qty'].create({
'product_id': self.product_1.id,
'new_quantity': 50.0,
'location_id': self.warehouse_1.lot_stock_id.id,
})
inventory_wizard.change_product_qty()
# Check inventory performed in setup was effectivley performed
self.assertEqual(self.product_1.virtual_available, 50.0)
self.assertEqual(self.product_1.qty_available, 50.0)
@@ -63,12 +75,24 @@ class TestInventory(TestStockCommon):
def test_basic_move(self):
# TDE NOTE: replaces test/move.yml present until saas-10, including onchanges
Move = self.env['stock.move'].sudo(self.user_stock_manager)
product = self.product_3.sudo(self.user_stock_manager)
product.type = 'product'
picking_out = self.env['stock.picking'].create({
'partner_id': self.env.ref('base.res_partner_2').id,
'picking_type_id': self.env.ref('stock.picking_type_out').id,
'location_id': self.warehouse_1.lot_stock_id.id,
'location_dest_id': self.env.ref('stock.stock_location_customers').id,
})
customer_move = self.env['stock.move'].create({
'name': product.name,
'product_id': product.id,
'product_uom_qty': 5,
'product_uom': product.uom_id.id,
'picking_id': picking_out.id,
'location_id': self.warehouse_1.lot_stock_id.id,
'location_dest_id': self.env.ref('stock.stock_location_customers').id,
})
# simulate create + onchange
customer_move = self._create_move(product, self.warehouse_1.lot_stock_id, self.env.ref('stock.stock_location_customers'), product_uom_qty=5)
# test move values
self.assertEqual(customer_move.product_uom, product.uom_id)
self.assertEqual(customer_move.location_id, self.warehouse_1.lot_stock_id)
@@ -79,16 +103,18 @@ class TestInventory(TestStockCommon):
self.assertEqual(product.qty_available, 0.0)
self.assertEqual(product.virtual_available, -5.0)
customer_move.quantity_done = 5
customer_move.action_done()
self.assertEqual(product.qty_available, -5.0)
self.assertEqual(product.with_context(location=self.env.ref('stock.stock_location_customers').id).qty_available, 5.0)
# compensate negative quants by receiving products from supplier
receive_move = self._create_move(product, self.env.ref('stock.stock_location_suppliers'), self.warehouse_1.lot_stock_id, product_uom_qty=15)
receive_move.action_confirm()
receive_move.quantity_done = 15
receive_move.action_done()
product._compute_quantities()
self.assertEqual(product.qty_available, 10.0)
self.assertEqual(product.virtual_available, 10.0)
@@ -96,19 +122,20 @@ class TestInventory(TestStockCommon):
customer_move_2 = self._create_move(product, self.warehouse_1.lot_stock_id, self.env.ref('stock.stock_location_customers'), product_uom_qty=2)
customer_move_2.action_confirm()
product._compute_quantities()
self.assertEqual(product.qty_available, 10.0)
self.assertEqual(product.virtual_available, 8.0)
customer_move_2.quantity_done = 2.0
customer_move_2.action_done()
product._compute_quantities()
self.assertEqual(product.qty_available, 8.0)
self.assertEqual(product.with_context(location=self.env.ref('stock.stock_location_customers').id).qty_available, 7.0)
def test_inventory_adjustment_and_negative_quants_1(self):
"""Make sure negative quants from returns get wiped out with an inventory adjustment"""
productA = self.env['product.product'].create({'name': 'Product A', 'type': 'product'})
stock_location = self.env.ref('stock.stock_location_stock')
customer_location = self.env.ref('stock.stock_location_customers')
location_loss = self.env.ref('stock.location_inventory')
# Create a picking out and force availability
picking_out = self.env['stock.picking'].create({
@@ -128,53 +155,23 @@ class TestInventory(TestStockCommon):
})
picking_out.action_confirm()
picking_out.force_assign()
picking_out.do_transfer()
picking_out.move_lines.quantity_done = 1
picking_out.action_done()
# Create return picking for all goods
default_data = self.env['stock.return.picking']\
.with_context(active_ids=picking_out.ids, active_id=picking_out.ids[0])\
.default_get([
'move_dest_exists',
'original_location_id',
'product_return_moves',
'parent_location_id',
'location_id',
])
return_wiz = self.env['stock.return.picking']\
.with_context(active_ids=picking_out.ids, active_id=picking_out.ids[0])\
.create(default_data)
res = return_wiz.create_returns()
return_pick = self.env['stock.picking'].browse(res['res_id'])
return_pick.action_assign()
return_pick.do_transfer()
# Make an inventory adjustment to set the quantity to 0
inventory = self.env['stock.inventory'].create({
'name': 'Starting for product_1',
'filter': 'product',
'location_id': stock_location.id,
'product_id': productA.id,
})
inventory.prepare_inventory()
self.assertEqual(len(inventory.line_ids), 1, "Wrong inventory lines generated.")
self.assertEqual(inventory.line_ids.theoretical_qty, 0, "Theoretical quantity should be zero.")
inventory.action_done()
# The inventory adjustment should have created two moves
self.assertEqual(len(inventory.move_ids), 2)
quantity = inventory.move_ids.mapped('product_qty')
self.assertEqual(quantity, [1, 1], "Moves created with wrong quantity.")
location_ids = inventory.move_ids.mapped('location_id').ids
self.assertEqual(set(location_ids), {stock_location.id, location_loss.id})
# There should be no quant in the stock location
quants = self.env['stock.quant'].search([('product_id', '=', productA.id), ('location_id', '=', stock_location.id)])
self.assertEqual(len(quants), 0)
# There should be one quant in the inventory loss location
quant = self.env['stock.quant'].search([('product_id', '=', productA.id), ('location_id', '=', location_loss.id)])
quant = self.env['stock.quant'].search([('product_id', '=', productA.id), ('location_id', '=', stock_location.id)])
self.assertEqual(len(quant), 1)
self.assertEqual(quant.qty, 1)
stock_return_picking = self.env['stock.return.picking']\
.with_context(active_ids=picking_out.ids, active_id=picking_out.ids[0])\
.create({})
stock_return_picking.product_return_moves.quantity = 1.0
stock_return_picking_action = stock_return_picking.create_returns()
return_pick = self.env['stock.picking'].browse(stock_return_picking_action['res_id'])
return_pick.action_assign()
return_pick.move_lines.quantity_done = 1
return_pick.action_done()
quant = self.env['stock.quant'].search([('product_id', '=', productA.id), ('location_id', '=', stock_location.id)])
self.assertEqual(len(quant), 0)
def test_inventory_adjustment_and_negative_quants_2(self):
"""Make sure negative quants get wiped out with an inventory adjustment"""
@@ -201,6 +198,7 @@ class TestInventory(TestStockCommon):
})
picking_out.action_confirm()
picking_out.force_assign()
picking_out.move_lines.quantity_done = 1
picking_out.do_transfer()
# Make an inventory adjustment to set the quantity to 0