Initial commit: Ventor Odoo packages (4 packages)

This commit is contained in:
Ernad Husremovic 2025-08-29 15:49:21 +02:00
commit 1f20ad87e6
190 changed files with 10375 additions and 0 deletions

View file

@ -0,0 +1,9 @@
# Copyright 2020 VentorTech OU
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0).
from . import test_merp_outgoing_routing
from . import test_merp_picking_wave_base
from . import test_merp_quants_location_routing
from . import test_stock_reservation_by_name
from . import test_stock_reservation_by_priority
from . import test_stock_reservation_by_quantity

View file

@ -0,0 +1,150 @@
# Copyright 2020 VentorTech OU
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0).
from odoo.tests.common import TransactionCase
from datetime import datetime
class TestMerpOutgoingRouting(TransactionCase):
def setUp(self):
super(TestMerpOutgoingRouting, self).setUp()
self.location_1 = self.env['stock.location'].create({
'name': 'test_location_1',
'removal_prio': 2
})
self.location_2 = self.env['stock.location'].create({
'name': 'test_location_2',
'removal_prio': 3
})
self.location_3 = self.env['stock.location'].create({
'name': 'test_location_3',
'removal_prio': 1
})
self.location_4 = self.env['stock.location'].create({
'name': 'test_location_4',
'removal_prio': 4
})
company = self.env.user.company_id
picking_type = self.env['stock.picking.type'].search([], limit=1)
self.stock_picking = self.env['stock.picking'].create({
'name': 'test_stock_picking',
'location_id': self.location_1.id,
'location_dest_id': self.location_2.id,
'move_type': 'one',
'company_id': company.id,
'picking_type_id': picking_type.id
})
products = self.env['product.product']
for suf in range(1, 5):
products += self.create_product(suf)
self.move_line_1 = self.env['stock.move.line'].create({
'picking_id': self.stock_picking.id,
'qty_done': 1.0,
'location_id': self.location_1.id,
'date': datetime.now(),
'location_dest_id': self.location_2.id,
'reserved_uom_qty': 20.0,
'product_uom_id': products[1].uom_id.id,
'product_id': products[1].id
})
self.move_line_2 = self.env['stock.move.line'].create({
'picking_id': self.stock_picking.id,
'qty_done': 2.0,
'location_id': self.location_2.id,
'date': datetime.now(),
'location_dest_id': self.location_3.id,
'reserved_uom_qty': 25.0,
'product_uom_id': products[0].uom_id.id,
'product_id': products[0].id
})
self.move_line_3 = self.env['stock.move.line'].create({
'picking_id': self.stock_picking.id,
'qty_done': 3.0,
'location_id': self.location_3.id,
'date': datetime.now(),
'location_dest_id': self.location_2.id,
'reserved_uom_qty': 15.0,
'product_uom_id': products[2].uom_id.id,
'product_id': products[2].id
})
self.move_line_4 = self.env['stock.move.line'].create({
'picking_id': self.stock_picking.id,
'qty_done': 10.0,
'location_id': self.location_4.id,
'date': datetime.now(),
'location_dest_id': self.location_2.id,
'reserved_uom_qty': 10.0,
'product_uom_id': products[3].uom_id.id,
'product_id': products[3].id
})
def create_product(self, suf):
name = 'test_product_{}'.format(suf)
product_data = {
'name': name,
}
return self.env['product.product'].create(product_data)
def test_sort_alphabet_a_z(self):
self.set_way_outgoing_routing('location_id.name', '0')
locations_name = self.stock_picking.mapped('operations_to_pick.location_id.name')
self.assertEqual(locations_name[0], 'test_location_1')
self.assertEqual(locations_name[1], 'test_location_2')
self.assertEqual(locations_name[2], 'test_location_3')
def test_sort_alphabet_z_a(self):
self.set_way_outgoing_routing('location_id.name', '1')
locations_name = self.stock_picking.mapped('operations_to_pick.location_id.name')
self.assertEqual(locations_name[0], 'test_location_3')
self.assertEqual(locations_name[1], 'test_location_2')
self.assertEqual(locations_name[2], 'test_location_1')
def test_sort_removal_priority_a_z(self):
self.set_way_outgoing_routing('location_id.removal_prio', '0')
locations_removal_prio = self.stock_picking\
.mapped('operations_to_pick.location_id.removal_prio')
self.assertEqual(locations_removal_prio[0], 1)
self.assertEqual(locations_removal_prio[1], 2)
self.assertEqual(locations_removal_prio[2], 3)
def test_sort_removal_priority_z_a(self):
self.set_way_outgoing_routing('location_id.removal_prio', '1')
locations_removal_prio = self.stock_picking\
.mapped('operations_to_pick.location_id.removal_prio')
self.assertEqual(locations_removal_prio[0], 3)
self.assertEqual(locations_removal_prio[1], 2)
self.assertEqual(locations_removal_prio[2], 1)
def test_sort_by_products_name_a_z(self):
self.set_way_outgoing_routing('product_id.name', '0')
products_name = self.stock_picking \
.mapped('operations_to_pick.product_id.name')
self.assertEqual(products_name[0], 'test_product_1')
self.assertEqual(products_name[1], 'test_product_2')
self.assertEqual(products_name[2], 'test_product_3')
def test_sort_by_products_name_z_a(self):
self.set_way_outgoing_routing('product_id.name', '1')
products_name = self.stock_picking \
.mapped('operations_to_pick.product_id.name')
self.assertEqual(products_name[0], 'test_product_3')
self.assertEqual(products_name[1], 'test_product_2')
self.assertEqual(products_name[2], 'test_product_1')
def set_way_outgoing_routing(self, outgoing_routing_strategy, outgoing_routing_order):
config = self.env['res.config.settings'].create({
'outgoing_routing_strategy': outgoing_routing_strategy,
'outgoing_routing_order': outgoing_routing_order
})
config.execute()

