diff --git a/addons/stock/tests/__init__.py b/addons/stock/tests/__init__.py index 5990f5a90f0..ea985ba98a1 100644 --- a/addons/stock/tests/__init__.py +++ b/addons/stock/tests/__init__.py @@ -3,7 +3,6 @@ from . import test_stock_flow from . import test_product from . import test_warehouse -from . import test_shipment from . import test_stock_location_search from . import test_quant from . import test_inventory diff --git a/addons/stock/tests/common.py b/addons/stock/tests/common.py index f0a1bd2d795..7a14070caf7 100644 --- a/addons/stock/tests/common.py +++ b/addons/stock/tests/common.py @@ -3,98 +3,99 @@ from odoo.tests import common -class TestStockCommon(common.TransactionCase): +class TestStockCommon(common.SavepointCase): - def setUp(self): - super(TestStockCommon, self).setUp() + @classmethod + def setUpClass(cls): + super(TestStockCommon, cls).setUpClass() - self.ProductObj = self.env['product.product'] - self.UomObj = self.env['uom.uom'] - self.PartnerObj = self.env['res.partner'] - self.ModelDataObj = self.env['ir.model.data'] - self.StockPackObj = self.env['stock.move.line'] - self.StockQuantObj = self.env['stock.quant'] - self.PickingObj = self.env['stock.picking'] - 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'] + cls.ProductObj = cls.env['product.product'] + cls.UomObj = cls.env['uom.uom'] + cls.PartnerObj = cls.env['res.partner'] + cls.ModelDataObj = cls.env['ir.model.data'] + cls.StockPackObj = cls.env['stock.move.line'] + cls.StockQuantObj = cls.env['stock.quant'] + cls.PickingObj = cls.env['stock.picking'] + cls.MoveObj = cls.env['stock.move'] + cls.InvObj = cls.env['stock.inventory'] + cls.InvLineObj = cls.env['stock.inventory.line'] + cls.LotObj = cls.env['stock.production.lot'] # Model Data - self.partner_agrolite_id = self.ModelDataObj.xmlid_to_res_id('base.res_partner_2') - self.partner_delta_id = self.ModelDataObj.xmlid_to_res_id('base.res_partner_4') - self.picking_type_in = self.ModelDataObj.xmlid_to_res_id('stock.picking_type_in') - self.picking_type_out = self.ModelDataObj.xmlid_to_res_id('stock.picking_type_out') - self.supplier_location = self.ModelDataObj.xmlid_to_res_id('stock.stock_location_suppliers') - self.stock_location = self.ModelDataObj.xmlid_to_res_id('stock.stock_location_stock') - pack_location = self.env.ref('stock.location_pack_zone') + cls.partner_agrolite_id = cls.ModelDataObj.xmlid_to_res_id('base.res_partner_2') + cls.partner_delta_id = cls.ModelDataObj.xmlid_to_res_id('base.res_partner_4') + cls.picking_type_in = cls.ModelDataObj.xmlid_to_res_id('stock.picking_type_in') + cls.picking_type_out = cls.ModelDataObj.xmlid_to_res_id('stock.picking_type_out') + cls.supplier_location = cls.ModelDataObj.xmlid_to_res_id('stock.stock_location_suppliers') + cls.stock_location = cls.ModelDataObj.xmlid_to_res_id('stock.stock_location_stock') + pack_location = cls.env.ref('stock.location_pack_zone') pack_location.active = True - self.pack_location = pack_location.id - output_location = self.env.ref('stock.stock_location_output') + cls.pack_location = pack_location.id + output_location = cls.env.ref('stock.stock_location_output') output_location.active = True - self.output_location = output_location.id - self.customer_location = self.ModelDataObj.xmlid_to_res_id('stock.stock_location_customers') - self.categ_unit = self.ModelDataObj.xmlid_to_res_id('uom.product_uom_categ_unit') - self.categ_kgm = self.ModelDataObj.xmlid_to_res_id('uom.product_uom_categ_kgm') + cls.output_location = output_location.id + cls.customer_location = cls.ModelDataObj.xmlid_to_res_id('stock.stock_location_customers') + cls.categ_unit = cls.ModelDataObj.xmlid_to_res_id('uom.product_uom_categ_unit') + cls.categ_kgm = cls.ModelDataObj.xmlid_to_res_id('uom.product_uom_categ_kgm') # Product Created A, B, C, D - self.productA = self.ProductObj.create({'name': 'Product A', 'type': 'product'}) - self.productB = self.ProductObj.create({'name': 'Product B', 'type': 'product'}) - self.productC = self.ProductObj.create({'name': 'Product C', 'type': 'product'}) - self.productD = self.ProductObj.create({'name': 'Product D', 'type': 'product'}) - self.productE = self.ProductObj.create({'name': 'Product E', 'type': 'product'}) + cls.productA = cls.ProductObj.create({'name': 'Product A', 'type': 'product'}) + cls.productB = cls.ProductObj.create({'name': 'Product B', 'type': 'product'}) + cls.productC = cls.ProductObj.create({'name': 'Product C', 'type': 'product'}) + cls.productD = cls.ProductObj.create({'name': 'Product D', 'type': 'product'}) + cls.productE = cls.ProductObj.create({'name': 'Product E', 'type': 'product'}) # Configure unit of measure. - self.uom_kg = self.env['uom.uom'].search([('category_id', '=', self.categ_kgm), ('uom_type', '=', 'reference')], limit=1) - self.uom_kg.write({ + cls.uom_kg = cls.env['uom.uom'].search([('category_id', '=', cls.categ_kgm), ('uom_type', '=', 'reference')], limit=1) + cls.uom_kg.write({ 'name': 'Test-KG', 'rounding': 0.000001}) - self.uom_tone = self.UomObj.create({ + cls.uom_tone = cls.UomObj.create({ 'name': 'Test-Tone', - 'category_id': self.categ_kgm, + 'category_id': cls.categ_kgm, 'uom_type': 'bigger', 'factor_inv': 1000.0, 'rounding': 0.001}) - self.uom_gm = self.UomObj.create({ + cls.uom_gm = cls.UomObj.create({ 'name': 'Test-G', - 'category_id': self.categ_kgm, + 'category_id': cls.categ_kgm, 'uom_type': 'smaller', 'factor': 1000.0, 'rounding': 0.001}) - self.uom_mg = self.UomObj.create({ + cls.uom_mg = cls.UomObj.create({ 'name': 'Test-MG', - 'category_id': self.categ_kgm, + 'category_id': cls.categ_kgm, 'uom_type': 'smaller', 'factor': 100000.0, 'rounding': 0.001}) # Check Unit - self.uom_unit = self.env['uom.uom'].search([('category_id', '=', self.categ_unit), ('uom_type', '=', 'reference')], limit=1) - self.uom_unit.write({ + cls.uom_unit = cls.env['uom.uom'].search([('category_id', '=', cls.categ_unit), ('uom_type', '=', 'reference')], limit=1) + cls.uom_unit.write({ 'name': 'Test-Unit', 'rounding': 1.0}) - self.uom_dozen = self.UomObj.create({ + cls.uom_dozen = cls.UomObj.create({ 'name': 'Test-DozenA', - 'category_id': self.categ_unit, + 'category_id': cls.categ_unit, 'factor_inv': 12, 'uom_type': 'bigger', 'rounding': 0.001}) - self.uom_sdozen = self.UomObj.create({ + cls.uom_sdozen = cls.UomObj.create({ 'name': 'Test-SDozenA', - 'category_id': self.categ_unit, + 'category_id': cls.categ_unit, 'factor_inv': 144, 'uom_type': 'bigger', 'rounding': 0.001}) - self.uom_sdozen_round = self.UomObj.create({ + cls.uom_sdozen_round = cls.UomObj.create({ 'name': 'Test-SDozenA Round', - 'category_id': self.categ_unit, + 'category_id': cls.categ_unit, 'factor_inv': 144, 'uom_type': 'bigger', 'rounding': 1.0}) # Product for different unit of measure. - self.DozA = self.ProductObj.create({'name': 'Dozon-A', 'type': 'product', 'uom_id': self.uom_dozen.id, 'uom_po_id': self.uom_dozen.id}) - self.SDozA = self.ProductObj.create({'name': 'SuperDozon-A', 'type': 'product', 'uom_id': self.uom_sdozen.id, 'uom_po_id': self.uom_sdozen.id}) - self.SDozARound = self.ProductObj.create({'name': 'SuperDozenRound-A', 'type': 'product', 'uom_id': self.uom_sdozen_round.id, 'uom_po_id': self.uom_sdozen_round.id}) - self.UnitA = self.ProductObj.create({'name': 'Unit-A', 'type': 'product'}) - self.kgB = self.ProductObj.create({'name': 'kg-B', 'type': 'product', 'uom_id': self.uom_kg.id, 'uom_po_id': self.uom_kg.id}) - self.gB = self.ProductObj.create({'name': 'g-B', 'type': 'product', 'uom_id': self.uom_gm.id, 'uom_po_id': self.uom_gm.id}) + cls.DozA = cls.ProductObj.create({'name': 'Dozon-A', 'type': 'product', 'uom_id': cls.uom_dozen.id, 'uom_po_id': cls.uom_dozen.id}) + cls.SDozA = cls.ProductObj.create({'name': 'SuperDozon-A', 'type': 'product', 'uom_id': cls.uom_sdozen.id, 'uom_po_id': cls.uom_sdozen.id}) + cls.SDozARound = cls.ProductObj.create({'name': 'SuperDozenRound-A', 'type': 'product', 'uom_id': cls.uom_sdozen_round.id, 'uom_po_id': cls.uom_sdozen_round.id}) + cls.UnitA = cls.ProductObj.create({'name': 'Unit-A', 'type': 'product'}) + cls.kgB = cls.ProductObj.create({'name': 'kg-B', 'type': 'product', 'uom_id': cls.uom_kg.id, 'uom_po_id': cls.uom_kg.id}) + cls.gB = cls.ProductObj.create({'name': 'g-B', 'type': 'product', 'uom_id': cls.uom_gm.id, 'uom_po_id': cls.uom_gm.id}) diff --git a/addons/stock/tests/test_inventory.py b/addons/stock/tests/test_inventory.py index b37b1a17464..730300d16d4 100644 --- a/addons/stock/tests/test_inventory.py +++ b/addons/stock/tests/test_inventory.py @@ -1,27 +1,28 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo.exceptions import ValidationError -from odoo.tests.common import TransactionCase +from odoo.tests.common import SavepointCase -class TestInventory(TransactionCase): - def setUp(self): - super(TestInventory, self).setUp() - self.stock_location = self.env.ref('stock.stock_location_stock') - self.pack_location = self.env.ref('stock.location_pack_zone') - self.pack_location.active = True - self.customer_location = self.env.ref('stock.stock_location_customers') - self.uom_unit = self.env.ref('uom.product_uom_unit') - self.product1 = self.env['product.product'].create({ +class TestInventory(SavepointCase): + @classmethod + def setUpClass(cls): + super(TestInventory, cls).setUpClass() + cls.stock_location = cls.env.ref('stock.stock_location_stock') + cls.pack_location = cls.env.ref('stock.location_pack_zone') + cls.pack_location.active = True + cls.customer_location = cls.env.ref('stock.stock_location_customers') + cls.uom_unit = cls.env.ref('uom.product_uom_unit') + cls.product1 = cls.env['product.product'].create({ 'name': 'Product A', 'type': 'product', - 'categ_id': self.env.ref('product.product_category_all').id, + 'categ_id': cls.env.ref('product.product_category_all').id, }) - self.product2 = self.env['product.product'].create({ + cls.product2 = cls.env['product.product'].create({ 'name': 'Product A', 'type': 'product', 'tracking': 'serial', - 'categ_id': self.env.ref('product.product_category_all').id, + 'categ_id': cls.env.ref('product.product_category_all').id, }) def test_inventory_1(self): diff --git a/addons/stock/tests/test_move.py b/addons/stock/tests/test_move.py index e009fc5ee7d..409966c006b 100644 --- a/addons/stock/tests/test_move.py +++ b/addons/stock/tests/test_move.py @@ -2,44 +2,45 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo.exceptions import UserError -from odoo.tests.common import TransactionCase +from odoo.tests.common import SavepointCase -class StockMove(TransactionCase): - def setUp(self): - super(StockMove, self).setUp() - self.stock_location = self.env.ref('stock.stock_location_stock') - self.customer_location = self.env.ref('stock.stock_location_customers') - self.supplier_location = self.env.ref('stock.stock_location_suppliers') - self.pack_location = self.env.ref('stock.location_pack_zone') - self.pack_location.active = True - self.transit_location = self.env['stock.location'].search([ - ('company_id', '=', self.env.user.company_id.id), +class StockMove(SavepointCase): + @classmethod + def setUpClass(cls): + super(StockMove, cls).setUpClass() + cls.stock_location = cls.env.ref('stock.stock_location_stock') + cls.customer_location = cls.env.ref('stock.stock_location_customers') + cls.supplier_location = cls.env.ref('stock.stock_location_suppliers') + cls.pack_location = cls.env.ref('stock.location_pack_zone') + cls.pack_location.active = True + cls.transit_location = cls.env['stock.location'].search([ + ('company_id', '=', cls.env.user.company_id.id), ('usage', '=', 'transit'), ], limit=1) - self.uom_unit = self.env.ref('uom.product_uom_unit') - self.uom_dozen = self.env.ref('uom.product_uom_dozen') - self.product1 = self.env['product.product'].create({ + cls.uom_unit = cls.env.ref('uom.product_uom_unit') + cls.uom_dozen = cls.env.ref('uom.product_uom_dozen') + cls.product = cls.env['product.product'].create({ 'name': 'Product A', 'type': 'product', - 'categ_id': self.env.ref('product.product_category_all').id, + 'categ_id': cls.env.ref('product.product_category_all').id, }) - self.product2 = self.env['product.product'].create({ + cls.product_serial = cls.env['product.product'].create({ 'name': 'Product A', 'type': 'product', 'tracking': 'serial', - 'categ_id': self.env.ref('product.product_category_all').id, + 'categ_id': cls.env.ref('product.product_category_all').id, }) - self.product3 = self.env['product.product'].create({ + cls.product_lot = cls.env['product.product'].create({ 'name': 'Product A', 'type': 'product', 'tracking': 'lot', - 'categ_id': self.env.ref('product.product_category_all').id, + 'categ_id': cls.env.ref('product.product_category_all').id, }) - self.product4 = self.env['product.product'].create({ + cls.product_consu = cls.env['product.product'].create({ 'name': 'Product A', 'type': 'consu', - 'categ_id': self.env.ref('product.product_category_all').id, + 'categ_id': cls.env.ref('product.product_category_all').id, }) def gather_relevant(self, product_id, location_id, lot_id=None, package_id=None, owner_id=None, strict=False): @@ -55,7 +56,7 @@ class StockMove(TransactionCase): 'name': 'test_in_1', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 100.0, }) @@ -80,11 +81,11 @@ class StockMove(TransactionCase): move1._action_done() self.assertEqual(move1.state, 'done') # no quants are created in the supplier location - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.supplier_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.supplier_location, allow_negative=True), -100.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 100.0) - self.assertEqual(len(self.gather_relevant(self.product1, self.supplier_location)), 1.0) - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location)), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.supplier_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.supplier_location, allow_negative=True), -100.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 100.0) + self.assertEqual(len(self.gather_relevant(self.product, self.supplier_location)), 1.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 1.0) def test_in_2(self): """ Receive 5 tracked products from a supplier. The create move line should have 5 @@ -96,7 +97,7 @@ class StockMove(TransactionCase): 'name': 'test_in_1', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 5.0, 'picking_type_id': self.env.ref('stock.picking_type_in').id, @@ -121,13 +122,13 @@ class StockMove(TransactionCase): self.assertEqual(move_line.product_qty, 0) # change reservation to 0 for done move self.assertEqual(move1.state, 'done') - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.supplier_location), 0.0) - supplier_quants = self.gather_relevant(self.product3, self.supplier_location) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_lot, self.supplier_location), 0.0) + supplier_quants = self.gather_relevant(self.product_lot, self.supplier_location) self.assertEqual(sum(supplier_quants.mapped('quantity')), -5.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.stock_location), 5.0) - self.assertEqual(len(self.gather_relevant(self.product3, self.supplier_location)), 1.0) - quants = self.gather_relevant(self.product3, self.stock_location) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_lot, self.stock_location), 5.0) + self.assertEqual(len(self.gather_relevant(self.product_lot, self.supplier_location)), 1.0) + quants = self.gather_relevant(self.product_lot, self.stock_location) self.assertEqual(len(quants), 1.0) for quant in quants: self.assertNotEqual(quant.in_date, False) @@ -141,7 +142,7 @@ class StockMove(TransactionCase): 'name': 'test_in_1', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 5.0, 'picking_type_id': self.env.ref('stock.picking_type_in').id, @@ -174,13 +175,13 @@ class StockMove(TransactionCase): self.assertEqual(move1.state, 'done') # Quant balance should result with 5 quant in supplier and stock - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.supplier_location), 0.0) - supplier_quants = self.gather_relevant(self.product2, self.supplier_location) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.supplier_location), 0.0) + supplier_quants = self.gather_relevant(self.product_serial, self.supplier_location) self.assertEqual(sum(supplier_quants.mapped('quantity')), -5.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location), 5.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location), 5.0) - self.assertEqual(len(self.gather_relevant(self.product2, self.supplier_location)), 5.0) - quants = self.gather_relevant(self.product2, self.stock_location) + self.assertEqual(len(self.gather_relevant(self.product_serial, self.supplier_location)), 5.0) + quants = self.gather_relevant(self.product_serial, self.stock_location) self.assertEqual(len(quants), 5.0) for quant in quants: self.assertNotEqual(quant.in_date, False) @@ -190,16 +191,16 @@ class StockMove(TransactionCase): stock and that the delivery correctly remove the single quant in stock. """ # make some stock - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 100) - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location)), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 100.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 100) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 100.0) # creation move1 = self.env['stock.move'].create({ 'name': 'test_out_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 100.0, }) @@ -213,9 +214,9 @@ class StockMove(TransactionCase): move1._action_assign() self.assertEqual(move1.state, 'assigned') self.assertEqual(len(move1.move_line_ids), 1) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) # Should be a reserved quantity and thus a quant. - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location)), 1.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 1.0) # fill the move line move_line = move1.move_line_ids[0] @@ -227,11 +228,11 @@ class StockMove(TransactionCase): move1._action_done() self.assertEqual(move1.state, 'done') # Check there is one quant in customer location - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.customer_location), 100.0) - self.assertEqual(len(self.gather_relevant(self.product1, self.customer_location)), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.customer_location), 100.0) + self.assertEqual(len(self.gather_relevant(self.product, self.customer_location)), 1.0) # there should be no quant amymore in the stock location - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0.0) - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location)), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 0.0) def test_out_2(self): """ Send a consumable product to a client. Check that a move line is created but @@ -239,16 +240,16 @@ class StockMove(TransactionCase): """ # make some stock - self.product1.type = 'consu' - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location)), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0.0) + self.product.type = 'consu' + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) # creation move1 = self.env['stock.move'].create({ 'name': 'test_out_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 100.0, }) @@ -262,9 +263,9 @@ class StockMove(TransactionCase): move1._action_assign() self.assertEqual(move1.state, 'assigned') self.assertEqual(len(move1.move_line_ids), 1) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) # Should be a reserved quantity and thus a quant. - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location)), 0.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 0.0) # fill the move line move_line = move1.move_line_ids[0] @@ -276,11 +277,11 @@ class StockMove(TransactionCase): move1._action_done() self.assertEqual(move1.state, 'done') # no quants are created in the customer location since it's a consumable - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.customer_location), 0.0) - self.assertEqual(len(self.gather_relevant(self.product1, self.customer_location)), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.customer_location), 0.0) + self.assertEqual(len(self.gather_relevant(self.product, self.customer_location)), 0.0) # there should be no quant amymore in the stock location - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0.0) - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location)), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 0.0) def test_mixed_tracking_reservation_1(self): """ Send products tracked by lot to a customer. In your stock, there are tracked and @@ -289,18 +290,18 @@ class StockMove(TransactionCase): """ lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, }) - self.env['stock.quant']._update_available_quantity(self.product3, self.stock_location, 2) - self.env['stock.quant']._update_available_quantity(self.product3, self.stock_location, 3, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product_lot, self.stock_location, 2) + self.env['stock.quant']._update_available_quantity(self.product_lot, self.stock_location, 3, lot_id=lot1) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.stock_location), 5.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_lot, self.stock_location), 5.0) # creation move1 = self.env['stock.move'].create({ 'name': 'test_in_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 5.0, }) @@ -317,22 +318,22 @@ class StockMove(TransactionCase): """ lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, }) lot2 = self.env['stock.production.lot'].create({ 'name': 'lot2', - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, }) - self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 2) - self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1, lot_id=lot1) - self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1, lot_id=lot2) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location), 4.0) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 2) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1, lot_id=lot2) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location), 4.0) # creation move1 = self.env['stock.move'].create({ 'name': 'test_in_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 4.0, }) @@ -345,11 +346,11 @@ class StockMove(TransactionCase): # assign lot3 and lot 4 to both untracked move lines lot3 = self.env['stock.production.lot'].create({ 'name': 'lot3', - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, }) lot4 = self.env['stock.production.lot'].create({ 'name': 'lot4', - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, }) untracked_move_line = move1.move_line_ids.filtered(lambda ml: not ml.lot_id) untracked_move_line[0].lot_id = lot3 @@ -358,21 +359,21 @@ class StockMove(TransactionCase): self.assertEqual(ml.product_qty, 1.0) # no changes on quants, even if i made some move lines with a lot id whom reserved on untracked quants - self.assertEqual(len(self.gather_relevant(self.product2, self.stock_location, strict=True)), 1.0) # with a qty of 2 - self.assertEqual(len(self.gather_relevant(self.product2, self.stock_location, lot_id=lot1, strict=True)), 1.0) - self.assertEqual(len(self.gather_relevant(self.product2, self.stock_location, lot_id=lot2, strict=True)), 1.0) - self.assertEqual(len(self.gather_relevant(self.product2, self.stock_location, lot_id=lot3, strict=True)), 0) - self.assertEqual(len(self.gather_relevant(self.product2, self.stock_location, lot_id=lot4, strict=True)), 0) + self.assertEqual(len(self.gather_relevant(self.product_serial, self.stock_location, strict=True)), 1.0) # with a qty of 2 + self.assertEqual(len(self.gather_relevant(self.product_serial, self.stock_location, lot_id=lot1, strict=True)), 1.0) + self.assertEqual(len(self.gather_relevant(self.product_serial, self.stock_location, lot_id=lot2, strict=True)), 1.0) + self.assertEqual(len(self.gather_relevant(self.product_serial, self.stock_location, lot_id=lot3, strict=True)), 0) + self.assertEqual(len(self.gather_relevant(self.product_serial, self.stock_location, lot_id=lot4, strict=True)), 0) move1.move_line_ids.write({'qty_done': 1.0}) move1._action_done() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location, lot_id=lot1, strict=True), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location, lot_id=lot2, strict=True), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location, lot_id=lot3, strict=True), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location, lot_id=lot4, strict=True), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, lot_id=lot1, strict=True), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, lot_id=lot2, strict=True), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, lot_id=lot3, strict=True), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, lot_id=lot4, strict=True), 0.0) def test_mixed_tracking_reservation_3(self): """ Send two products tracked by lot to a customer. In your stock, there two tracked quants @@ -382,22 +383,22 @@ class StockMove(TransactionCase): """ lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, }) lot2 = self.env['stock.production.lot'].create({ 'name': 'lot2', - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, }) - self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1, lot_id=lot1) - self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1, lot_id=lot2) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1, lot_id=lot2) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location), 2.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location), 2.0) # creation move1 = self.env['stock.move'].create({ 'name': 'test_in_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 2.0, }) @@ -406,14 +407,14 @@ class StockMove(TransactionCase): move1.move_line_ids.write({'qty_done': 1.0}) move1._action_done() - self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 2) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 2) lot3 = self.env['stock.production.lot'].create({ 'name': 'lot3', - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, }) lot4 = self.env['stock.production.lot'].create({ 'name': 'lot4', - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, }) self.env['stock.move.line'].create({ @@ -435,11 +436,11 @@ class StockMove(TransactionCase): 'lot_id': lot4.id }) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location, lot_id=lot1, strict=True), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location, lot_id=lot2, strict=True), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location, lot_id=lot3, strict=True), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location, lot_id=lot4, strict=True), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, lot_id=lot1, strict=True), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, lot_id=lot2, strict=True), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, lot_id=lot3, strict=True), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, lot_id=lot4, strict=True), 0.0) def test_mixed_tracking_reservation_4(self): """ Send two products tracked by lot to a customer. In your stock, there two tracked quants @@ -449,22 +450,22 @@ class StockMove(TransactionCase): """ lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, }) lot2 = self.env['stock.production.lot'].create({ 'name': 'lot2', - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, }) - self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1, lot_id=lot1) - self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1, lot_id=lot2) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1, lot_id=lot2) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location), 2.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location), 2.0) # creation move1 = self.env['stock.move'].create({ 'name': 'test_in_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 2.0, }) @@ -473,29 +474,29 @@ class StockMove(TransactionCase): move1.move_line_ids.write({'qty_done': 1.0}) move1._action_done() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location, lot_id=lot1, strict=True), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location, lot_id=lot2, strict=True), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, lot_id=lot1, strict=True), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, lot_id=lot2, strict=True), 0.0) - self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1) lot3 = self.env['stock.production.lot'].create({ 'name': 'lot3', - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, }) move1.move_line_ids[1].lot_id = lot3 - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location, lot_id=lot1, strict=True), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location, lot_id=lot2, strict=True), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location, lot_id=lot3, strict=True), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, lot_id=lot1, strict=True), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, lot_id=lot2, strict=True), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, lot_id=lot3, strict=True), 0.0) def test_mixed_tracking_reservation_5(self): move1 = self.env['stock.move'].create({ 'name': 'test_jenaimarre_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -504,10 +505,10 @@ class StockMove(TransactionCase): self.assertEqual(move1.state, 'confirmed') # create an untracked quant - self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1.0) lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, }) # create a new move line with a lot not assigned to any quant @@ -525,17 +526,17 @@ class StockMove(TransactionCase): # validating the move line should move the lot, not create a negative quant in stock move1._action_done() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location), 0.0) - self.assertEqual(len(self.gather_relevant(self.product2, self.stock_location)), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location), 0.0) + self.assertEqual(len(self.gather_relevant(self.product_serial, self.stock_location)), 0.0) def test_mixed_tracking_reservation_6(self): # create an untracked quant - self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1.0) move1 = self.env['stock.move'].create({ 'name': 'test_jenaimarre_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -545,11 +546,11 @@ class StockMove(TransactionCase): lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, }) lot2 = self.env['stock.production.lot'].create({ 'name': 'lot2', - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, }) move_line = move1.move_line_ids @@ -561,8 +562,8 @@ class StockMove(TransactionCase): # validating the move line should move the lot, not create a negative quant in stock move1._action_done() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location), 0.0) - self.assertEqual(len(self.gather_relevant(self.product2, self.stock_location)), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location), 0.0) + self.assertEqual(len(self.gather_relevant(self.product_serial, self.stock_location)), 0.0) def test_mixed_tracking_reservation_7(self): """ Similar test_mixed_tracking_reservation_2 but creates first the tracked quant, then the @@ -572,22 +573,22 @@ class StockMove(TransactionCase): """ lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, }) lot2 = self.env['stock.production.lot'].create({ 'name': 'lot2', - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, }) - self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1, lot_id=lot1) - self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location), 2.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location), 2.0) # creation move1 = self.env['stock.move'].create({ 'name': 'test_in_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 2.0, }) @@ -605,10 +606,10 @@ class StockMove(TransactionCase): move1._action_done() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location, lot_id=lot1, strict=True), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location, lot_id=lot2, strict=True), 0.0) - quants = self.gather_relevant(self.product2, self.stock_location) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, lot_id=lot1, strict=True), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, lot_id=lot2, strict=True), 0.0) + quants = self.gather_relevant(self.product_serial, self.stock_location) self.assertEqual(len(quants), 0) def test_mixed_tracking_reservation_8(self): @@ -619,18 +620,18 @@ class StockMove(TransactionCase): """ lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, }) # at first, we only make the tracked quant available in stock to make sure this one is selected - self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1, lot_id=lot1) # creation move1 = self.env['stock.move'].create({ 'name': 'test_mixed_tracking_reservation_7', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -641,24 +642,24 @@ class StockMove(TransactionCase): self.assertEqual(move1.move_line_ids.lot_id.id, lot1.id) # change the lot_id to one not available in stock while an untracked quant is available - self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1) lot2 = self.env['stock.production.lot'].create({ 'name': 'lot2', - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, }) move1.move_line_ids.lot_id = lot2 self.assertEqual(move1.reserved_availability, 1.0) self.assertEqual(move1.move_line_ids.lot_id.id, lot2.id) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location, strict=True), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location, lot_id=lot1, strict=True), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, strict=True), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, lot_id=lot1, strict=True), 1.0) # unreserve move1._do_unreserve() self.assertEqual(move1.reserved_availability, 0.0) self.assertEqual(len(move1.move_line_ids), 0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location, strict=True), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.stock_location, lot_id=lot1, strict=True), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, strict=True), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, lot_id=lot1, strict=True), 1.0) def test_putaway_1(self): """ Receive products from a supplier. Check that putaway rules are rightly applied on @@ -686,7 +687,7 @@ class StockMove(TransactionCase): 'name': 'test_putaway_1', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 100.0, }) @@ -837,7 +838,7 @@ class StockMove(TransactionCase): 'name': 'test_putaway_4', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 100.0, }) @@ -955,20 +956,20 @@ class StockMove(TransactionCase): more than enough products in stock. """ # make some stock - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 150.0) - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location)), 1.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 150.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 1.0) move1 = self.env['stock.move'].create({ 'name': 'test_putaway_1', 'location_id': self.stock_location.id, 'location_dest_id': self.supplier_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 100.0, }) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 150.0) - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location)), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 150.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 1.0) self.assertEqual(move1.availability, 100.0) def test_availability_2(self): @@ -976,38 +977,38 @@ class StockMove(TransactionCase): not enough products in stock. """ # make some stock - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 50.0) - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location)), 1.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 50.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 1.0) move1 = self.env['stock.move'].create({ 'name': 'test_putaway_1', 'location_id': self.stock_location.id, 'location_dest_id': self.supplier_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 100.0, }) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 50.0) - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location)), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 50.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 1.0) self.assertEqual(move1.availability, 50.0) def test_availability_3(self): lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, }) lot2 = self.env['stock.production.lot'].create({ 'name': 'lot2', - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, }) - self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, -1.0, lot_id=lot1) - self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1.0, lot_id=lot2) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, -1.0, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1.0, lot_id=lot2) move1 = self.env['stock.move'].create({ 'name': 'test_availability_3', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -1017,12 +1018,12 @@ class StockMove(TransactionCase): self.assertEqual(move1.reserved_availability, 1.0) def test_availability_4(self): - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 30.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 30.0) move1 = self.env['stock.move'].create({ 'name': 'test_availability_4', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 15.0, }) @@ -1034,7 +1035,7 @@ class StockMove(TransactionCase): 'name': 'test_availability_4', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 15.0, }) @@ -1052,9 +1053,9 @@ class StockMove(TransactionCase): self.assertEqual(move1.move_line_ids.qty_done, 15) self.assertEqual(move2.state, 'done') - stock_quants = self.gather_relevant(self.product1, self.stock_location) + stock_quants = self.gather_relevant(self.product, self.stock_location) self.assertEqual(len(stock_quants), 0) - customer_quants = self.gather_relevant(self.product1, self.customer_location) + customer_quants = self.gather_relevant(self.product, self.customer_location) self.assertEqual(customer_quants.quantity, 30) self.assertEqual(customer_quants.reserved_quantity, 0) @@ -1062,20 +1063,20 @@ class StockMove(TransactionCase): """ Check that rerun action assign only create new stock move lines instead of adding quantity in existing one. """ - self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 2.0) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 2.0) # move from shelf1 move = self.env['stock.move'].create({ 'name': 'test_edit_moveline_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 4.0, }) move._action_confirm() move._action_assign() - self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 4.0) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 4.0) move._action_assign() self.assertEqual(len(move.move_line_ids), 4.0) @@ -1090,14 +1091,14 @@ class StockMove(TransactionCase): self.uom_dozen.rounding = 1 # 6 units are available in stock - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 6.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 6.0) # the move should not be reserved move = self.env['stock.move'].create({ 'name': 'test_availability_6', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_dozen.id, 'product_uom_qty': 1, }) @@ -1106,19 +1107,19 @@ class StockMove(TransactionCase): self.assertEqual(move.state, 'confirmed') # the quants should be left untouched - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 6.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 6.0) # make 8 units available, the move should again not be reservabale - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 2.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 2.0) move._action_assign() self.assertEqual(move.state, 'confirmed') - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 8.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 8.0) # make 12 units available, this time the move should be reservable - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 4.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 4.0) move._action_assign() self.assertEqual(move.state, 'assigned') - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) # Check it isn't possible to set any value to quantity_done with self.assertRaises(UserError): @@ -1135,7 +1136,7 @@ class StockMove(TransactionCase): move.quantity_done = 1 move._action_done() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.customer_location), 12.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.customer_location), 12.0) def test_availability_7(self): """ Check that, in the scenario where a move is in a bigger uom than the uom of the quants @@ -1149,16 +1150,16 @@ class StockMove(TransactionCase): for i in range(1, 13): lot_id = self.env['stock.production.lot'].create({ 'name': 'lot%s' % str(i), - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, }) - self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1.0, lot_id=lot_id) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1.0, lot_id=lot_id) # the move should be reserved move = self.env['stock.move'].create({ 'name': 'test_availability_7', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, 'product_uom': self.uom_dozen.id, 'product_uom_qty': 1, }) @@ -1175,29 +1176,29 @@ class StockMove(TransactionCase): self.assertEqual(move.product_uom_qty, 1) self.assertEqual(move.product_uom.id, self.uom_dozen.id) self.assertEqual(move.state, 'done') - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.customer_location), 12.0) - self.assertEqual(len(self.gather_relevant(self.product2, self.customer_location)), 12) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.customer_location), 12.0) + self.assertEqual(len(self.gather_relevant(self.product_serial, self.customer_location)), 12) def test_availability_8(self): """ Test the assignment mechanism when the product quantity is decreased on a partially reserved stock move. """ # make some stock - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 3.0) - self.assertAlmostEqual(self.product1.qty_available, 3.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 3.0) + self.assertAlmostEqual(self.product.qty_available, 3.0) move_partial = self.env['stock.move'].create({ 'name': 'test_partial', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 5.0, }) move_partial._action_confirm() move_partial._action_assign() - self.assertAlmostEqual(self.product1.virtual_available, -2.0) + self.assertAlmostEqual(self.product.virtual_available, -2.0) self.assertEqual(move_partial.state, 'partially_available') move_partial.product_uom_qty = 3.0 move_partial._action_assign() @@ -1211,7 +1212,7 @@ class StockMove(TransactionCase): 'name': 'test_receipt_edit', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_dozen.id, 'product_uom_qty': 1.0, }) @@ -1229,19 +1230,19 @@ class StockMove(TransactionCase): set the state back to confirmed. """ # make some stock - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 150.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 150.0) # creation move1 = self.env['stock.move'].create({ 'name': 'test_putaway_1', 'location_id': self.stock_location.id, 'location_dest_id': self.supplier_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 100.0, }) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 150.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 150.0) self.assertEqual(move1.availability, 100.0) # confirmation @@ -1252,12 +1253,12 @@ class StockMove(TransactionCase): move1._action_assign() self.assertEqual(move1.state, 'assigned') self.assertEqual(len(move1.move_line_ids), 1) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 50.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 50.0) # unreserve move1._do_unreserve() self.assertEqual(len(move1.move_line_ids), 0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 150.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 150.0) self.assertEqual(move1.state, 'confirmed') def test_unreserve_2(self): @@ -1267,19 +1268,19 @@ class StockMove(TransactionCase): package1 = self.env['stock.quant.package'].create({'name': 'test_unreserve_2_pack'}) # make some stock - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 150.0, package_id=package1) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 150.0, package_id=package1) # creation move1 = self.env['stock.move'].create({ 'name': 'test_putaway_1', 'location_id': self.stock_location.id, 'location_dest_id': self.supplier_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 100.0, }) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, package_id=package1), 150.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, package_id=package1), 150.0) self.assertEqual(move1.availability, 100.0) # confirmation @@ -1290,28 +1291,28 @@ class StockMove(TransactionCase): move1._action_assign() self.assertEqual(move1.state, 'assigned') self.assertEqual(len(move1.move_line_ids), 1) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, package_id=package1), 50.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, package_id=package1), 50.0) # unreserve move1._do_unreserve() self.assertEqual(len(move1.move_line_ids), 0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, package_id=package1), 150.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, package_id=package1), 150.0) self.assertEqual(move1.state, 'confirmed') def test_unreserve_3(self): """ Similar to `test_unreserve_1` but checking the quants more in details. """ # make some stock - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 2) - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location)), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 2) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 2) # creation move1 = self.env['stock.move'].create({ 'name': 'test_out_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 2.0, }) @@ -1326,14 +1327,14 @@ class StockMove(TransactionCase): self.assertEqual(move1.state, 'assigned') self.assertEqual(len(move1.move_line_ids), 1) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0.0) - quants = self.gather_relevant(self.product1, self.stock_location) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) + quants = self.gather_relevant(self.product, self.stock_location) self.assertEqual(len(quants), 1.0) self.assertEqual(quants.quantity, 2.0) self.assertEqual(quants.reserved_quantity, 2.0) move1._do_unreserve() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 2.0) self.assertEqual(len(quants), 1.0) self.assertEqual(quants.quantity, 2.0) self.assertEqual(quants.reserved_quantity, 0.0) @@ -1343,16 +1344,16 @@ class StockMove(TransactionCase): """ Check the unreservation of a partially available stock move. """ # make some stock - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 2) - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location)), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 2) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 2) # creation move1 = self.env['stock.move'].create({ 'name': 'test_out_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 3.0, }) @@ -1367,14 +1368,14 @@ class StockMove(TransactionCase): self.assertEqual(move1.state, 'partially_available') self.assertEqual(len(move1.move_line_ids), 1) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0.0) - quants = self.gather_relevant(self.product1, self.stock_location) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) + quants = self.gather_relevant(self.product, self.stock_location) self.assertEqual(len(quants), 1.0) self.assertEqual(quants.quantity, 2.0) self.assertEqual(quants.reserved_quantity, 2.0) move1._do_unreserve() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 2.0) self.assertEqual(len(quants), 1.0) self.assertEqual(quants.quantity, 2.0) self.assertEqual(quants.reserved_quantity, 0.0) @@ -1384,21 +1385,21 @@ class StockMove(TransactionCase): """ Check the unreservation of a stock move reserved on multiple quants. """ # make some stock - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 3) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 3) self.env['stock.quant'].create({ - 'product_id': self.product1.id, + 'product_id': self.product.id, 'location_id': self.stock_location.id, 'quantity': 2, }) - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location)), 2) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 5) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 2) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 5) # creation move1 = self.env['stock.move'].create({ 'name': 'test_unreserve_5', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 5.0, }) @@ -1414,7 +1415,7 @@ class StockMove(TransactionCase): self.assertEqual(len(move1.move_line_ids), 1) move1._do_unreserve() - quants = self.gather_relevant(self.product1, self.stock_location) + quants = self.gather_relevant(self.product, self.stock_location) self.assertEqual(len(quants), 2.0) for quant in quants: self.assertEqual(quant.reserved_quantity, 0) @@ -1423,26 +1424,26 @@ class StockMove(TransactionCase): """ In a situation with a negative and a positive quant, reserve and unreserve. """ q1 = self.env['stock.quant'].create({ - 'product_id': self.product1.id, + 'product_id': self.product.id, 'location_id': self.stock_location.id, 'quantity': -10, 'reserved_quantity': 0, }) q2 = self.env['stock.quant'].create({ - 'product_id': self.product1.id, + 'product_id': self.product.id, 'location_id': self.stock_location.id, 'quantity': 30.0, 'reserved_quantity': 10.0, }) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 10.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 10.0) move1 = self.env['stock.move'].create({ 'name': 'test_unreserve_6', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 10.0, }) @@ -1451,13 +1452,13 @@ class StockMove(TransactionCase): self.assertEqual(move1.state, 'assigned') self.assertEqual(len(move1.move_line_ids), 1) self.assertEqual(move1.move_line_ids.product_qty, 10) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) self.assertEqual(q2.reserved_quantity, 20) move1._do_unreserve() self.assertEqual(move1.state, 'confirmed') self.assertEqual(len(move1.move_line_ids), 0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 10.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 10.0) self.assertEqual(q2.reserved_quantity, 10) def test_link_assign_1(self): @@ -1465,14 +1466,14 @@ class StockMove(TransactionCase): untracked product. """ # make some stock - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0) - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location)), 1.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 1.0) move_stock_pack = self.env['stock.move'].create({ 'name': 'test_link_assign_1_1', 'location_id': self.stock_location.id, 'location_dest_id': self.pack_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -1480,7 +1481,7 @@ class StockMove(TransactionCase): 'name': 'test_link_assign_1_2', 'location_id': self.pack_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -1503,18 +1504,18 @@ class StockMove(TransactionCase): """ lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.product1.id, + 'product_id': self.product.id, }) # make some stock - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot1) - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location, lot1)), 1.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0, lot_id=lot1) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location, lot1)), 1.0) move_stock_pack = self.env['stock.move'].create({ 'name': 'test_link_2_1', 'location_id': self.stock_location.id, 'location_dest_id': self.pack_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -1522,7 +1523,7 @@ class StockMove(TransactionCase): 'name': 'test_link_2_2', 'location_id': self.pack_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -1534,33 +1535,33 @@ class StockMove(TransactionCase): move_line_stock_pack = move_stock_pack.move_line_ids[0] self.assertEqual(move_line_stock_pack.lot_id.id, lot1.id) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot1), 0.0) - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location, lot1)), 1.0) - self.assertEqual(len(self.gather_relevant(self.product1, self.pack_location, lot1)), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot1), 0.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location, lot1)), 1.0) + self.assertEqual(len(self.gather_relevant(self.product, self.pack_location, lot1)), 0.0) move_line_stock_pack.qty_done = 1.0 move_stock_pack._action_done() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot1), 0.0) - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location, lot1)), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot1), 0.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location, lot1)), 0.0) move_line_pack_cust = move_pack_cust.move_line_ids[0] self.assertEqual(move_line_pack_cust.lot_id.id, lot1.id) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.pack_location, lot_id=lot1), 0.0) - self.assertEqual(len(self.gather_relevant(self.product1, self.pack_location, lot1)), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.pack_location, lot_id=lot1), 0.0) + self.assertEqual(len(self.gather_relevant(self.product, self.pack_location, lot1)), 1.0) def test_link_assign_3(self): """ Test the assignment mechanism when three chained stock moves (2 sources, 1 dest) try to move multiple units of an untracked product. """ # make some stock - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 2.0) - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location)), 1.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 2.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 1.0) move_stock_pack_1 = self.env['stock.move'].create({ 'name': 'test_link_assign_1_1', 'location_id': self.stock_location.id, 'location_dest_id': self.pack_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -1568,7 +1569,7 @@ class StockMove(TransactionCase): 'name': 'test_link_assign_1_1', 'location_id': self.stock_location.id, 'location_dest_id': self.pack_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -1576,7 +1577,7 @@ class StockMove(TransactionCase): 'name': 'test_link_assign_1_2', 'location_id': self.pack_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 2.0, }) @@ -1598,8 +1599,8 @@ class StockMove(TransactionCase): self.assertEqual(move_pack_cust.state, 'partially_available') self.assertEqual(len(move_pack_cust.move_line_ids), 1) # Should have 1 quant in stock_location and another in pack_location - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location)), 1.0) - self.assertEqual(len(self.gather_relevant(self.product1, self.pack_location)), 1.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 1.0) + self.assertEqual(len(self.gather_relevant(self.product, self.pack_location)), 1.0) move_stock_pack_2._action_assign() self.assertEqual(move_stock_pack_2.state, 'assigned') @@ -1608,8 +1609,8 @@ class StockMove(TransactionCase): move_stock_pack_2._action_done() self.assertEqual(move_stock_pack_2.state, 'done') - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location)), 0.0) - self.assertEqual(len(self.gather_relevant(self.product1, self.pack_location)), 1.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 0.0) + self.assertEqual(len(self.gather_relevant(self.product, self.pack_location)), 1.0) self.assertEqual(move_pack_cust.state, 'assigned') self.assertEqual(len(move_pack_cust.move_line_ids), 1) @@ -1625,18 +1626,18 @@ class StockMove(TransactionCase): """ lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.product1.id, + 'product_id': self.product.id, }) # make some stock - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 2.0, lot_id=lot1) - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location, lot1)), 1.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 2.0, lot_id=lot1) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location, lot1)), 1.0) move_stock_pack_1 = self.env['stock.move'].create({ 'name': 'test_link_assign_1_1', 'location_id': self.stock_location.id, 'location_dest_id': self.pack_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -1644,7 +1645,7 @@ class StockMove(TransactionCase): 'name': 'test_link_assign_1_1', 'location_id': self.stock_location.id, 'location_dest_id': self.pack_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -1652,7 +1653,7 @@ class StockMove(TransactionCase): 'name': 'test_link_assign_1_2', 'location_id': self.pack_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 2.0, }) @@ -1691,13 +1692,13 @@ class StockMove(TransactionCase): move multiple units of an untracked product. """ # make some stock - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 2.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 2.0) move_stock_pack = self.env['stock.move'].create({ 'name': 'test_link_assign_1_1', 'location_id': self.stock_location.id, 'location_dest_id': self.pack_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 2.0, }) @@ -1705,7 +1706,7 @@ class StockMove(TransactionCase): 'name': 'test_link_assign_1_1', 'location_id': self.pack_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -1713,7 +1714,7 @@ class StockMove(TransactionCase): 'name': 'test_link_assign_1_2', 'location_id': self.pack_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -1746,7 +1747,7 @@ class StockMove(TransactionCase): 'name': 'test_link_assign_6_1', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 3.0, }) @@ -1754,7 +1755,7 @@ class StockMove(TransactionCase): 'name': 'test_link_assign_6_1', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 2.0, }) @@ -1762,7 +1763,7 @@ class StockMove(TransactionCase): 'name': 'test_link_assign_6_1', 'location_id': self.stock_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 3.0, }) @@ -1771,7 +1772,7 @@ class StockMove(TransactionCase): 'name': 'test_link_assign_6_1', 'location_id': self.stock_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 3.0, }) @@ -1783,7 +1784,7 @@ class StockMove(TransactionCase): self.assertEqual(move_supp_stock_2.state, 'confirmed') self.assertEqual(move_stock_stock_1.state, 'waiting') self.assertEqual(move_stock_stock_2.state, 'waiting') - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) # do the fist move, it'll bring 3 units in stock location so only `move_stock_stock_1` # should be assigned @@ -1799,7 +1800,7 @@ class StockMove(TransactionCase): self.uom_dozen.rounding = 1 # 6 units are available in stock - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 6.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 6.0) # create pickings and moves for a pick -> pack mto scenario picking_stock_pack = self.env['stock.picking'].create({ @@ -1811,7 +1812,7 @@ class StockMove(TransactionCase): 'name': 'test_link_assign_7', 'location_id': self.stock_location.id, 'location_dest_id': self.pack_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_dozen.id, 'product_uom_qty': 1.0, 'picking_id': picking_stock_pack.id, @@ -1825,7 +1826,7 @@ class StockMove(TransactionCase): 'name': 'test_link_assign_7', 'location_id': self.pack_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_dozen.id, 'product_uom_qty': 1.0, 'picking_id': picking_pack_cust.id, @@ -1842,7 +1843,7 @@ class StockMove(TransactionCase): # move the 6 units by adding an unreserved move line move_stock_pack.write({'move_line_ids': [(0, 0, { - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom_id': self.uom_unit.id, 'qty_done': 6, 'product_uom_qty': 0, @@ -1875,7 +1876,7 @@ class StockMove(TransactionCase): # move a dozen on the backorder to see how we handle the extra move backorder = self.env['stock.picking'].search([('backorder_id', '=', picking_stock_pack.id)]) backorder.move_lines.write({'move_line_ids': [(0, 0, { - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom_id': self.uom_dozen.id, 'qty_done': 1, 'product_uom_qty': 0, @@ -1900,7 +1901,7 @@ class StockMove(TransactionCase): self.assertEqual(move_pack_cust.state, 'assigned') self.assertEqual(move_line_pack_cust.product_uom_qty, 12) self.assertEqual(move_line_pack_cust.product_uom_id.id, self.uom_unit.id) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, move_stock_pack.location_dest_id), 6) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, move_stock_pack.location_dest_id), 6) def test_link_assign_8(self): """ Set the rounding of the dozen to 1.0, create a chain of two move for a dozen, the product @@ -1913,9 +1914,9 @@ class StockMove(TransactionCase): for i in range(1, 13): lot_id = self.env['stock.production.lot'].create({ 'name': 'lot%s' % str(i), - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, }) - self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1.0, lot_id=lot_id) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1.0, lot_id=lot_id) # create pickings and moves for a pick -> pack mto scenario picking_stock_pack = self.env['stock.picking'].create({ @@ -1927,7 +1928,7 @@ class StockMove(TransactionCase): 'name': 'test_link_assign_7', 'location_id': self.stock_location.id, 'location_dest_id': self.pack_location.id, - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, 'product_uom': self.uom_dozen.id, 'product_uom_qty': 1.0, 'picking_id': picking_stock_pack.id, @@ -1941,7 +1942,7 @@ class StockMove(TransactionCase): 'name': 'test_link_assign_7', 'location_id': self.pack_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, 'product_uom': self.uom_dozen.id, 'product_uom_qty': 1.0, 'picking_id': picking_pack_cust.id, @@ -1980,9 +1981,9 @@ class StockMove(TransactionCase): for i in range(1, 4): lot_id = self.env['stock.production.lot'].create({ 'name': 'lot%s' % str(i), - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, }) - self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1.0, lot_id=lot_id) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1.0, lot_id=lot_id) picking_stock_pack = self.env['stock.picking'].create({ 'location_id': self.stock_location.id, @@ -1993,7 +1994,7 @@ class StockMove(TransactionCase): 'name': 'test_link_assign_9', 'location_id': self.stock_location.id, 'location_dest_id': self.pack_location.id, - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, 'product_uom': uom_3units.id, 'product_uom_qty': 1.0, 'picking_id': picking_stock_pack.id, @@ -2007,7 +2008,7 @@ class StockMove(TransactionCase): 'name': 'test_link_assign_0', 'location_id': self.pack_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, 'product_uom': uom_3units.id, 'product_uom_qty': 1.0, 'picking_id': picking_pack_cust.id, @@ -2038,7 +2039,7 @@ class StockMove(TransactionCase): # force the serial number and validate lot3 = self.env['stock.production.lot'].search([('name', '=', "lot3")]) backorder.write({'move_line_ids': [(0, 0, { - 'product_id': self.product2.id, + 'product_id': self.product_serial.id, 'product_uom_id': self.uom_unit.id, 'qty_done': 1, 'product_uom_qty': 0, @@ -2054,8 +2055,8 @@ class StockMove(TransactionCase): overprocessed_wizard = self.env['stock.overprocessed.transfer'].browse(overprocessed_wizard['res_id']) overprocessed_wizard.action_confirm() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.customer_location), 3) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product2, self.pack_location), 0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.customer_location), 3) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.pack_location), 0) def test_link_assign_10(self): """ Test the assignment mechanism with partial availability. @@ -2063,14 +2064,14 @@ class StockMove(TransactionCase): # make some stock: # stock location: 2.0 # pack location: -1.0 - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 2.0) - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location)), 1.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 2.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 1.0) move_out = self.env['stock.move'].create({ 'name': 'test_link_assign_out', 'location_id': self.pack_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -2078,13 +2079,13 @@ class StockMove(TransactionCase): move_out._action_assign() move_out.quantity_done = 1.0 move_out._action_done() - self.assertEqual(len(self.gather_relevant(self.product1, self.pack_location)), 1.0) + self.assertEqual(len(self.gather_relevant(self.product, self.pack_location)), 1.0) move_stock_pack = self.env['stock.move'].create({ 'name': 'test_link_assign_1_1', 'location_id': self.stock_location.id, 'location_dest_id': self.pack_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 2.0, }) @@ -2092,7 +2093,7 @@ class StockMove(TransactionCase): 'name': 'test_link_assign_1_2', 'location_id': self.pack_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 2.0, }) @@ -2112,12 +2113,12 @@ class StockMove(TransactionCase): """ Test that _free_reservation work when quantity is only available on reserved move lines. """ - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 10.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 10.0) move1 = self.env['stock.move'].create({ 'name': 'test_use_unreserved_move_line_1_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 5.0, }) @@ -2125,7 +2126,7 @@ class StockMove(TransactionCase): 'name': 'test_use_unreserved_move_line_1_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 5.0, }) @@ -2137,7 +2138,7 @@ class StockMove(TransactionCase): 'name': 'test_use_unreserved_move_line_1_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 0.0, 'quantity_done': 1.0, @@ -2146,7 +2147,7 @@ class StockMove(TransactionCase): move3._action_assign() move3._action_done() self.assertEqual(move3.state, 'done') - quant = self.env['stock.quant']._gather(self.product1, self.stock_location) + quant = self.env['stock.quant']._gather(self.product, self.stock_location) self.assertEqual(quant.quantity, 9.0) self.assertEqual(quant.reserved_quantity, 9.0) @@ -2155,14 +2156,14 @@ class StockMove(TransactionCase): correctly unreserves the other one. """ # make some stock - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0) # prepare the conflicting move move1 = self.env['stock.move'].create({ 'name': 'test_use_unreserved_move_line_1_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -2170,13 +2171,13 @@ class StockMove(TransactionCase): 'name': 'test_use_unreserved_move_line_1_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) # reserve those move - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) move1._action_confirm() move1._action_assign() self.assertEqual(move1.state, 'assigned') @@ -2186,7 +2187,7 @@ class StockMove(TransactionCase): # use the product from the first one move2.write({'move_line_ids': [(0, 0, { - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom_id': self.uom_unit.id, 'qty_done': 1, 'product_uom_qty': 0, @@ -2200,7 +2201,7 @@ class StockMove(TransactionCase): # the first move should go back to confirmed self.assertEqual(move1.state, 'confirmed') - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) def test_use_unreserved_move_line_2(self): """ Test that validating a stock move linked to a tracked product reserved by another one @@ -2208,18 +2209,18 @@ class StockMove(TransactionCase): """ lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.product1.id, + 'product_id': self.product.id, }) # make some stock - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0, lot_id=lot1) # prepare the conflicting move move1 = self.env['stock.move'].create({ 'name': 'test_use_unreserved_move_line_1_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -2227,13 +2228,13 @@ class StockMove(TransactionCase): 'name': 'test_use_unreserved_move_line_1_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) # reserve those move - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot1), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot1), 1.0) move1._action_confirm() move1._action_assign() self.assertEqual(move1.state, 'assigned') @@ -2243,7 +2244,7 @@ class StockMove(TransactionCase): # use the product from the first one move2.write({'move_line_ids': [(0, 0, { - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom_id': self.uom_unit.id, 'qty_done': 1, 'product_uom_qty': 0, @@ -2257,20 +2258,20 @@ class StockMove(TransactionCase): # the first move should go back to confirmed self.assertEqual(move1.state, 'confirmed') - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot1), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot1), 0.0) def test_use_unreserved_move_line_3(self): """ Test the behavior of `_free_reservation` when ran on a recordset of move lines where some are assigned and some are force assigned. `_free_reservation` should not use an already processed move line when looking for a move line candidate to unreserve. """ - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0) move1 = self.env['stock.move'].create({ 'name': 'test_use_unreserved_move_line_3', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 3.0, }) @@ -2280,7 +2281,7 @@ class StockMove(TransactionCase): # add a forced move line in `move1` move1.write({'move_line_ids': [(0, 0, { - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom_id': self.uom_unit.id, 'qty_done': 2, 'product_uom_qty': 0, @@ -2292,7 +2293,7 @@ class StockMove(TransactionCase): })]}) move1._action_done() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.customer_location), 3.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.customer_location), 3.0) def test_edit_reserved_move_line_1(self): """ Test that editing a stock move line linked to an untracked product correctly and @@ -2309,33 +2310,33 @@ class StockMove(TransactionCase): 'usage': 'internal', 'location_id': self.stock_location.id, }) - self.env['stock.quant']._update_available_quantity(self.product1, shelf1_location, 1.0) - self.env['stock.quant']._update_available_quantity(self.product1, shelf2_location, 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf2_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) + self.env['stock.quant']._update_available_quantity(self.product, shelf1_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product, shelf2_location, 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf2_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 2.0) move1 = self.env['stock.move'].create({ 'name': 'test_edit_moveline_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) move1._action_confirm() move1._action_assign() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf2_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf2_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) move1.move_line_ids.location_id = shelf2_location.id self.assertEqual(move1.reserved_availability, 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf2_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf2_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) def test_edit_reserved_move_line_2(self): """ Test that editing a stock move line linked to a tracked product correctly and directly @@ -2343,23 +2344,23 @@ class StockMove(TransactionCase): """ lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.product1.id, + 'product_id': self.product.id, }) lot2 = self.env['stock.production.lot'].create({ 'name': 'lot2', - 'product_id': self.product1.id, + 'product_id': self.product.id, }) - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot1) - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot2) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot1), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot2), 1.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0, lot_id=lot2) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 2.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot1), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot2), 1.0) move1 = self.env['stock.move'].create({ 'name': 'test_edit_moveline_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -2367,16 +2368,16 @@ class StockMove(TransactionCase): move1._action_assign() self.assertEqual(move1.reserved_availability, 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot1), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot2), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot1), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot2), 1.0) move1.move_line_ids.lot_id = lot2.id self.assertEqual(move1.reserved_availability, 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot1), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot2), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot1), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot2), 0.0) def test_edit_reserved_move_line_3(self): """ Test that editing a stock move line linked to a packed product correctly and directly @@ -2385,33 +2386,33 @@ class StockMove(TransactionCase): package1 = self.env['stock.quant.package'].create({'name': 'test_edit_reserved_move_line_3'}) package2 = self.env['stock.quant.package'].create({'name': 'test_edit_reserved_move_line_3'}) - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, package_id=package1) - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, package_id=package2) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, package_id=package1), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, package_id=package2), 1.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0, package_id=package1) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0, package_id=package2) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 2.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, package_id=package1), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, package_id=package2), 1.0) move1 = self.env['stock.move'].create({ 'name': 'test_edit_moveline_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) move1._action_confirm() move1._action_assign() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, package_id=package1), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, package_id=package2), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, package_id=package1), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, package_id=package2), 1.0) move1.move_line_ids.package_id = package2.id self.assertEqual(move1.reserved_availability, 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, package_id=package1), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, package_id=package2), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, package_id=package1), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, package_id=package2), 0.0) def test_edit_reserved_move_line_4(self): """ Test that editing a stock move line linked to an owned product correctly and directly @@ -2420,33 +2421,33 @@ class StockMove(TransactionCase): owner1 = self.env['res.partner'].create({'name': 'test_edit_reserved_move_line_4_1'}) owner2 = self.env['res.partner'].create({'name': 'test_edit_reserved_move_line_4_2'}) - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, owner_id=owner1) - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, owner_id=owner2) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, owner_id=owner1), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, owner_id=owner2), 1.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0, owner_id=owner1) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0, owner_id=owner2) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 2.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, owner_id=owner1), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, owner_id=owner2), 1.0) move1 = self.env['stock.move'].create({ 'name': 'test_edit_moveline_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) move1._action_confirm() move1._action_assign() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, owner_id=owner1), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, owner_id=owner2), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, owner_id=owner1), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, owner_id=owner2), 1.0) move1.move_line_ids.owner_id = owner2.id self.assertEqual(move1.reserved_availability, 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, owner_id=owner1), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, owner_id=owner2), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, owner_id=owner1), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, owner_id=owner2), 0.0) def test_edit_reserved_move_line_5(self): """ Test that editing a stock move line linked to a packed and tracked product correctly @@ -2455,41 +2456,41 @@ class StockMove(TransactionCase): """ lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.product1.id, + 'product_id': self.product.id, }) lot2 = self.env['stock.production.lot'].create({ 'name': 'lot2', - 'product_id': self.product1.id, + 'product_id': self.product.id, }) package1 = self.env['stock.quant.package'].create({'name': 'test_edit_reserved_move_line_5'}) - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot1, package_id=package1) - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot2) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot1, package_id=package1), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot2), 1.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0, lot_id=lot1, package_id=package1) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0, lot_id=lot2) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 2.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot1, package_id=package1), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot2), 1.0) move1 = self.env['stock.move'].create({ 'name': 'test_edit_moveline_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) move1._action_confirm() move1._action_assign() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot1, package_id=package1), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot2), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot1, package_id=package1), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot2), 1.0) move_line = move1.move_line_ids[0] move_line.write({'package_id': False, 'lot_id': lot2.id}) self.assertEqual(move1.reserved_availability, 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot1, package_id=package1), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot2), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot1, package_id=package1), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot2), 0.0) def test_edit_reserved_move_line_6(self): """ Test that editing a stock move line linked to an untracked product correctly and @@ -2506,32 +2507,32 @@ class StockMove(TransactionCase): 'usage': 'internal', 'location_id': self.stock_location.id, }) - self.env['stock.quant']._update_available_quantity(self.product1, shelf1_location, 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf2_location), 0.0) + self.env['stock.quant']._update_available_quantity(self.product, shelf1_location, 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf2_location), 0.0) move1 = self.env['stock.move'].create({ 'name': 'test_edit_moveline_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) move1._action_confirm() move1._action_assign() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf2_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf2_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) move1.move_line_ids.location_id = shelf2_location.id self.assertEqual(move1.reserved_availability, 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf2_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf2_location), 0.0) def test_edit_reserved_move_line_7(self): """ Send 5 tracked products to a client, but these products do not have any lot set in our @@ -2542,17 +2543,17 @@ class StockMove(TransactionCase): # """ lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, }) # make some stock without assigning a lot id - self.env['stock.quant']._update_available_quantity(self.product3, self.stock_location, 5) + self.env['stock.quant']._update_available_quantity(self.product_lot, self.stock_location, 5) # creation move1 = self.env['stock.move'].create({ 'name': 'test_in_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 5.0, }) @@ -2577,10 +2578,10 @@ class StockMove(TransactionCase): self.assertEqual(move_line.product_qty, 0) # change reservation to 0 for done move self.assertEqual(move1.state, 'done') - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.stock_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.stock_location, lot_id=lot1, strict=True), 0.0) - self.assertEqual(len(self.gather_relevant(self.product3, self.stock_location)), 0.0) - self.assertEqual(len(self.gather_relevant(self.product3, self.stock_location, lot_id=lot1, strict=True)), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_lot, self.stock_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_lot, self.stock_location, lot_id=lot1, strict=True), 0.0) + self.assertEqual(len(self.gather_relevant(self.product_lot, self.stock_location)), 0.0) + self.assertEqual(len(self.gather_relevant(self.product_lot, self.stock_location, lot_id=lot1, strict=True)), 0.0) def test_edit_reserved_move_line_8(self): """ Send 5 tracked products to a client, but some of these products do not have any lot set @@ -2590,22 +2591,22 @@ class StockMove(TransactionCase): """ lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, }) lot2 = self.env['stock.production.lot'].create({ 'name': 'lot2', - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, }) # make some stock without assigning a lot id - self.env['stock.quant']._update_available_quantity(self.product3, self.stock_location, 3) - self.env['stock.quant']._update_available_quantity(self.product3, self.stock_location, 2, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product_lot, self.stock_location, 3) + self.env['stock.quant']._update_available_quantity(self.product_lot, self.stock_location, 2, lot_id=lot1) # creation move1 = self.env['stock.move'].create({ 'name': 'test_in_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 5.0, }) @@ -2642,12 +2643,12 @@ class StockMove(TransactionCase): self.assertEqual(tracked_move_line.product_qty, 0) # change reservation to 0 for done move self.assertEqual(move1.state, 'done') - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.stock_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.stock_location, lot_id=lot1, strict=True), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.stock_location, lot_id=lot2, strict=True), 0.0) - self.assertEqual(len(self.gather_relevant(self.product3, self.stock_location)), 0.0) - self.assertEqual(len(self.gather_relevant(self.product3, self.stock_location, lot_id=lot1, strict=True)), 0.0) - self.assertEqual(len(self.gather_relevant(self.product3, self.stock_location, lot_id=lot2, strict=True)), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_lot, self.stock_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_lot, self.stock_location, lot_id=lot1, strict=True), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_lot, self.stock_location, lot_id=lot2, strict=True), 0.0) + self.assertEqual(len(self.gather_relevant(self.product_lot, self.stock_location)), 0.0) + self.assertEqual(len(self.gather_relevant(self.product_lot, self.stock_location, lot_id=lot1, strict=True)), 0.0) + self.assertEqual(len(self.gather_relevant(self.product_lot, self.stock_location, lot_id=lot2, strict=True)), 0.0) def test_edit_done_move_line_1(self): """ Test that editing a done stock move line linked to an untracked product correctly and @@ -2664,18 +2665,18 @@ class StockMove(TransactionCase): 'usage': 'internal', 'location_id': self.stock_location.id, }) - self.env['stock.quant']._update_available_quantity(self.product1, shelf1_location, 1.0) - self.env['stock.quant']._update_available_quantity(self.product1, shelf2_location, 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf2_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) + self.env['stock.quant']._update_available_quantity(self.product, shelf1_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product, shelf2_location, 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf2_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 2.0) # move from shelf1 move1 = self.env['stock.move'].create({ 'name': 'test_edit_moveline_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -2684,16 +2685,16 @@ class StockMove(TransactionCase): move1.move_line_ids.qty_done = 1 move1._action_done() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf2_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf2_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) # edit once done, we actually moved from shelf2 move1.move_line_ids.location_id = shelf2_location.id - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf2_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf2_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) def test_edit_done_move_line_2(self): """ Test that editing a done stock move line linked to a tracked product correctly and directly @@ -2701,23 +2702,23 @@ class StockMove(TransactionCase): """ lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.product1.id, + 'product_id': self.product.id, }) lot2 = self.env['stock.production.lot'].create({ 'name': 'lot2', - 'product_id': self.product1.id, + 'product_id': self.product.id, }) - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot1) - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot2) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot1), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot2), 1.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0, lot_id=lot2) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 2.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot1), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot2), 1.0) move1 = self.env['stock.move'].create({ 'name': 'test_edit_moveline_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -2726,17 +2727,17 @@ class StockMove(TransactionCase): move1.move_line_ids.qty_done = 1 move1._action_done() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot1), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot2), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot1), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot2), 1.0) move1.move_line_ids.lot_id = lot2.id # reserved_availability should always been 0 for done move. self.assertEqual(move1.reserved_availability, 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot1), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot2), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot1), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot2), 0.0) def test_edit_done_move_line_3(self): """ Test that editing a done stock move line linked to a packed product correctly and directly @@ -2745,17 +2746,17 @@ class StockMove(TransactionCase): package1 = self.env['stock.quant.package'].create({'name': 'test_edit_reserved_move_line_3'}) package2 = self.env['stock.quant.package'].create({'name': 'test_edit_reserved_move_line_3'}) - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, package_id=package1) - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, package_id=package2) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, package_id=package1), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, package_id=package2), 1.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0, package_id=package1) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0, package_id=package2) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 2.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, package_id=package1), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, package_id=package2), 1.0) move1 = self.env['stock.move'].create({ 'name': 'test_edit_moveline_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -2764,15 +2765,15 @@ class StockMove(TransactionCase): move1.move_line_ids.qty_done = 1 move1._action_done() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, package_id=package1), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, package_id=package2), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, package_id=package1), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, package_id=package2), 1.0) move1.move_line_ids.package_id = package2.id - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, package_id=package1), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, package_id=package2), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, package_id=package1), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, package_id=package2), 0.0) def test_edit_done_move_line_4(self): """ Test that editing a done stock move line linked to an owned product correctly and directly @@ -2781,17 +2782,17 @@ class StockMove(TransactionCase): owner1 = self.env['res.partner'].create({'name': 'test_edit_reserved_move_line_4_1'}) owner2 = self.env['res.partner'].create({'name': 'test_edit_reserved_move_line_4_2'}) - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, owner_id=owner1) - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, owner_id=owner2) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, owner_id=owner1), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, owner_id=owner2), 1.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0, owner_id=owner1) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0, owner_id=owner2) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 2.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, owner_id=owner1), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, owner_id=owner2), 1.0) move1 = self.env['stock.move'].create({ 'name': 'test_edit_moveline_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -2800,15 +2801,15 @@ class StockMove(TransactionCase): move1.move_line_ids.qty_done = 1 move1._action_done() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, owner_id=owner1), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, owner_id=owner2), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, owner_id=owner1), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, owner_id=owner2), 1.0) move1.move_line_ids.owner_id = owner2.id - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, owner_id=owner1), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, owner_id=owner2), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, owner_id=owner1), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, owner_id=owner2), 0.0) def test_edit_done_move_line_5(self): """ Test that editing a done stock move line linked to a packed and tracked product correctly @@ -2817,25 +2818,25 @@ class StockMove(TransactionCase): """ lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.product1.id, + 'product_id': self.product.id, }) lot2 = self.env['stock.production.lot'].create({ 'name': 'lot2', - 'product_id': self.product1.id, + 'product_id': self.product.id, }) package1 = self.env['stock.quant.package'].create({'name': 'test_edit_reserved_move_line_5'}) - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot1, package_id=package1) - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot2) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot1, package_id=package1), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot2), 1.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0, lot_id=lot1, package_id=package1) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0, lot_id=lot2) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 2.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot1, package_id=package1), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot2), 1.0) move1 = self.env['stock.move'].create({ 'name': 'test_edit_moveline_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -2844,15 +2845,15 @@ class StockMove(TransactionCase): move1.move_line_ids.qty_done = 1 move1._action_done() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot1, package_id=package1), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot2), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot1, package_id=package1), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot2), 1.0) move_line = move1.move_line_ids[0] move_line.write({'package_id': False, 'lot_id': lot2.id}) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot1, package_id=package1), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, lot_id=lot2), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot1, package_id=package1), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, lot_id=lot2), 0.0) def test_edit_done_move_line_6(self): """ Test that editing a done stock move line linked to an untracked product correctly and @@ -2869,16 +2870,16 @@ class StockMove(TransactionCase): 'usage': 'internal', 'location_id': self.stock_location.id, }) - self.env['stock.quant']._update_available_quantity(self.product1, shelf1_location, 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf2_location), 0.0) + self.env['stock.quant']._update_available_quantity(self.product, shelf1_location, 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf2_location), 0.0) move1 = self.env['stock.move'].create({ 'name': 'test_edit_moveline_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -2887,16 +2888,16 @@ class StockMove(TransactionCase): move1.move_line_ids.qty_done = 1 move1._action_done() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf2_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf2_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) move1.move_line_ids.location_id = shelf2_location.id - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf2_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf2_location, allow_negative=True), -1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf2_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf2_location, allow_negative=True), -1.0) def test_edit_done_move_line_7(self): """ Test that editing a done stock move line linked to an untracked product correctly and @@ -2914,17 +2915,17 @@ class StockMove(TransactionCase): 'usage': 'internal', 'location_id': self.stock_location.id, }) - self.env['stock.quant']._update_available_quantity(self.product1, shelf1_location, 1.0) - self.env['stock.quant']._update_available_quantity(self.product1, shelf2_location, 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 2.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf2_location), 1.0) + self.env['stock.quant']._update_available_quantity(self.product, shelf1_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product, shelf2_location, 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 2.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf2_location), 1.0) move1 = self.env['stock.move'].create({ 'name': 'test_edit_moveline_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -2937,7 +2938,7 @@ class StockMove(TransactionCase): 'name': 'test_edit_moveline_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -2945,15 +2946,15 @@ class StockMove(TransactionCase): move2._action_assign() self.assertEqual(move2.state, 'assigned') - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf2_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf2_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) move1.move_line_ids.location_id = shelf2_location.id - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf2_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf2_location), 0.0) self.assertEqual(move2.state, 'confirmed') def test_edit_done_move_line_8(self): @@ -2966,16 +2967,16 @@ class StockMove(TransactionCase): 'usage': 'internal', 'location_id': self.stock_location.id, }) - self.env['stock.quant']._update_available_quantity(self.product1, shelf1_location, 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) + self.env['stock.quant']._update_available_quantity(self.product, shelf1_location, 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) # move from shelf1 move1 = self.env['stock.move'].create({ 'name': 'test_edit_moveline_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -2985,16 +2986,16 @@ class StockMove(TransactionCase): move1._action_done() self.assertEqual(move1.product_uom_qty, 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) # edit once done, we actually moved 2 products move1.move_line_ids.qty_done = 2 - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location, allow_negative=True), -1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location, allow_negative=True), -1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location, allow_negative=True), -1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, allow_negative=True), -1.0) self.assertEqual(move1.product_uom_qty, 2.0) def test_edit_done_move_line_9(self): @@ -3006,16 +3007,16 @@ class StockMove(TransactionCase): 'usage': 'internal', 'location_id': self.stock_location.id, }) - self.env['stock.quant']._update_available_quantity(self.product1, shelf1_location, 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) + self.env['stock.quant']._update_available_quantity(self.product, shelf1_location, 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) # move from shelf1 move1 = self.env['stock.move'].create({ 'name': 'test_edit_moveline_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -3025,15 +3026,15 @@ class StockMove(TransactionCase): move1._action_done() self.assertEqual(move1.product_uom_qty, 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) # edit once done, we actually moved 2 products move1.move_line_ids.qty_done = 0 self.assertEqual(move1.product_uom_qty, 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, shelf1_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, shelf1_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) def test_edit_done_move_line_10(self): """ Edit the quantity done for an incoming move shoudld also remove the quant if there @@ -3044,7 +3045,7 @@ class StockMove(TransactionCase): 'name': 'test_edit_moveline_1', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 10.0, }) @@ -3053,13 +3054,13 @@ class StockMove(TransactionCase): move1.move_line_ids.qty_done = 10 move1._action_done() - quant = self.gather_relevant(self.product1, self.stock_location) + quant = self.gather_relevant(self.product, self.stock_location) self.assertEqual(len(quant), 1.0) # edit once done, we actually moved 2 products move1.move_line_ids.qty_done = 0 - quant = self.gather_relevant(self.product1, self.stock_location) + quant = self.gather_relevant(self.product, self.stock_location) self.assertEqual(len(quant), 0.0) self.assertEqual(move1.product_uom_qty, 0.0) @@ -3079,7 +3080,7 @@ class StockMove(TransactionCase): 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, 'picking_id': picking.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 10.0, }) @@ -3088,7 +3089,7 @@ class StockMove(TransactionCase): move1.move_line_ids.qty_done = 10 picking.action_done() self.assertEqual(move1.product_uom_qty, 10.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 10.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 10.0) self.env['stock.move.line'].create({ 'picking_id': move1.move_line_ids.picking_id.id, 'move_id': move1.move_line_ids.move_id.id, @@ -3098,10 +3099,10 @@ class StockMove(TransactionCase): 'location_id': move1.move_line_ids.location_id.id, 'location_dest_id': move1.move_line_ids.location_dest_id.id, }) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 20.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 20.0) move1.move_line_ids[1].qty_done = 5 self.assertEqual(move1.product_uom_qty, 15.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 15.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 15.0) def test_edit_done_move_line_12(self): """ Test that editing a done stock move line linked a tracked product correctly and directly @@ -3110,18 +3111,18 @@ class StockMove(TransactionCase): """ lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, }) lot2 = self.env['stock.production.lot'].create({ 'name': 'lot2', - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, }) package1 = self.env['stock.quant.package'].create({'name': 'test_edit_done_move_line_12'}) move1 = self.env['stock.move'].create({ 'name': 'test_edit_moveline_1', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, 'product_uom': self.uom_dozen.id, 'product_uom_qty': 1.0, }) @@ -3130,11 +3131,11 @@ class StockMove(TransactionCase): move1.move_line_ids.qty_done = 1 move1.move_line_ids.lot_id = lot1.id move1._action_done() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.stock_location, lot_id=lot1), 12.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_lot, self.stock_location, lot_id=lot1), 12.0) # Change the done quantity from 1 dozen to two dozen move1.move_line_ids.qty_done = 2 - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.stock_location, lot_id=lot1), 24.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_lot, self.stock_location, lot_id=lot1), 24.0) def test_edit_done_move_line_13(self): """ Test that editing a done stock move line linked to a packed and tracked product correctly @@ -3143,11 +3144,11 @@ class StockMove(TransactionCase): """ lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, }) lot2 = self.env['stock.production.lot'].create({ 'name': 'lot2', - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, }) package1 = self.env['stock.quant.package'].create({'name': 'test_edit_reserved_move_line_5'}) @@ -3155,7 +3156,7 @@ class StockMove(TransactionCase): 'name': 'test_edit_moveline_1', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -3166,15 +3167,15 @@ class StockMove(TransactionCase): move1.move_line_ids.result_package_id = package1.id move1._action_done() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.stock_location, lot_id=lot1, package_id=package1), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_lot, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_lot, self.stock_location, lot_id=lot1, package_id=package1), 1.0) move1.move_line_ids.write({'lot_id': lot2.id}) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.stock_location, lot_id=lot1), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.stock_location, lot_id=lot1, package_id=package1), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product3, self.stock_location, lot_id=lot2, package_id=package1), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_lot, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_lot, self.stock_location, lot_id=lot1), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_lot, self.stock_location, lot_id=lot1, package_id=package1), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_lot, self.stock_location, lot_id=lot2, package_id=package1), 1.0) def test_immediate_validate_1(self): """ In a picking with a single available move, clicking on validate without filling any @@ -3192,7 +3193,7 @@ class StockMove(TransactionCase): 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, 'picking_id': picking.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 10.0, }) @@ -3202,7 +3203,7 @@ class StockMove(TransactionCase): self.assertEqual(res_dict.get('res_model'), 'stock.immediate.transfer') wizard = self.env[(res_dict.get('res_model'))].browse(res_dict.get('res_id')) wizard.process() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 10.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 10.0) def test_immediate_validate_2(self): """ In a picking with a single partially available move, clicking on validate without @@ -3212,7 +3213,7 @@ class StockMove(TransactionCase): not processed. """ partner = self.env['res.partner'].create({'name': 'Jean'}) - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 5.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 5.0) picking = self.env['stock.picking'].create({ 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, @@ -3224,7 +3225,7 @@ class StockMove(TransactionCase): 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, 'picking_id': picking.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 10.0, }) @@ -3243,8 +3244,8 @@ class StockMove(TransactionCase): # Only 5 products should be processed on the initial move. self.assertEqual(picking.move_lines.state, 'done') self.assertEqual(picking.move_lines.quantity_done, 5.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0.0) - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location)), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 0.0) # The backoder should contain a move for the other 5 produts. backorder = self.env['stock.picking'].search([('backorder_id', '=', picking.id)]) @@ -3264,7 +3265,7 @@ class StockMove(TransactionCase): 'categ_id': self.env.ref('product.product_category_all').id, }) - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1) picking = self.env['stock.picking'].create({ 'location_id': self.stock_location.id, @@ -3276,7 +3277,7 @@ class StockMove(TransactionCase): 'location_id': self.stock_location.id, 'location_dest_id': self.pack_location.id, 'picking_id': picking.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 100, }) @@ -3310,7 +3311,7 @@ class StockMove(TransactionCase): # The backorder should contain 99 product1 and 100 product5. for backorder_move in backorder.move_lines: - if backorder_move.product_id.id == self.product1.id: + if backorder_move.product_id.id == self.product.id: self.assertEqual(backorder_move.product_qty, 99) elif backorder_move.product_id.id == product5.id: self.assertEqual(backorder_move.product_qty, 100) @@ -3322,9 +3323,9 @@ class StockMove(TransactionCase): partner = self.env['res.partner'].create({'name': 'Jean'}) lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, }) - self.env['stock.quant']._update_available_quantity(self.product3, self.stock_location, 5.0, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product_lot, self.stock_location, 5.0, lot_id=lot1) picking = self.env['stock.picking'].create({ 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, @@ -3337,7 +3338,7 @@ class StockMove(TransactionCase): 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, 'picking_id': picking.id, - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 5.0, }) @@ -3355,8 +3356,8 @@ class StockMove(TransactionCase): self.assertEqual(picking.move_lines.move_line_ids.lot_id, lot1) self.assertEqual(picking.move_lines.move_line_ids.qty_done, 5.0) # Check quants data - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0.0) - self.assertEqual(len(self.gather_relevant(self.product1, self.stock_location)), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 0.0) def _create_picking_test_immediate_validate_5(self, picking_type_id, product_id): picking = self.env['stock.picking'].create({ @@ -3388,7 +3389,7 @@ class StockMove(TransactionCase): configured to allow otherwise. """ picking_type_id = self.env.ref('stock.picking_type_in') - product_id = self.product2 + product_id = self.product_serial self.assertTrue(picking_type_id.use_create_lots or picking_type_id.use_existing_lots) self.assertEqual(product_id.tracking, 'serial') @@ -3424,7 +3425,7 @@ class StockMove(TransactionCase): 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, 'picking_id': picking.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1, }) @@ -3433,7 +3434,7 @@ class StockMove(TransactionCase): 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, 'picking_id': picking.id, - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1, }) @@ -3473,7 +3474,7 @@ class StockMove(TransactionCase): 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, 'picking_id': picking.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 10.0, }) @@ -3482,7 +3483,7 @@ class StockMove(TransactionCase): scrap = self.env['stock.scrap'].create({ 'picking_id': picking.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom_id': self.uom_unit.id, 'scrap_qty': 5.0, }) @@ -3497,7 +3498,7 @@ class StockMove(TransactionCase): 'name': 'test_set_quantity_done_1', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 2.0, }) @@ -3505,7 +3506,7 @@ class StockMove(TransactionCase): 'name': 'test_set_quantity_done_2', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 2.0, }) @@ -3522,13 +3523,13 @@ class StockMove(TransactionCase): 'name': 'test_in_1', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, }) self.assertEqual(move1.state, 'draft') self.assertEqual(move1.product_uom_qty, 0) move1.product_uom_qty = 100 - move1.product_id = self.product2 + move1.product_id = self.product_serial move1.onchange_product_id() self.assertEqual(move1.product_uom_qty, 100) @@ -3536,10 +3537,10 @@ class StockMove(TransactionCase): """ Check the created stock move and the impact on quants when we scrap a storable product. """ - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1) scrap = self.env['stock.scrap'].create({ - 'product_id': self.product1.id, - 'product_uom_id':self.product1.uom_id.id, + 'product_id': self.product.id, + 'product_uom_id':self.product.uom_id.id, 'scrap_qty': 1, }) scrap.do_scrap() @@ -3548,15 +3549,15 @@ class StockMove(TransactionCase): self.assertEqual(move.state, 'done') self.assertEqual(move.quantity_done, 1) self.assertEqual(move.scrapped, True) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0) def test_scrap_2(self): """ Check the created stock move and the impact on quants when we scrap a consumable product. """ scrap = self.env['stock.scrap'].create({ - 'product_id': self.product4.id, - 'product_uom_id':self.product4.uom_id.id, + 'product_id': self.product_consu.id, + 'product_uom_id':self.product_consu.uom_id.id, 'scrap_qty': 1, }) scrap.do_scrap() @@ -3565,18 +3566,18 @@ class StockMove(TransactionCase): self.assertEqual(move.state, 'done') self.assertEqual(move.quantity_done, 1) self.assertEqual(move.scrapped, True) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product4, self.stock_location), 0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_consu, self.stock_location), 0) def test_scrap_3(self): """ Scrap the product of a reserved move line. Check that the move line is correctly deleted and that the associated stock move is not assigned anymore. """ - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1) move1 = self.env['stock.move'].create({ 'name': 'test_scrap_3', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -3586,8 +3587,8 @@ class StockMove(TransactionCase): self.assertEqual(len(move1.move_line_ids), 1) scrap = self.env['stock.scrap'].create({ - 'product_id': self.product1.id, - 'product_uom_id':self.product1.uom_id.id, + 'product_id': self.product.id, + 'product_uom_id':self.product.uom_id.id, 'scrap_qty': 1, }) scrap.do_scrap() @@ -3599,7 +3600,7 @@ class StockMove(TransactionCase): done linked stock move and ensure the scrap quantity is also updated. """ - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 10) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 10) partner = self.env['res.partner'].create({'name': 'Kimberley'}) picking = self.env['stock.picking'].create({ 'name': 'A single picking with one move to scrap', @@ -3612,7 +3613,7 @@ class StockMove(TransactionCase): 'name': 'A move to confirm and scrap its product', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, 'picking_id': picking.id, @@ -3621,8 +3622,8 @@ class StockMove(TransactionCase): self.assertEqual(move1.state, 'confirmed') scrap = self.env['stock.scrap'].create({ - 'product_id': self.product1.id, - 'product_uom_id': self.product1.uom_id.id, + 'product_id': self.product.id, + 'product_uom_id': self.product.uom_id.id, 'scrap_qty': 5, 'picking_id': picking.id, }) @@ -3642,7 +3643,7 @@ class StockMove(TransactionCase): unit of measure. Check that the move line is correctly updated after the scrap. """ # 4 units are available in stock - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 4) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 4) # try to reserve a dozen partner = self.env['res.partner'].create({'name': 'Kimberley'}) @@ -3657,7 +3658,7 @@ class StockMove(TransactionCase): 'name': 'A move to confirm and scrap its product', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_dozen.id, 'product_uom_qty': 1.0, 'picking_id': picking.id, @@ -3668,8 +3669,8 @@ class StockMove(TransactionCase): # scrap a unit scrap = self.env['stock.scrap'].create({ - 'product_id': self.product1.id, - 'product_uom_id': self.product1.uom_id.id, + 'product_id': self.product.id, + 'product_uom_id': self.product.uom_id.id, 'scrap_qty': 1, 'picking_id': picking.id, }) @@ -3680,21 +3681,21 @@ class StockMove(TransactionCase): def test_scrap_6(self): """ Check that scrap correctly handle UoM. """ - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1) scrap = self.env['stock.scrap'].create({ - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom_id': self.uom_dozen.id, 'scrap_qty': 1, }) warning_message = scrap.action_validate() self.assertEqual(warning_message.get('res_model', 'Wrong Model'), 'stock.warn.insufficient.qty.scrap') insufficient_qty_wizard = self.env['stock.warn.insufficient.qty.scrap'].create({ - 'product_id': self.product1.id, + 'product_id': self.product.id, 'location_id': self.stock_location.id, 'scrap_id': scrap.id }) insufficient_qty_wizard.action_done() - self.assertEqual(self.env['stock.quant']._gather(self.product1, self.stock_location).quantity, -11) + self.assertEqual(self.env['stock.quant']._gather(self.product, self.stock_location).quantity, -11) def test_in_date_1(self): """ Check that moving a tracked quant keeps the incoming date. @@ -3703,7 +3704,7 @@ class StockMove(TransactionCase): 'name': 'test_in_date_1', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, 'picking_type_id': self.env.ref('stock.picking_type_in').id, @@ -3714,7 +3715,7 @@ class StockMove(TransactionCase): move1.move_line_ids.qty_done = 1 move1._action_done() - quant = self.gather_relevant(self.product3, self.stock_location) + quant = self.gather_relevant(self.product_lot, self.stock_location) self.assertEqual(len(quant), 1.0) self.assertNotEqual(quant.in_date, False) @@ -3725,7 +3726,7 @@ class StockMove(TransactionCase): 'name': 'test_in_date_1', 'location_id': self.stock_location.id, 'location_dest_id': self.pack_location.id, - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -3734,7 +3735,7 @@ class StockMove(TransactionCase): move2.move_line_ids.qty_done = 1 move2._action_done() - quant = self.gather_relevant(self.product3, self.pack_location) + quant = self.gather_relevant(self.product_lot, self.pack_location) self.assertEqual(len(quant), 1.0) self.assertEqual(quant.in_date, initial_incoming_date) @@ -3745,18 +3746,18 @@ class StockMove(TransactionCase): """ lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, }) lot2 = self.env['stock.production.lot'].create({ 'name': 'lot2', - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, }) # receive lot1 move1 = self.env['stock.move'].create({ 'name': 'test_in_date_1', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, 'picking_type_id': self.env.ref('stock.picking_type_in').id, @@ -3772,7 +3773,7 @@ class StockMove(TransactionCase): 'name': 'test_in_date_1', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, 'picking_type_id': self.env.ref('stock.picking_type_in').id, @@ -3785,14 +3786,14 @@ class StockMove(TransactionCase): initial_in_date_lot2 = self.env['stock.quant'].search([ ('location_id', '=', self.stock_location.id), - ('product_id', '=', self.product3.id), + ('product_id', '=', self.product_lot.id), ('lot_id', '=', lot2.id), ]).in_date # Edit lot1's incoming date. quant_lot1 = self.env['stock.quant'].search([ ('location_id', '=', self.stock_location.id), - ('product_id', '=', self.product3.id), + ('product_id', '=', self.product_lot.id), ('lot_id', '=', lot1.id), ]) from odoo.fields import Datetime @@ -3805,7 +3806,7 @@ class StockMove(TransactionCase): 'name': 'test_in_date_1', 'location_id': self.stock_location.id, 'location_dest_id': self.pack_location.id, - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -3814,7 +3815,7 @@ class StockMove(TransactionCase): move3.move_line_ids.qty_done = 1 move3._action_done() quant_in_pack = self.env['stock.quant'].search([ - ('product_id', '=', self.product3.id), + ('product_id', '=', self.product_lot.id), ('location_id', '=', self.pack_location.id), ]) # As lot1 has an older date and FIFO is set by default, it's the one that should be @@ -3829,7 +3830,7 @@ class StockMove(TransactionCase): # Check that lot1 correctly is back to stock with its right in_date quant_lot1 = self.env['stock.quant'].search([ ('location_id.usage', '=', 'internal'), - ('product_id', '=', self.product3.id), + ('product_id', '=', self.product_lot.id), ('lot_id', '=', lot1.id), ('quantity', '!=', 0), ]) @@ -3839,7 +3840,7 @@ class StockMove(TransactionCase): # Check that lo2 is in pack with is right in_date quant_lot2 = self.env['stock.quant'].search([ ('location_id.usage', '=', 'internal'), - ('product_id', '=', self.product3.id), + ('product_id', '=', self.product_lot.id), ('lot_id', '=', lot2.id), ('quantity', '!=', 0), ]) @@ -3852,18 +3853,18 @@ class StockMove(TransactionCase): """ lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, }) lot2 = self.env['stock.production.lot'].create({ 'name': 'lot2', - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, }) # receive lot1 move1 = self.env['stock.move'].create({ 'name': 'test_in_date_1', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, 'picking_type_id': self.env.ref('stock.picking_type_in').id, @@ -3879,7 +3880,7 @@ class StockMove(TransactionCase): 'name': 'test_in_date_1', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, 'picking_type_id': self.env.ref('stock.picking_type_in').id, @@ -3892,7 +3893,7 @@ class StockMove(TransactionCase): initial_in_date_lot2 = self.env['stock.quant'].search([ ('location_id', '=', self.stock_location.id), - ('product_id', '=', self.product3.id), + ('product_id', '=', self.product_lot.id), ('lot_id', '=', lot2.id), ('quantity', '!=', 0), ]).in_date @@ -3900,7 +3901,7 @@ class StockMove(TransactionCase): # Edit lot1's incoming date. quant_lot1 = self.env['stock.quant'].search([ ('location_id.usage', '=', 'internal'), - ('product_id', '=', self.product3.id), + ('product_id', '=', self.product_lot.id), ('lot_id', '=', lot1.id), ('quantity', '!=', 0), ]) @@ -3914,7 +3915,7 @@ class StockMove(TransactionCase): 'name': 'test_in_date_1', 'location_id': self.stock_location.id, 'location_dest_id': self.pack_location.id, - 'product_id': self.product3.id, + 'product_id': self.product_lot.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, }) @@ -3936,7 +3937,7 @@ class StockMove(TransactionCase): quants = self.env['stock.quant'].search([ ('location_id.usage', '=', 'internal'), - ('product_id', '=', self.product3.id), + ('product_id', '=', self.product_lot.id), ('quantity', '!=', 0), ]) self.assertEqual(len(quants), 2) @@ -3954,7 +3955,7 @@ class StockMove(TransactionCase): 'name': 'test_transit_1', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 10.0, 'picking_type_id': self.env.ref('stock.picking_type_in').id, @@ -3964,13 +3965,13 @@ class StockMove(TransactionCase): move1.move_line_ids.qty_done = 10 move1._action_done() - self.assertEqual(self.product1.qty_available, 10.0) + self.assertEqual(self.product.qty_available, 10.0) move2 = self.env['stock.move'].create({ 'name': 'test_transit_1', 'location_id': self.stock_location.id, 'location_dest_id': self.transit_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 5.0, }) @@ -3979,8 +3980,8 @@ class StockMove(TransactionCase): move2.move_line_ids.qty_done = 5 move2._action_done() - self.assertEqual(self.product1.qty_available, 5.0) - self.assertEqual(self.product1.with_context(company_owned=True).qty_available, 10.0) + self.assertEqual(self.product.qty_available, 5.0) + self.assertEqual(self.product.with_context(company_owned=True).qty_available, 10.0) def test_edit_initial_demand_1(self): """ Increase initial demand once everything is reserved and check if @@ -3990,7 +3991,7 @@ class StockMove(TransactionCase): 'name': 'test_transit_1', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 10.0, 'picking_type_id': self.env.ref('stock.picking_type_in').id, @@ -4012,7 +4013,7 @@ class StockMove(TransactionCase): 'name': 'test_transit_1', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 10.0, 'picking_type_id': self.env.ref('stock.picking_type_in').id, @@ -4039,7 +4040,7 @@ class StockMove(TransactionCase): 'name': 'test_transit_1', 'location_id': self.supplier_location.id, 'location_dest_id': self.stock_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 10.0, 'picking_id': picking.id, @@ -4053,7 +4054,7 @@ class StockMove(TransactionCase): """ Increase the initial demand on a delivery picking, the system should not automatically reserve the new quantity. """ - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 12) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 12) picking = self.env['stock.picking'].create({ 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, @@ -4063,7 +4064,7 @@ class StockMove(TransactionCase): 'name': 'test_transit_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 10.0, 'picking_id': picking.id, @@ -4081,12 +4082,12 @@ class StockMove(TransactionCase): """ Changing type of an existing product will raise a user error if some move are reserved. """ - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 10) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 10) move1 = self.env['stock.move'].create({ 'name': 'test_customer', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 5, 'picking_type_id': self.env.ref('stock.picking_type_out').id, @@ -4095,15 +4096,15 @@ class StockMove(TransactionCase): move1._action_assign() with self.assertRaises(UserError): - self.product1.type = 'consu' + self.product.type = 'consu' move1._action_cancel() - self.product1.type = 'consu' + self.product.type = 'consu' move2 = self.env['stock.move'].create({ 'name': 'test_customer', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 5, 'picking_type_id': self.env.ref('stock.picking_type_out').id, @@ -4113,15 +4114,15 @@ class StockMove(TransactionCase): move2._action_assign() with self.assertRaises(UserError): - self.product1.type = 'product' + self.product.type = 'product' move2._action_cancel() - self.product1.type = 'product' + self.product.type = 'product' def test_edit_done_picking_1(self): """ Add a new move line in a done picking should generate an associated move. """ - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 12) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 12) picking = self.env['stock.picking'].create({ 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, @@ -4131,7 +4132,7 @@ class StockMove(TransactionCase): 'name': 'test_transit_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 10.0, 'picking_id': picking.id, @@ -4147,7 +4148,7 @@ class StockMove(TransactionCase): ml = self.env['stock.move.line'].create({ 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom_id': self.uom_unit.id, 'qty_done': 2.0, 'picking_id': picking.id, @@ -4163,7 +4164,7 @@ class StockMove(TransactionCase): """ Check that reserving a move and adding its move lines to different packages work as expected. """ - self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 2) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 2) picking = self.env['stock.picking'].create({ 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, @@ -4173,24 +4174,24 @@ class StockMove(TransactionCase): 'name': 'test_transit_1', 'location_id': self.stock_location.id, 'location_dest_id': self.customer_location.id, - 'product_id': self.product1.id, + 'product_id': self.product.id, 'product_uom': self.uom_unit.id, 'product_uom_qty': 2.0, 'picking_id': picking.id, }) picking.action_confirm() picking.action_assign() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0) move1.quantity_done = 1 picking.put_in_pack() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0) self.assertEqual(len(picking.move_line_ids), 2) unpacked_ml = picking.move_line_ids.filtered(lambda ml: not ml.result_package_id) self.assertEqual(unpacked_ml.product_qty, 1) unpacked_ml.qty_done = 1 picking.put_in_pack() self.assertEqual(len(picking.move_line_ids), 2) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0) picking.button_validate() - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.customer_location), 2) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.customer_location), 2) diff --git a/addons/stock/tests/test_packing.py b/addons/stock/tests/test_packing.py index fcda966d04a..02b35707e17 100644 --- a/addons/stock/tests/test_packing.py +++ b/addons/stock/tests/test_packing.py @@ -1,22 +1,22 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo.tests.common import TransactionCase +from odoo.tests.common import SavepointCase -class TestPacking(TransactionCase): +class TestPacking(SavepointCase): + @classmethod + def setUpClass(cls): + super(TestPacking, cls).setUpClass() + cls.stock_location = cls.env.ref('stock.stock_location_stock') + cls.warehouse = cls.env['stock.warehouse'].search([('lot_stock_id', '=', cls.stock_location.id)], limit=1) + cls.warehouse.write({'delivery_steps': 'pick_pack_ship'}) + cls.pack_location = cls.warehouse.wh_pack_stock_loc_id + cls.ship_location = cls.warehouse.wh_output_stock_loc_id + cls.customer_location = cls.env.ref('stock.stock_location_customers') - def setUp(self): - super(TestPacking, self).setUp() - self.stock_location = self.env.ref('stock.stock_location_stock') - self.warehouse = self.env['stock.warehouse'].search([('lot_stock_id', '=', self.stock_location.id)], limit=1) - self.warehouse.write({'delivery_steps': 'pick_pack_ship'}) - self.pack_location = self.warehouse.wh_pack_stock_loc_id - self.ship_location = self.warehouse.wh_output_stock_loc_id - self.customer_location = self.env.ref('stock.stock_location_customers') - - self.productA = self.env['product.product'].create({'name': 'Product A', 'type': 'product'}) - self.productB = self.env['product.product'].create({'name': 'Product B', 'type': 'product'}) + cls.productA = cls.env['product.product'].create({'name': 'Product A', 'type': 'product'}) + cls.productB = cls.env['product.product'].create({'name': 'Product B', 'type': 'product'}) def test_put_in_pack(self): """ In a pick pack ship scenario, create two packs in pick and check that @@ -88,7 +88,6 @@ class TestPacking(TransactionCase): packing_picking.package_level_ids.write({'is_done': True}) packing_picking.action_done() - def test_pick_a_pack_confirm(self): pack = self.env['stock.quant.package'].create({'name': 'The pack to pick'}) self.env['stock.quant']._update_available_quantity(self.productA, self.stock_location, 20.0, package_id=pack) diff --git a/addons/stock/tests/test_product.py b/addons/stock/tests/test_product.py index b8882640199..606254f1ab5 100644 --- a/addons/stock/tests/test_product.py +++ b/addons/stock/tests/test_product.py @@ -8,7 +8,6 @@ from odoo.addons.stock.tests.common2 import TestStockCommon class TestVirtualAvailable(TestStockCommon): - def setUp(self): super(TestVirtualAvailable, self).setUp() diff --git a/addons/stock/tests/test_quant.py b/addons/stock/tests/test_quant.py index 49fcb6702cb..f5a22c672c0 100644 --- a/addons/stock/tests/test_quant.py +++ b/addons/stock/tests/test_quant.py @@ -5,28 +5,50 @@ from contextlib import closing from datetime import datetime, timedelta from odoo.exceptions import ValidationError -from odoo.tests.common import TransactionCase +from odoo.tests.common import SavepointCase from odoo.exceptions import AccessError, UserError -class StockQuant(TransactionCase): - def setUp(self): - super(StockQuant, self).setUp() - Users = self.env['res.users'].with_context({'no_reset_password': True, 'mail_create_nosubscribe': True}) - self.demo_user = Users.create({ + +class StockQuant(SavepointCase): + @classmethod + def setUpClass(cls): + super(StockQuant, cls).setUpClass() + Users = cls.env['res.users'].with_context({'no_reset_password': True, 'mail_create_nosubscribe': True}) + cls.demo_user = Users.create({ 'name': 'Pauline Poivraisselle', 'login': 'pauline', 'email': 'p.p@example.com', 'notification_type': 'inbox', - 'groups_id': [(6, 0, [self.env.ref('base.group_user').id])] + 'groups_id': [(6, 0, [cls.env.ref('base.group_user').id])] }) - self.stock_user = Users.create({ + cls.stock_user = Users.create({ 'name': 'Pauline Poivraisselle', 'login': 'pauline2', 'email': 'p.p@example.com', 'notification_type': 'inbox', - 'groups_id': [(6, 0, [self.env.ref('stock.group_stock_user').id])] + 'groups_id': [(6, 0, [cls.env.ref('stock.group_stock_user').id])] }) + cls.product = cls.env['product.product'].create({ + 'name': 'Product A', + 'type': 'product', + }) + cls.product_lot = cls.env['product.product'].create({ + 'name': 'Product A', + 'type': 'product', + 'tracking': 'lot', + }) + cls.product_consu = cls.env['product.product'].create({ + 'name': 'Product A', + 'type': 'consu', + }) + cls.product_serial = cls.env['product.product'].create({ + 'name': 'Product A', + 'type': 'product', + 'tracking': 'serial', + }) + cls.stock_location = cls.env.ref('stock.stock_location_stock') + def gather_relevant(self, product_id, location_id, lot_id=None, package_id=None, owner_id=None, strict=False): quants = self.env['stock.quant']._gather(product_id, location_id, lot_id=lot_id, package_id=package_id, owner_id=owner_id, strict=strict) return quants.filtered(lambda q: not (q.quantity == 0 and q.reserved_quantity == 0)) @@ -34,572 +56,432 @@ class StockQuant(TransactionCase): def test_get_available_quantity_1(self): """ Quantity availability with only one quant in a location. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 1.0, }) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) def test_get_available_quantity_2(self): """ Quantity availability with multiple quants in a location. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) for i in range(3): self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 1.0, }) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 3.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 3.0) def test_get_available_quantity_3(self): """ Quantity availability with multiple quants (including negatives ones) in a location. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) for i in range(3): self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 1.0, }) self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': -3.0, }) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) def test_get_available_quantity_4(self): """ Quantity availability with no quants in a location. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) def test_get_available_quantity_5(self): """ Quantity availability with multiple partially reserved quants in a location. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 10.0, 'reserved_quantity': 9.0, }) self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 1.0, 'reserved_quantity': 1.0, }) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) def test_get_available_quantity_6(self): """ Quantity availability with multiple partially reserved quants in a location. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 10.0, 'reserved_quantity': 20.0, }) self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 5.0, 'reserved_quantity': 0.0, }) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location, allow_negative=True), -5.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, allow_negative=True), -5.0) def test_get_available_quantity_7(self): """ Quantity availability with only one tracked quant in a location. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - 'tracking': 'lot', - }) lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': product1.id, + 'product_id': self.product_lot.id, }) self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product_lot.id, + 'location_id': self.stock_location.id, 'quantity': 10.0, 'reserved_quantity': 20.0, 'lot_id': lot1.id, }) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location, lot_id=lot1), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location, lot_id=lot1, allow_negative=True), -10.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_lot, self.stock_location, lot_id=lot1), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_lot, self.stock_location, lot_id=lot1, allow_negative=True), -10.0) def test_get_available_quantity_8(self): """ Quantity availability with a consumable product. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'consu', - }) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) - self.assertEqual(len(self.gather_relevant(product1, stock_location)), 0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_consu, self.stock_location), 0.0) + self.assertEqual(len(self.gather_relevant(self.product_consu, self.stock_location)), 0) with self.assertRaises(ValidationError): - self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product_consu, self.stock_location, 1.0) def test_get_available_quantity_9(self): """ Quantity availability by a demo user with access rights/rules. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 1.0, }) self.env = self.env(user=self.env.ref('base.user_demo')) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) def test_increase_available_quantity_1(self): """ Increase the available quantity when no quants are already in a location. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) - self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 1.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) def test_increase_available_quantity_2(self): """ Increase the available quantity when multiple quants are already in a location. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) for i in range(2): self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 1.0, }) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 2.0) - self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 3.0) - self.assertEqual(len(self.gather_relevant(product1, stock_location)), 2) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 2.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 3.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 2) def test_increase_available_quantity_3(self): """ Increase the available quantity when a concurrent transaction is already increasing the reserved quanntity for the same product. """ - stock_location = self.env.ref('stock.stock_location_stock') - quant = self.env['stock.quant'].search([('location_id', '=', stock_location.id)], limit=1) + quant = self.env['stock.quant'].search([('location_id', '=', self.stock_location.id)], limit=1) product = quant.product_id - available_quantity = self.env['stock.quant']._get_available_quantity(product, stock_location) + available_quantity = self.env['stock.quant']._get_available_quantity(product, self.stock_location) # opens a new cursor and SELECT FOR UPDATE the quant, to simulate another concurrent reserved # quantity increase with closing(self.registry.cursor()) as cr: - cr.execute("SELECT id FROM stock_quant WHERE product_id=%s AND location_id=%s", (product.id, stock_location.id)) + cr.execute("SELECT id FROM stock_quant WHERE product_id=%s AND location_id=%s", (product.id, self.stock_location.id)) quant_id = cr.fetchone() cr.execute("SELECT 1 FROM stock_quant WHERE id=%s FOR UPDATE", quant_id) - self.env['stock.quant']._update_available_quantity(product, stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(product, self.stock_location, 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product, stock_location), available_quantity + 1) - self.assertEqual(len(self.gather_relevant(product, stock_location, strict=True)), 2) + self.assertEqual(self.env['stock.quant']._get_available_quantity(product, self.stock_location), available_quantity + 1) + self.assertEqual(len(self.gather_relevant(product, self.stock_location, strict=True)), 2) def test_increase_available_quantity_4(self): """ Increase the available quantity when no quants are already in a location with a user without access right. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) self.env = self.env(user=self.env.ref('base.user_demo')) - self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0) def test_increase_available_quantity_5(self): """ Increase the available quantity when no quants are already in stock. Increase a subLocation and check that quants are in this location. Also test inverse. """ - stock_location = self.env.ref('stock.stock_location_stock') - stock_sub_location = stock_location.child_ids[0] - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) + stock_sub_location = self.stock_location.child_ids[0] product2 = self.env['product.product'].create({ 'name': 'Product B', 'type': 'product', }) - self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0) - self.env['stock.quant']._update_available_quantity(product1, stock_sub_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product, stock_sub_location, 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 2.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_sub_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 2.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, stock_sub_location), 1.0) self.env['stock.quant']._update_available_quantity(product2, stock_sub_location, 1.0) - self.env['stock.quant']._update_available_quantity(product2, stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(product2, self.stock_location, 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product2, stock_location), 2.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(product2, self.stock_location), 2.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(product2, stock_sub_location), 1.0) def test_increase_available_quantity_6(self): """ Increasing the available quantity in a view location should be forbidden. """ - stock_location = self.env.ref('stock.stock_location_stock') location1 = self.env['stock.location'].create({ 'name': 'viewloc1', 'usage': 'view', - 'location_id': stock_location.id, - }) - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', + 'location_id': self.stock_location.id, }) with self.assertRaises(ValidationError): - self.env['stock.quant']._update_available_quantity(product1, location1, 1.0) + self.env['stock.quant']._update_available_quantity(self.product, location1, 1.0) def test_increase_available_quantity_7(self): """ Setting a location's usage as "view" should be forbidden if it already contains quant. """ - stock_location = self.env.ref('stock.stock_location_stock') - self.assertTrue(len(stock_location.quant_ids.ids) > 0) + self.assertTrue(len(self.stock_location.quant_ids.ids) > 0) with self.assertRaises(UserError): - stock_location.usage = 'view' + self.stock_location.usage = 'view' def test_decrease_available_quantity_1(self): """ Decrease the available quantity when no quants are already in a location. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) - self.env['stock.quant']._update_available_quantity(product1, stock_location, -1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location, allow_negative=True), -1.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, -1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location, allow_negative=True), -1.0) def test_decrease_available_quantity_2(self): """ Decrease the available quantity when multiple quants are already in a location. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) for i in range(2): self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 1.0, }) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 2.0) - self.assertEqual(len(self.gather_relevant(product1, stock_location)), 2) - self.env['stock.quant']._update_available_quantity(product1, stock_location, -1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 1.0) - self.assertEqual(len(self.gather_relevant(product1, stock_location)), 1) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 2.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 2) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, -1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 1.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 1) def test_decrease_available_quantity_3(self): """ Decrease the available quantity when a concurrent transaction is already increasing the reserved quanntity for the same product. """ - stock_location = self.env.ref('stock.stock_location_stock') - quant = self.env['stock.quant'].search([('location_id', '=', stock_location.id)], limit=1) + quant = self.env['stock.quant'].search([('location_id', '=', self.stock_location.id)], limit=1) product = quant.product_id - available_quantity = self.env['stock.quant']._get_available_quantity(product, stock_location) + available_quantity = self.env['stock.quant']._get_available_quantity(product, self.stock_location) # opens a new cursor and SELECT FOR UPDATE the quant, to simulate another concurrent reserved # quantity increase with closing(self.registry.cursor()) as cr: cr.execute("SELECT 1 FROM stock_quant WHERE id = %s FOR UPDATE", quant.ids) - self.env['stock.quant']._update_available_quantity(product, stock_location, -1.0) + self.env['stock.quant']._update_available_quantity(product, self.stock_location, -1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product, stock_location), available_quantity - 1) - self.assertEqual(len(self.gather_relevant(product, stock_location, strict=True)), 2) + self.assertEqual(self.env['stock.quant']._get_available_quantity(product, self.stock_location), available_quantity - 1) + self.assertEqual(len(self.gather_relevant(product, self.stock_location, strict=True)), 2) def test_decrease_available_quantity_4(self): """ Decrease the available quantity that delete the quant. The active user should have read,write and unlink rights """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 1.0, }) self.env = self.env(user=self.demo_user) - self.env['stock.quant']._update_available_quantity(product1, stock_location, -1.0) - self.assertEqual(len(self.gather_relevant(product1, stock_location)), 0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, -1.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 0) def test_increase_reserved_quantity_1(self): """ Increase the reserved quantity of quantity x when there's a single quant in a given location which has an available quantity of x. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 10.0, }) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 10.0) - self.assertEqual(len(self.gather_relevant(product1, stock_location)), 1) - self.env['stock.quant']._update_reserved_quantity(product1, stock_location, 10.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) - self.assertEqual(len(self.gather_relevant(product1, stock_location)), 1) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 10.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 1) + self.env['stock.quant']._update_reserved_quantity(self.product, self.stock_location, 10.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 1) def test_increase_reserved_quantity_2(self): """ Increase the reserved quantity of quantity x when there's two quants in a given location which have an available quantity of x together. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) for i in range(2): self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 5.0, }) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 10.0) - self.assertEqual(len(self.gather_relevant(product1, stock_location)), 2) - self.env['stock.quant']._update_reserved_quantity(product1, stock_location, 10.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) - self.assertEqual(len(self.gather_relevant(product1, stock_location)), 2) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 10.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 2) + self.env['stock.quant']._update_reserved_quantity(self.product, self.stock_location, 10.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 2) def test_increase_reserved_quantity_3(self): """ Increase the reserved quantity of quantity x when there's multiple quants in a given location which have an available quantity of x together. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 5.0, 'reserved_quantity': 2.0, }) self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 10.0, 'reserved_quantity': 12.0, }) self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 8.0, 'reserved_quantity': 3.0, }) self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 35.0, 'reserved_quantity': 12.0, }) # total quantity: 58 # total reserved quantity: 29 - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 29.0) - self.assertEqual(len(self.gather_relevant(product1, stock_location)), 4) - self.env['stock.quant']._update_reserved_quantity(product1, stock_location, 10.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 19.0) - self.assertEqual(len(self.gather_relevant(product1, stock_location)), 4) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 29.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 4) + self.env['stock.quant']._update_reserved_quantity(self.product, self.stock_location, 10.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 19.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 4) def test_increase_reserved_quantity_4(self): """ Increase the reserved quantity of quantity x when there's multiple quants in a given location which have an available quantity of x together. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 5.0, 'reserved_quantity': 7.0, }) self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 12.0, 'reserved_quantity': 10.0, }) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) - self.assertEqual(len(self.gather_relevant(product1, stock_location)), 2) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 2) with self.assertRaises(UserError): - self.env['stock.quant']._update_reserved_quantity(product1, stock_location, 10.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) + self.env['stock.quant']._update_reserved_quantity(self.product, self.stock_location, 10.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) def test_increase_reserved_quantity_5(self): """ Decrease the available quantity when no quant are in a location. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) with self.assertRaises(UserError): - self.env['stock.quant']._update_reserved_quantity(product1, stock_location, 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) + self.env['stock.quant']._update_reserved_quantity(self.product, self.stock_location, 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) def test_decrease_reserved_quantity_1(self): - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 10.0, 'reserved_quantity': 10.0, }) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) - self.assertEqual(len(self.gather_relevant(product1, stock_location)), 1) - self.env['stock.quant']._update_reserved_quantity(product1, stock_location, -10.0, strict=True) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 10.0) - self.assertEqual(len(self.gather_relevant(product1, stock_location)), 1) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 1) + self.env['stock.quant']._update_reserved_quantity(self.product, self.stock_location, -10.0, strict=True) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 10.0) + self.assertEqual(len(self.gather_relevant(self.product, self.stock_location)), 1) def test_increase_decrease_reserved_quantity_1(self): """ Decrease then increase reserved quantity when no quant are in a location. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) with self.assertRaises(UserError): - self.env['stock.quant']._update_reserved_quantity(product1, stock_location, 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) + self.env['stock.quant']._update_reserved_quantity(self.product, self.stock_location, 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) with self.assertRaises(UserError): - self.env['stock.quant']._update_reserved_quantity(product1, stock_location, -1.0, strict=True) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) + self.env['stock.quant']._update_reserved_quantity(self.product, self.stock_location, -1.0, strict=True) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) def test_action_done_1(self): - stock_location = self.env.ref('stock.stock_location_stock') pack_location = self.env.ref('stock.location_pack_zone') pack_location.active = True - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) - self.env['stock.quant']._update_available_quantity(product1, stock_location, 2.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 2.0) - self.env['stock.quant']._update_reserved_quantity(product1, stock_location, 2.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) - self.env['stock.quant']._update_reserved_quantity(product1, stock_location, -2.0, strict=True) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 2.0) - self.env['stock.quant']._update_available_quantity(product1, stock_location, -2.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 0.0) - self.env['stock.quant']._update_available_quantity(product1, pack_location, 2.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, pack_location), 2.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 2.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 2.0) + self.env['stock.quant']._update_reserved_quantity(self.product, self.stock_location, 2.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) + self.env['stock.quant']._update_reserved_quantity(self.product, self.stock_location, -2.0, strict=True) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 2.0) + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, -2.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, self.stock_location), 0.0) + self.env['stock.quant']._update_available_quantity(self.product, pack_location, 2.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product, pack_location), 2.0) def test_mix_tracked_untracked_1(self): - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - 'tracking': 'serial', - }) lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': product1.id, + 'product_id': self.product_serial.id, }) # add one tracked, one untracked - self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0) - self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0, lot_id=lot1) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1.0) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1.0, lot_id=lot1) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 2.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location, strict=True), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location, lot_id=lot1), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location), 2.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, strict=True), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, lot_id=lot1), 1.0) - self.env['stock.quant']._update_reserved_quantity(product1, stock_location, 1.0, lot_id=lot1, strict=True) + self.env['stock.quant']._update_reserved_quantity(self.product_serial, self.stock_location, 1.0, lot_id=lot1, strict=True) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location, strict=True), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location, lot_id=lot1), 0.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, strict=True), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, lot_id=lot1), 0.0) - self.env['stock.quant']._update_reserved_quantity(product1, stock_location, -1.0, lot_id=lot1, strict=True) + self.env['stock.quant']._update_reserved_quantity(self.product_serial, self.stock_location, -1.0, lot_id=lot1, strict=True) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 2.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location, strict=True), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location, lot_id=lot1), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location), 2.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, strict=True), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, lot_id=lot1), 1.0) with self.assertRaises(UserError): - self.env['stock.quant']._update_reserved_quantity(product1, stock_location, -1.0, strict=True) + self.env['stock.quant']._update_reserved_quantity(self.product_serial, self.stock_location, -1.0, strict=True) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location), 2.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location, strict=True), 1.0) - self.assertEqual(self.env['stock.quant']._get_available_quantity(product1, stock_location, lot_id=lot1), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location), 2.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, strict=True), 1.0) + self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, lot_id=lot1), 1.0) def test_access_rights_1(self): """ Directly update the quant with a user with or without stock access rights sould raise an AccessError. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) quant = self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 1.0, }) self.env = self.env(user=self.demo_user) with self.assertRaises(AccessError): self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 1.0, }) with self.assertRaises(AccessError): @@ -610,8 +492,8 @@ class StockQuant(TransactionCase): self.env = self.env(user=self.stock_user) with self.assertRaises(AccessError): self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 1.0, }) with self.assertRaises(AccessError): @@ -622,47 +504,29 @@ class StockQuant(TransactionCase): def test_in_date_1(self): """ Check that no incoming date is set when updating the quantity of an untracked quant. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) - quantity, in_date = self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0) + quantity, in_date = self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0) self.assertEqual(quantity, 1) self.assertNotEqual(in_date, None) - def test_in_date_1b(self): - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - }) self.env['stock.quant'].create({ - 'product_id': product1.id, - 'location_id': stock_location.id, + 'product_id': self.product.id, + 'location_id': self.stock_location.id, 'quantity': 1.0, }) - quantity, in_date = self.env['stock.quant']._update_available_quantity(product1, stock_location, 2.0) + quantity, in_date = self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 2.0) self.assertEqual(quantity, 3) self.assertNotEqual(in_date, None) - def test_in_date_2(self): """ Check that an incoming date is correctly set when updating the quantity of a tracked quant. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - 'tracking': 'serial', - }) lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': product1.id, + 'product_id': self.product_serial.id, }) - quantity, in_date = self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0, lot_id=lot1) + quantity, in_date = self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1.0, lot_id=lot1) self.assertEqual(quantity, 1) self.assertNotEqual(in_date, None) @@ -670,26 +534,20 @@ class StockQuant(TransactionCase): """ Check that the FIFO strategies correctly applies when you have multiple lot received at different times for a tracked product. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - 'tracking': 'serial', - }) lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': product1.id, + 'product_id': self.product_serial.id, }) lot2 = self.env['stock.production.lot'].create({ 'name': 'lot2', - 'product_id': product1.id, + 'product_id': self.product_serial.id, }) in_date_lot1 = datetime.now() in_date_lot2 = datetime.now() - timedelta(days=5) - self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0, lot_id=lot1, in_date=in_date_lot1) - self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0, lot_id=lot2, in_date=in_date_lot2) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1.0, lot_id=lot1, in_date=in_date_lot1) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1.0, lot_id=lot2, in_date=in_date_lot2) - quants = self.env['stock.quant']._update_reserved_quantity(product1, stock_location, 1) + quants = self.env['stock.quant']._update_reserved_quantity(self.product_serial, self.stock_location, 1) # Default removal strategy is FIFO, so lot2 should be received as it was received earlier. self.assertEqual(quants[0][0].lot_id.id, lot2.id) @@ -698,28 +556,22 @@ class StockQuant(TransactionCase): """ Check that the LIFO strategies correctly applies when you have multiple lot received at different times for a tracked product. """ - stock_location = self.env.ref('stock.stock_location_stock') lifo_strategy = self.env['product.removal'].search([('method', '=', 'lifo')]) - stock_location.removal_strategy_id = lifo_strategy - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - 'tracking': 'serial', - }) + self.stock_location.removal_strategy_id = lifo_strategy lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': product1.id, + 'product_id': self.product_serial.id, }) lot2 = self.env['stock.production.lot'].create({ 'name': 'lot2', - 'product_id': product1.id, + 'product_id': self.product_serial.id, }) in_date_lot1 = datetime.now() in_date_lot2 = datetime.now() - timedelta(days=5) - self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0, lot_id=lot1, in_date=in_date_lot1) - self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0, lot_id=lot2, in_date=in_date_lot2) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1.0, lot_id=lot1, in_date=in_date_lot1) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1.0, lot_id=lot2, in_date=in_date_lot2) - quants = self.env['stock.quant']._update_reserved_quantity(product1, stock_location, 1) + quants = self.env['stock.quant']._update_reserved_quantity(self.product_serial, self.stock_location, 1) # Removal strategy is LIFO, so lot1 should be received as it was received later. self.assertEqual(quants[0][0].lot_id.id, lot1.id) @@ -727,27 +579,21 @@ class StockQuant(TransactionCase): def test_in_date_4b(self): """ Check for LIFO and max with/without in_date that it handles the LIFO NULLS LAST well """ - stock_location = self.env.ref('stock.stock_location_stock') stock_location1 = self.env.ref('stock.stock_location_components') stock_location2 = self.env.ref('stock.stock_location_14') lifo_strategy = self.env['product.removal'].search([('method', '=', 'lifo')]) - stock_location.removal_strategy_id = lifo_strategy - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - 'tracking': 'serial', - }) + self.stock_location.removal_strategy_id = lifo_strategy self.env['stock.quant'].create({ - 'product_id': product1.id, + 'product_id': self.product_serial.id, 'location_id': stock_location1.id, 'quantity': 1.0, }) in_date_location2 = datetime.now() - self.env['stock.quant']._update_available_quantity(product1, stock_location2, 1.0, in_date=in_date_location2) + self.env['stock.quant']._update_available_quantity(self.product_serial, stock_location2, 1.0, in_date=in_date_location2) - quants = self.env['stock.quant']._update_reserved_quantity(product1, stock_location, 1) + quants = self.env['stock.quant']._update_reserved_quantity(self.product_serial, self.stock_location, 1) # Removal strategy is LIFO, so the one with date is the most recent one and should be selected self.assertEqual(quants[0][0].location_id.id, stock_location2.id) @@ -756,24 +602,18 @@ class StockQuant(TransactionCase): """ Receive the same lot at different times, once they're in the same location, the quants are merged and only the earliest incoming date is kept. """ - stock_location = self.env.ref('stock.stock_location_stock') - product1 = self.env['product.product'].create({ - 'name': 'Product A', - 'type': 'product', - 'tracking': 'lot', - }) lot1 = self.env['stock.production.lot'].create({ 'name': 'lot1', - 'product_id': product1.id, + 'product_id': self.product_lot.id, }) from odoo.fields import Datetime in_date1 = Datetime.now() - self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0, lot_id=lot1, in_date=in_date1) + self.env['stock.quant']._update_available_quantity(self.product_lot, self.stock_location, 1.0, lot_id=lot1, in_date=in_date1) quant = self.env['stock.quant'].search([ - ('product_id', '=', product1.id), - ('location_id', '=', stock_location.id), + ('product_id', '=', self.product_lot.id), + ('location_id', '=', self.stock_location.id), ]) self.assertEqual(len(quant), 1) self.assertEqual(quant.quantity, 1) @@ -781,13 +621,14 @@ class StockQuant(TransactionCase): self.assertEqual(quant.in_date, in_date1) in_date2 = Datetime.now() - timedelta(days=5) - self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0, lot_id=lot1, in_date=in_date2) + self.env['stock.quant']._update_available_quantity(self.product_lot, self.stock_location, 1.0, lot_id=lot1, in_date=in_date2) quant = self.env['stock.quant'].search([ - ('product_id', '=', product1.id), - ('location_id', '=', stock_location.id), + ('product_id', '=', self.product_lot.id), + ('location_id', '=', self.stock_location.id), ]) self.assertEqual(len(quant), 1) self.assertEqual(quant.quantity, 2) self.assertEqual(quant.lot_id.id, lot1.id) self.assertEqual(quant.in_date, in_date2) + diff --git a/addons/stock/tests/test_robustness.py b/addons/stock/tests/test_robustness.py index b00409ff881..17dc53e7e1a 100644 --- a/addons/stock/tests/test_robustness.py +++ b/addons/stock/tests/test_robustness.py @@ -2,20 +2,21 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo.exceptions import UserError, ValidationError -from odoo.tests.common import TransactionCase +from odoo.tests.common import SavepointCase -class TestRobustness(TransactionCase): - def setUp(self): - super(TestRobustness, self).setUp() - self.stock_location = self.env.ref('stock.stock_location_stock') - self.customer_location = self.env.ref('stock.stock_location_customers') - self.uom_unit = self.env.ref('uom.product_uom_unit') - self.uom_dozen = self.env.ref('uom.product_uom_dozen') - self.product1 = self.env['product.product'].create({ +class TestRobustness(SavepointCase): + @classmethod + def setUpClass(cls): + super(TestRobustness, cls).setUpClass() + cls.stock_location = cls.env.ref('stock.stock_location_stock') + cls.customer_location = cls.env.ref('stock.stock_location_customers') + cls.uom_unit = cls.env.ref('uom.product_uom_unit') + cls.uom_dozen = cls.env.ref('uom.product_uom_dozen') + cls.product1 = cls.env['product.product'].create({ 'name': 'Product A', 'type': 'product', - 'categ_id': self.env.ref('product.product_category_all').id, + 'categ_id': cls.env.ref('product.product_category_all').id, }) def test_uom_factor(self): diff --git a/addons/stock/tests/test_shipment.py b/addons/stock/tests/test_shipment.py deleted file mode 100644 index 4317cb0909a..00000000000 --- a/addons/stock/tests/test_shipment.py +++ /dev/null @@ -1,48 +0,0 @@ -# -*- coding: utf-8 -*- - -from odoo.addons.stock.tests.common2 import TestStockCommon - - -class TestInventory(TestStockCommon): - - def test_shipment(self): - # TDE TODO - # pickign.action_confirm -> confirm moves - # picking.do_prepare_partial, should create pack ops, write on it ? - - # create and confirm an incoming move of product 3 - incoming_move = self._create_move_in(self.product_3, self.warehouse_1, create_picking=True, product_uom_qty=50) - incoming_move._action_confirm() - - # receive only 40 units of products; this will create a backorder of incoming shipment for the remaining 10 - pack_operation = self._create_pack_operation( - self.product_3, 40.0, incoming_move.picking_id, - location_id=self.env.ref('stock.stock_location_suppliers').id, # TDE FIXME: locations - location_dest_id=self.location_1.id) - - incoming_move.picking_id.with_context(active_model='stock.picking', active_id=incoming_move.picking_id.id, active_ids=[incoming_move.picking_id.id]).action_done() - - # check backorder shipment after receiving partial shipment and check remaining shipment - for move_line in incoming_move.picking_id.move_lines: - self.assertEqual(move_line.product_qty, 40) - self.assertEqual(move_line.state, 'done') - backorder = self.env['stock.picking'].search([('backorder_id', '=', incoming_move.picking_id.id)]) - for move_line in backorder.move_lines: - self.assertEqual(move_line.product_qty, 10) - self.assertIn(move_line.state, ['assigned', 'waiting', 'confirmed']) - - backorder.with_context(active_model='stock.picking', active_id=backorder.id, active_ids=[backorder.id]) - - # receive the remaining 10 units from the backorder - pack_operation = self._create_pack_operation( - self.product_3, 10.0, backorder, - location_id=self.env.ref('stock.stock_location_suppliers').id, # TDE FIXME: locations - location_dest_id=self.location_1.id) - - backorder.action_done() - - # check the incoming shipment after receipt - backorder = self.env['stock.picking'].search([('backorder_id', '=', incoming_move.picking_id.id)]) - self.assertEqual(backorder.state, 'done') - for move_line in backorder.move_lines: - self.assertEqual(move_line.state, 'done') diff --git a/addons/stock/tests/test_warehouse.py b/addons/stock/tests/test_warehouse.py index 7288e4eb58e..6c513d5c9b6 100644 --- a/addons/stock/tests/test_warehouse.py +++ b/addons/stock/tests/test_warehouse.py @@ -3,8 +3,8 @@ from odoo.addons.stock.tests.common2 import TestStockCommon from odoo.tests import Form -class TestWarehouse(TestStockCommon): +class TestWarehouse(TestStockCommon): def test_inventory_product(self): self.product_1.type = 'product' inventory_wizard = self.env['stock.change.product.qty'].create({ @@ -574,22 +574,3 @@ class TestWarehouse(TestStockCommon): self.assertTrue(warehouse.pick_type_id.active) self.assertTrue(warehouse.pack_type_id.active) -class TestResupply(TestStockCommon): - def setUp(self): - super(TestResupply, self).setUp() - - self.warehouse_2 = self.env['stock.warehouse'].create({ - 'name': 'Small Warehouse', - 'code': 'SWH', - 'resupply_wh_ids': [(6, 0, [self.warehouse_1.id])] - }) - - # minimum stock rule for test product on this warehouse - self.env['stock.warehouse.orderpoint'].create({ - 'warehouse_id': self.warehouse_2.id, - 'location_id': self.warehouse_2.lot_stock_id.id, - 'product_id': self.product_1.id, - 'product_min_qty': 10, - 'product_max_qty': 100, - 'product_uom': self.uom_unit.id, - })