- In order to test the inventory, I create a new product - !record {model: product.product, id: inventory_product}: name: inventory prod type: product - I create an inventory for this product only - !record {model: stock.inventory, id: inventory_test0}: name: Test product_id: inventory_product - I confirm the inventory and check that my inventory has no line, as the product is a new one. - !python {model: stock.inventory}: | self.prepare_inventory(cr, uid, [ref('inventory_test0')], context=context) inv = self.browse(cr, uid, ref('inventory_test0'), context=context) assert len(inv.line_ids) == 0, "Wrong number of inventory lines." - I add an inventory line and say i have 10 products in stock - !record {model: stock.inventory.line, id: inventory_testline0}: inventory_id: stock.inventory_test0 product_uom_id: product.product_uom_unit product_id: inventory_product product_qty: 10 location_id: stock.stock_location_14 - I Validate this inventory - !python {model: stock.inventory}: | self.action_done(cr, uid, [ref('inventory_test0')], context=context) - I check that this inventory has a stock.move and a quant - !python {model: stock.inventory}: | inv = self.browse(cr, uid, ref('inventory_test0'), context=context) assert len(inv.move_ids) >= 1, "No move created for the inventory." assert len(inv.move_ids[0].quant_ids) >= 1, "No quant created for this inventory" - I check that the quantity on hand is 10 on the location and its parent. - !python {model: product.product}: | context['location'] = ref('stock.stock_location_14') product = self.browse(cr, uid, ref('inventory_product'), context=context) assert product.qty_available == 10, 'Expecting 10 products, got %.2f on location stock_location_14!' % (product.qty_available,) context['location'] = ref('stock.stock_location_stock') product = self.browse(cr, uid, ref('inventory_product'), context=context) assert product.qty_available == 10, 'Expecting 10 products, got %.2f on location stock_location_stock!' % (product.qty_available,) - I check that the quantity on hand is 0 on a brother location - !python {model: product.product}: | context['location'] = ref('stock.stock_location_components') product = self.browse(cr, uid, ref('inventory_product'), context=context) assert product.qty_available == 0, 'Expecting 0 products, got %.2f on location stock_location_components!' % (product.qty_available,) - I create another inventory - !record {model: stock.inventory, id: inventory_test1}: name: second test inventory product_id: inventory_product - I confirm the inventory and check that my inventory has one line, with a quantity of 10. - !python {model: stock.inventory}: | self.prepare_inventory(cr, uid, [ref('inventory_test1')], context=context) inv = self.browse(cr, uid, ref('inventory_test1'), context=context) assert inv.line_ids and len(inv.line_ids) == 1, "Wrong number of inventory lines." assert inv.line_ids[0].product_qty == 10, "Wrong quantity in inventory line." assert inv.line_ids[0].product_id.id == ref('inventory_product'), "Wrong product in inventory line." - I modify the inventory line and set the quantity to 20 product on this new inventory - !python {model: stock.inventory}: | inv = self.browse(cr, uid, ref('inventory_test1'), context=context) self.pool.get('stock.inventory.line').write(cr, uid, inv.line_ids[0].id, {'product_qty': 20}) - I Validate this inventory - !python {model: stock.inventory}: | self.action_done(cr, uid, [ref('inventory_test1')], context=context) - I check that the quantity on hand is 20 on the location and it's parent. - !python {model: product.product}: | context['location'] = ref('stock.stock_location_14') product = self.browse(cr, uid, ref('inventory_product'), context=context) assert product.qty_available == 20, 'Expecting 20 products, got %.2f on location stock_location_14!' % (product.qty_available,)