View file

@ -0,0 +1,170 @@
# Copyright 2020 VentorTech OU
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0).
from odoo.tests.common import TransactionCase
from datetime import datetime
class TestMerpPickingWaveBase(TransactionCase):
def setUp(self):
super(TestMerpPickingWaveBase, self).setUp()
self.location_1 = self.env['stock.location'].create({
'name': 'test_location_1',
'removal_prio': 2
})
self.location_2 = self.env['stock.location'].create({
'name': 'test_location_2',
'removal_prio': 3
})
self.location_3 = self.env['stock.location'].create({
'name': 'test_location_3',
'removal_prio': 1
})
self.location_4 = self.env['stock.location'].create({
'name': 'test_location_4',
'removal_prio': 4
})
company = self.env.user.company_id
picking_type = self.env['stock.picking.type'].search([], limit=1)
self.stock_picking = self.env['stock.picking'].create({
'name': 'test_stock_picking',
'location_id': self.location_1.id,
'location_dest_id': self.location_2.id,
'move_type': 'one',
'company_id': company.id,
'picking_type_id': picking_type.id
})
self.picking_batch = self.env['stock.picking.batch'].create({
'name': 'test_stock_picking_batch',
'picking_ids': [(4, self.stock_picking.id, 0)]
})
products = self.env['product.product']
for suf in range(1, 5):
products += self.create_product(suf)
self.move_line_1 = self.env['stock.move.line'].create({
'picking_id': self.stock_picking.id,
'qty_done': 1.0,
'location_id': self.location_1.id,
'date': datetime.now(),
'location_dest_id': self.location_2.id,
'reserved_uom_qty': 20.0,
'product_uom_id': products[1].uom_id.id,
'product_id': products[1].id
})
self.move_line_2 = self.env['stock.move.line'].create({
'picking_id': self.stock_picking.id,
'qty_done': 2.0,
'location_id': self.location_2.id,
'date': datetime.now(),
'location_dest_id': self.location_3.id,
'reserved_uom_qty': 25.0,
'product_uom_id': products[1].uom_id.id,
'product_id': products[0].id
})
self.move_line_3 = self.env['stock.move.line'].create({
'picking_id': self.stock_picking.id,
'qty_done': 3.0,
'location_id': self.location_3.id,
'date': datetime.now(),
'location_dest_id': self.location_1.id,
'reserved_uom_qty': 15.0,
'product_uom_id': products[2].uom_id.id,
'product_id': products[2].id
})
self.move_line_4 = self.env['stock.move.line'].create({
'picking_id': self.stock_picking.id,
'qty_done': 10.0,
'location_id': self.location_4.id,
'date': datetime.now(),
'location_dest_id': self.location_2.id,
'reserved_uom_qty': 10.0,
'product_uom_id': products[3].uom_id.id,
'product_id': products[3].id
})
def create_product(self, suf):
name = 'test_product_{}'.format(suf)
product_data = {
'name': name,
}
return self.env['product.product'].create(product_data)
def test_related_pack_operations(self):
self.assertEqual(len(self.picking_batch.related_pack_operations), 4)
def test_operations_to_pick(self):
self.assertEqual(len(self.picking_batch.operations_to_pick), 3)
def test_sort_alphabet_a_z(self):
outgoing_routing_strategy = 'location_id.name'
outgoing_routing_order = '0'
self.set_way_outgoing_routing(outgoing_routing_strategy, outgoing_routing_order)
locations_name = self.picking_batch.mapped('operations_to_pick.location_id.name')
self.assertEqual(locations_name[0], 'test_location_1')
self.assertEqual(locations_name[1], 'test_location_2')
self.assertEqual(locations_name[2], 'test_location_3')
def test_sort_alphabet_z_a(self):
outgoing_routing_strategy = 'location_id.name'
outgoing_routing_order = '1'
self.set_way_outgoing_routing(outgoing_routing_strategy, outgoing_routing_order)
locations_name = self.picking_batch.mapped('operations_to_pick.location_id.name')
self.assertEqual(locations_name[0], 'test_location_3')
self.assertEqual(locations_name[1], 'test_location_2')
self.assertEqual(locations_name[2], 'test_location_1')
def test_sort_removal_priority_a_z(self):
outgoing_routing_strategy = 'location_id.removal_prio'
outgoing_routing_order = '0'
self.set_way_outgoing_routing(outgoing_routing_strategy, outgoing_routing_order)
locations_removal_prio = self.picking_batch \
.mapped('operations_to_pick.location_id.removal_prio')
self.assertEqual(locations_removal_prio[0], 1)
self.assertEqual(locations_removal_prio[1], 2)
self.assertEqual(locations_removal_prio[2], 3)
def test_sort_removal_priority_z_a(self):
outgoing_routing_strategy = 'location_id.removal_prio'
outgoing_routing_order = '1'
self.set_way_outgoing_routing(outgoing_routing_strategy, outgoing_routing_order)
locations_removal_prio = self.picking_batch \
.mapped('operations_to_pick.location_id.removal_prio')
self.assertEqual(locations_removal_prio[0], 3)
self.assertEqual(locations_removal_prio[1], 2)
self.assertEqual(locations_removal_prio[2], 1)
def test_sort_by_products_name_a_z(self):
outgoing_routing_strategy = 'product_id.name'
outgoing_routing_order = '0'
self.set_way_outgoing_routing(outgoing_routing_strategy, outgoing_routing_order)
products_name = self.picking_batch \
.mapped('operations_to_pick.product_id.name')
self.assertEqual(products_name[0], 'test_product_1')
self.assertEqual(products_name[1], 'test_product_2')
self.assertEqual(products_name[2], 'test_product_3')
def test_sort_by_products_name_z_a(self):
outgoing_routing_strategy = 'product_id.name'
outgoing_routing_order = '1'
self.set_way_outgoing_routing(outgoing_routing_strategy, outgoing_routing_order)
products_name = self.picking_batch \
.mapped('operations_to_pick.product_id.name')
self.assertEqual(products_name[0], 'test_product_3')
self.assertEqual(products_name[1], 'test_product_2')
self.assertEqual(products_name[2], 'test_product_1')
def set_way_outgoing_routing(self, outgoing_routing_strategy, outgoing_routing_order):
config = self.env['res.config.settings'].create({
'outgoing_routing_strategy': outgoing_routing_strategy,
'outgoing_routing_order': outgoing_routing_order
})
config.execute()

View file

@ -0,0 +1,162 @@
# Copyright 2020 VentorTech OU
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0).
from datetime import date
from odoo.tests.common import TransactionCase
class TestMerpQuantsLocationRouting(TransactionCase):
def setUp(self):
super(TestMerpQuantsLocationRouting, self).setUp()
self.res_users_model = self.env['res.users']
self.stock_location_model = self.env['stock.location']
self.stock_warehouse_model = self.env['stock.warehouse']
self.stock_picking_model = self.env['stock.picking']
self.stock_change_model = self.env['stock.change.product.qty']
self.product_model = self.env['product.product']
self.quant_model = self.env['stock.quant']
self.picking_internal = self.env.ref('stock.picking_type_internal')
self.picking_out = self.env.ref('stock.picking_type_out')
self.location_supplier = self.env.ref('stock.stock_location_suppliers')
self.company = self.env.ref('base.main_company')
self.wh1 = self.stock_warehouse_model.create({
'name': 'WH2',
'code': 'WH2',
})
# Removal strategies:
self.fifo = self.env.ref('stock.removal_fifo')
self.lifo = self.env.ref('stock.removal_lifo')
self.removal_location_priority = self.env.ref(
'outgoing_routing.removal_location_priority'
)
# Create locations:
self.stock = self.stock_location_model.create({
'name': 'Default Base',
'usage': 'internal',
})
self.location_A = self.stock_location_model.create({
'name': 'location_A',
'usage': 'internal',
'location_id': self.stock.id,
'removal_prio': 1,
})
self.location_B = self.stock_location_model.create({
'name': 'Location_B',
'usage': 'internal',
'location_id': self.stock.id,
'removal_prio': 0,
})
self.stock_2 = self.stock_location_model.create({
'name': 'Another Location',
'usage': 'internal',
})
# Create a product
self.product_1 = self.product_model.create({
'name': 'Product 1',
'type': 'product',
})
# Create quants
today = date.today()
quant_1 = self.quant_model.create({
'product_id': self.product_1.id,
'location_id': self.location_A.id,
'quantity': 10.0,
'in_date': today,
})
quant_2 = self.quant_model.create({
'product_id': self.product_1.id,
'location_id': self.location_B.id,
'quantity': 5.0,
'in_date': today,
})
self.quants = quant_1 + quant_2
def _create_picking(self, picking_type, location, location_dest, qty):
move_line_values = {
'name': 'Default Test Move',
'product_id': self.product_1.id,
'product_uom': self.product_1.uom_id.id,
'product_uom_qty': qty,
'location_id': location.id,
'location_dest_id': location_dest.id,
'price_unit': 2,
}
picking = self.stock_picking_model.create({
'picking_type_id': picking_type.id,
'location_id': location.id,
'location_dest_id': location_dest.id,
'move_ids': [(0, 0, move_line_values)],
})
return picking
def test_stock_removal_location_by_removal_location_priority(self):
"""Tests removal priority with Location Priority strategy."""
self.stock.removal_strategy_id = self.removal_location_priority
# Quants must start unreserved
for quant in self.quants:
self.assertEqual(
quant.reserved_quantity,
0.0,
'Quant must not have reserved qty right now.'
)
if quant.location_id == self.location_A:
self.assertEqual(
quant.removal_prio,
1,
'Removal Priority Location must be 1'
)
if quant.location_id == self.location_B:
self.assertEqual(
quant.removal_prio,
0,
'Removal Priority Location must be 0'
)
self.assertEqual(
self.quants[0].in_date,
self.quants[1].in_date,
'Dates must be Equal'
)
picking_1 = self._create_picking(
self.picking_internal,
self.stock,
self.stock_2,
5,
)
# picking_1.flush()
picking_1.action_confirm()
picking_1.action_assign()
# Quants must be reserved in Location B (lower removal_priority value).
for quant in self.quants:
if quant.location_id == self.location_A:
self.assertEqual(
quant.reserved_quantity,
0.0,
'This quant must not have reserved qty.'
)
if quant.location_id == self.location_B:
self.assertEqual(
quant.reserved_quantity,
5.0,
'This quant must have 5 reserved qty.'
)

View file

@ -0,0 +1,110 @@
# Copyright 2020 VentorTech OU
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0).
from datetime import date
from odoo.tests.common import TransactionCase
class TestStockRouting(TransactionCase):
def setUp(self):
super(TestStockRouting, self).setUp()
self.base_company = self.env.ref('base.main_company')
self.product_product_model = self.env['product.product']
self.res_users_model = self.env['res.users']
self.stock_location_model = self.env['stock.location']
self.stock_move_model = self.env['stock.move']
self.stock_picking_model = self.env['stock.picking']
self.stock_quant_model = self.env['stock.quant']
self.picking_internal = self.env.ref('stock.picking_type_internal')
today = date.today()
self.env['res.config.settings'].create({
'outgoing_routing_strategy': 'location_id.name',
'outgoing_routing_order': '0',
'stock_reservation_strategy': 'none',
}).execute()
self.stock_A = self.stock_location_model.create({
'name': 'A',
'usage': 'internal',
})
self.stock_A1 = self.stock_location_model.create({
'name': 'A-1',
'usage': 'internal',
'location_id': self.stock_A.id,
'removal_prio': 2,
})
self.stock_A2 = self.stock_location_model.create({
'name': 'A-2',
'usage': 'internal',
'location_id': self.stock_A.id,
'removal_prio': 3,
})
self.stock_A3 = self.stock_location_model.create({
'name': 'A-3',
'usage': 'internal',
'location_id': self.stock_A.id,
'removal_prio': 1,
})
self.stock_B = self.stock_location_model.create({
'name': 'B',
'usage': 'internal',
})
self.product_Z = self.product_product_model.create({
'name': 'Product',
'type': 'product',
})
quant_1 = self.stock_quant_model.create({
'product_id': self.product_Z.id,
'location_id': self.stock_A1.id, # prio:2
'quantity': 15.0,
'in_date': today,
})
quant_2 = self.stock_quant_model.create({
'product_id': self.product_Z.id,
'location_id': self.stock_A2.id, # prio:3
'quantity': 5.0,
'in_date': today,
})
quant_3 = self.stock_quant_model.create({
'product_id': self.product_Z.id,
'location_id': self.stock_A3.id, # prio:1
'quantity': 10.0,
'in_date': today,
})
self.quants = quant_1 + quant_2 + quant_3
def test_stock_reservation_by_name_case1(self):
quants = self.stock_quant_model._update_reserved_quantity(self.product_Z, self.stock_A, 10)
for quant, quantity in quants:
if quant.location_id == self.stock_A1: self.assertEqual(quant.reserved_quantity, 10.0, '10 products should be reserved in A-1')
if quant.location_id == self.stock_A2: self.assertEqual(quant.reserved_quantity, 0.0, 'No products should be reserved in A-2')
if quant.location_id == self.stock_A3: self.assertEqual(quant.reserved_quantity, 0.0, 'No products should be reserved in A-3')
def test_stock_reservation_by_name_case2(self):
quants = self.stock_quant_model._update_reserved_quantity(self.product_Z, self.stock_A, 12)
for quant, quantity in quants:
if quant.location_id == self.stock_A1: self.assertEqual(quant.reserved_quantity, 12.0, '12 products should be reserved in A-1')
if quant.location_id == self.stock_A2: self.assertEqual(quant.reserved_quantity, 0.0, 'No products should be reserved in A-2')
if quant.location_id == self.stock_A3: self.assertEqual(quant.reserved_quantity, 0.0, 'No products should be reserved in A-3')
def test_stock_reservation_by_name_case3(self):
quants = self.stock_quant_model._update_reserved_quantity(self.product_Z, self.stock_A, 22)
for quant, quantity in quants:
if quant.location_id == self.stock_A1: self.assertEqual(quant.reserved_quantity, 15.0, '15 products should be reserved in A-1')
if quant.location_id == self.stock_A2: self.assertEqual(quant.reserved_quantity, 5.0, '5 products should be reserved in A-2')
if quant.location_id == self.stock_A3: self.assertEqual(quant.reserved_quantity, 2.0, '2 products should be reserved in A-3')

View file

@ -0,0 +1,110 @@
# Copyright 2020 VentorTech OU
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0).
from datetime import date
from odoo.tests.common import TransactionCase
class TestStockRouting(TransactionCase):
def setUp(self):
super(TestStockRouting, self).setUp()
self.base_company = self.env.ref('base.main_company')
self.product_product_model = self.env['product.product']
self.res_users_model = self.env['res.users']
self.stock_location_model = self.env['stock.location']
self.stock_move_model = self.env['stock.move']
self.stock_picking_model = self.env['stock.picking']
self.stock_quant_model = self.env['stock.quant']
self.picking_internal = self.env.ref('stock.picking_type_internal')
today = date.today()
self.env['res.config.settings'].create({
'outgoing_routing_strategy': 'location_id.removal_prio',
'outgoing_routing_order': '0',
'stock_reservation_strategy': 'base',
}).execute()
self.stock_A = self.stock_location_model.create({
'name': 'A',
'usage': 'internal',
})
self.stock_A1 = self.stock_location_model.create({
'name': 'A-1',
'usage': 'internal',
'location_id': self.stock_A.id,
'removal_prio': 2,
})
self.stock_A2 = self.stock_location_model.create({
'name': 'A-2',
'usage': 'internal',
'location_id': self.stock_A.id,
'removal_prio': 3,
})
self.stock_A3 = self.stock_location_model.create({
'name': 'A-3',
'usage': 'internal',
'location_id': self.stock_A.id,
'removal_prio': 1,
})
self.stock_B = self.stock_location_model.create({
'name': 'B',
'usage': 'internal',
})
self.product_Z = self.product_product_model.create({
'name': 'Product',
'type': 'product',
})
quant_1 = self.stock_quant_model.create({
'product_id': self.product_Z.id,
'location_id': self.stock_A1.id, # prio:2
'quantity': 15.0,
'in_date': today,
})
quant_2 = self.stock_quant_model.create({
'product_id': self.product_Z.id,
'location_id': self.stock_A2.id, # prio:3
'quantity': 5.0,
'in_date': today,
})
quant_3 = self.stock_quant_model.create({
'product_id': self.product_Z.id,
'location_id': self.stock_A3.id, # prio:1
'quantity': 10.0,
'in_date': today,
})
self.quants = quant_1 + quant_2 + quant_3
def test_stock_reservation_by_priority_case1(self):
quants = self.stock_quant_model._update_reserved_quantity(self.product_Z, self.stock_A, 10)
for quant, quantity in quants:
if quant.location_id == self.stock_A1: self.assertEqual(quant.reserved_quantity, 0.0, 'No products should be reserved in A-1 (prio:2)')
if quant.location_id == self.stock_A2: self.assertEqual(quant.reserved_quantity, 0.0, 'No products should be reserved in A-2 (prio:3)')
if quant.location_id == self.stock_A3: self.assertEqual(quant.reserved_quantity, 10.0, '10 products should be reserved in A-3 (prio:1)')
def test_stock_reservation_by_priority_case2(self):
quants = self.stock_quant_model._update_reserved_quantity(self.product_Z, self.stock_A, 12)
for quant, quantity in quants:
if quant.location_id == self.stock_A1: self.assertEqual(quant.reserved_quantity, 2.0, '2 products should be reserved in A-1 (prio:2)')
if quant.location_id == self.stock_A2: self.assertEqual(quant.reserved_quantity, 0.0, 'No products should be reserved in A-2 (prio:3)')
if quant.location_id == self.stock_A3: self.assertEqual(quant.reserved_quantity, 10.0, '10 products should be reserved in A-3 (prio:1)')
def test_stock_reservation_by_priority_case3(self):
quants = self.stock_quant_model._update_reserved_quantity(self.product_Z, self.stock_A, 22)
for quant, quantity in quants:
if quant.location_id == self.stock_A1: self.assertEqual(quant.reserved_quantity, 12.0, '12 products should be reserved in A-1 (prio:2)')
if quant.location_id == self.stock_A2: self.assertEqual(quant.reserved_quantity, 0.0, 'No products should be reserved in A-2 (prio:3)')
if quant.location_id == self.stock_A3: self.assertEqual(quant.reserved_quantity, 10.0, '10 products should be reserved in A-3 (prio:1)')

View file

@ -0,0 +1,110 @@
# Copyright 2020 VentorTech OU
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0).
from datetime import date
from odoo.tests.common import TransactionCase
class TestStockRouting(TransactionCase):
def setUp(self):
super(TestStockRouting, self).setUp()
self.base_company = self.env.ref('base.main_company')
self.product_product_model = self.env['product.product']
self.res_users_model = self.env['res.users']
self.stock_location_model = self.env['stock.location']
self.stock_move_model = self.env['stock.move']
self.stock_picking_model = self.env['stock.picking']
self.stock_quant_model = self.env['stock.quant']
self.picking_internal = self.env.ref('stock.picking_type_internal')
today = date.today()
self.env['res.config.settings'].create({
'outgoing_routing_strategy': 'location_id.removal_prio',
'outgoing_routing_order': '0',
'stock_reservation_strategy': 'quantity',
}).execute()
self.stock_A = self.stock_location_model.create({
'name': 'A',
'usage': 'internal',
})
self.stock_A1 = self.stock_location_model.create({
'name': 'A-1',
'usage': 'internal',
'location_id': self.stock_A.id,
'removal_prio': 2,
})
self.stock_A2 = self.stock_location_model.create({
'name': 'A-2',
'usage': 'internal',
'location_id': self.stock_A.id,
'removal_prio': 3,
})
self.stock_A3 = self.stock_location_model.create({
'name': 'A-3',
'usage': 'internal',
'location_id': self.stock_A.id,
'removal_prio': 1,
})
self.stock_B = self.stock_location_model.create({
'name': 'B',
'usage': 'internal',
})
self.product_Z = self.product_product_model.create({
'name': 'Product',
'type': 'product',
})
quant_1 = self.stock_quant_model.create({
'product_id': self.product_Z.id,
'location_id': self.stock_A1.id, # prio:2
'quantity': 15.0,
'in_date': today,
})
quant_2 = self.stock_quant_model.create({
'product_id': self.product_Z.id,
'location_id': self.stock_A2.id, # prio:3
'quantity': 5.0,
'in_date': today,
})
quant_3 = self.stock_quant_model.create({
'product_id': self.product_Z.id,
'location_id': self.stock_A3.id, # prio:1
'quantity': 10.0,
'in_date': today,
})
self.quants = quant_1 + quant_2 + quant_3
def test_stock_reservation_by_quantity_case1(self):
quants = self.stock_quant_model._update_reserved_quantity(self.product_Z, self.stock_A, 10)
for quant, quantity in quants:
if quant.location_id == self.stock_A1: self.assertEqual(quant.reserved_quantity, 0.0, 'No products should be reserved in A-1 (prio:2)')
if quant.location_id == self.stock_A2: self.assertEqual(quant.reserved_quantity, 0.0, 'No products should be reserved in A-2 (prio:3)')
if quant.location_id == self.stock_A3: self.assertEqual(quant.reserved_quantity, 10.0, '10 products should be reserved in A-3 (prio:1)')
def test_stock_reservation_by_quantity_case2(self):
quants = self.stock_quant_model._update_reserved_quantity(self.product_Z, self.stock_A, 12)
for quant, quantity in quants:
if quant.location_id == self.stock_A1: self.assertEqual(quant.reserved_quantity, 12.0, 'No products should be reserved in A-1 (prio:2)')
if quant.location_id == self.stock_A2: self.assertEqual(quant.reserved_quantity, 0.0, '12 products should be reserved in A-2 (prio:3)')
if quant.location_id == self.stock_A3: self.assertEqual(quant.reserved_quantity, 0.0, 'No products should be reserved in A-3 (prio:1)')
def test_stock_reservation_by_quantity_case3(self):
quants = self.stock_quant_model._update_reserved_quantity(self.product_Z, self.stock_A, 22)
for quant, quantity in quants:
if quant.location_id == self.stock_A1: self.assertEqual(quant.reserved_quantity, 12.0, '12 products should be reserved in A-1 (prio:2)')
if quant.location_id == self.stock_A2: self.assertEqual(quant.reserved_quantity, 0.0, 'No products should be reserved in A-2 (prio:3)')
if quant.location_id == self.stock_A3: self.assertEqual(quant.reserved_quantity, 10.0, '10 products should be reserved in A-3 (prio:1)')