mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[FIX] adapt back to V14
This commit is contained in:
@@ -2,9 +2,8 @@
|
||||
# Copyright 2021 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo.tests.common import SavepointCase
|
||||
from odoo.osv.expression import TRUE_LEAF
|
||||
from odoo.tests.common import TransactionCase
|
||||
from odoo.tests.common import SavepointCase
|
||||
|
||||
|
||||
class TestPotentialQty(SavepointCase):
|
||||
@@ -18,11 +17,12 @@ class TestPotentialQty(SavepointCase):
|
||||
cls.bom_model = cls.env["mrp.bom"]
|
||||
cls.bom_line_model = cls.env["mrp.bom.line"]
|
||||
cls.stock_quant_model = cls.env["stock.quant"]
|
||||
cls.config = cls.env['ir.config_parameter']
|
||||
cls.location = cls.env['stock.location']
|
||||
cls.config = cls.env["ir.config_parameter"]
|
||||
cls.location = cls.env["stock.location"]
|
||||
cls.main_company = cls.env.ref("base.main_company")
|
||||
# Get the warehouses
|
||||
cls.wh_main = cls.env.ref('stock.warehouse0')
|
||||
cls.wh_ch = cls.env.ref('stock.stock_warehouse_shop0')
|
||||
cls.wh_main = cls.env.ref("stock.warehouse0")
|
||||
cls.wh_ch = cls.env.ref("stock.stock_warehouse_shop0")
|
||||
|
||||
# We need to compute parent_left and parent_right of the locations as
|
||||
# they are used to compute qty_available of the product.
|
||||
@@ -32,39 +32,64 @@ class TestPotentialQty(SavepointCase):
|
||||
@classmethod
|
||||
def setup_demo_data(cls):
|
||||
# An interesting product (multi-line BoM, variants)
|
||||
cls.tmpl = cls.env.ref(
|
||||
'mrp.product_product_build_kit_product_template')
|
||||
cls.tmpl = cls.env.ref("mrp.product_product_table_kit_product_template")
|
||||
# First variant
|
||||
cls.var1 = cls.env.ref('mrp.product_product_build_kit')
|
||||
cls.var1.type = 'product'
|
||||
cls.var1 = cls.env.ref("mrp.product_product_table_kit")
|
||||
cls.var1.type = "product"
|
||||
# Second variant
|
||||
cls.var2 = cls.env.ref(
|
||||
'stock_available_mrp.product_kit_1a')
|
||||
cls.var2.type = 'product'
|
||||
cls.var2 = cls.env.ref("stock_available_mrp.product_kit_1a")
|
||||
cls.var2.type = "product"
|
||||
# Make bolt a stockable product to be able to change its stock
|
||||
# we need to unreserve the existing move before being able to do it.
|
||||
bolt = cls.env.ref("mrp.product_product_computer_desk_bolt")
|
||||
bolt.stock_move_ids._do_unreserve()
|
||||
bolt.type = "product"
|
||||
# Components that can be used to make the product
|
||||
components = (
|
||||
# KeyBoard
|
||||
cls.env.ref('product.product_product_9') |
|
||||
# Mouse
|
||||
cls.env.ref('product.product_product_12')
|
||||
)
|
||||
|
||||
components = [
|
||||
# Bolt
|
||||
bolt,
|
||||
# Wood Panel
|
||||
cls.env.ref("mrp.product_product_wood_panel"),
|
||||
]
|
||||
# Zero-out the inventory of all variants and components
|
||||
for component in components + cls.tmpl.product_variant_ids:
|
||||
cls.env['stock.quant'].search([
|
||||
('product_id', '=', component.id)
|
||||
]).unlink()
|
||||
for component in components + [v for v in cls.tmpl.product_variant_ids]:
|
||||
moves = component.stock_move_ids.filtered(
|
||||
lambda mo: mo.state not in ("done", "cancel")
|
||||
)
|
||||
moves._action_cancel()
|
||||
|
||||
cls.product_model.invalidate_cache()
|
||||
# A product without a BoM
|
||||
cls.product_wo_bom = cls.env.ref('product.product_product_11')
|
||||
component.stock_quant_ids.unlink()
|
||||
|
||||
# A product without a BoM
|
||||
cls.product_wo_bom = cls.env.ref("product.product_product_11")
|
||||
|
||||
# Record the initial quantity available for sale
|
||||
cls.initial_usable_qties = {i.id: i.immediately_usable_qty
|
||||
for i in [cls.tmpl,
|
||||
cls.var1,
|
||||
cls.var2,
|
||||
cls.product_wo_bom]}
|
||||
cls.initial_usable_qties = {
|
||||
i.id: i.immediately_usable_qty
|
||||
for i in [cls.tmpl, cls.var1, cls.var2, cls.product_wo_bom]
|
||||
}
|
||||
|
||||
def _create_inventory(self, location_id, company_id):
|
||||
inventory = self.env["stock.inventory"].create(
|
||||
{
|
||||
"name": "Test inventory",
|
||||
"company_id": company_id,
|
||||
"location_ids": [(4, location_id)],
|
||||
"start_empty": True,
|
||||
}
|
||||
)
|
||||
inventory.action_start()
|
||||
return inventory
|
||||
|
||||
def _create_inventory_line(self, inventory_id, product_id, location_id, qty):
|
||||
self.env["stock.inventory.line"].create(
|
||||
{
|
||||
"inventory_id": inventory_id,
|
||||
"product_id": product_id,
|
||||
"location_id": location_id,
|
||||
"product_qty": qty,
|
||||
}
|
||||
)
|
||||
|
||||
def create_inventory(self, product_id, qty, location_id=None, company_id=None):
|
||||
if location_id is None:
|
||||
@@ -353,74 +378,6 @@ class TestPotentialQty(SavepointCase):
|
||||
p1.refresh()
|
||||
self.assertEqual(2.0, p1.potential_qty)
|
||||
|
||||
def test_component_stock_choice(self):
|
||||
# Test to change component stock for compute BOM stock
|
||||
|
||||
# Get a demo product with outgoing move (qty: 3)
|
||||
prod = self.env.ref('product.product_product_20')
|
||||
|
||||
# Set on hand qty
|
||||
self.create_inventory(prod.id, 3)
|
||||
|
||||
# Create a product with BOM
|
||||
p1 = self.product_model.create({
|
||||
'name': 'Test product with BOM',
|
||||
})
|
||||
bom_p1 = self.bom_model.create({
|
||||
'product_tmpl_id': p1.product_tmpl_id.id,
|
||||
'product_id': p1.id,
|
||||
'product_qty': 1,
|
||||
})
|
||||
|
||||
# Need 1 prod for that
|
||||
self.bom_line_model.create({
|
||||
'bom_id': bom_p1.id,
|
||||
'product_id': prod.id,
|
||||
'product_qty': 1,
|
||||
})
|
||||
|
||||
# Default component is qty_available
|
||||
p1.refresh()
|
||||
self.assertEqual(3.0, p1.potential_qty)
|
||||
|
||||
# Change to immediately usable
|
||||
self.config.set_param('stock_available_mrp_based_on',
|
||||
'immediately_usable_qty')
|
||||
|
||||
p1.refresh()
|
||||
self.assertEqual(0.0, p1.potential_qty)
|
||||
|
||||
# If iMac has a Bom and can be manufactured
|
||||
component = self.product_model.create({
|
||||
'name': 'component',
|
||||
'type': 'product'
|
||||
})
|
||||
self.create_inventory(component.id, 5)
|
||||
|
||||
imac_bom = self.bom_model.create({
|
||||
'product_tmpl_id': prod.product_tmpl_id.id,
|
||||
'product_id': prod.id,
|
||||
'product_qty': 1,
|
||||
'type': 'phantom',
|
||||
})
|
||||
|
||||
# Need 1 component for prod
|
||||
self.bom_line_model.create({
|
||||
'bom_id': imac_bom.id,
|
||||
'product_id': component.id,
|
||||
'product_qty': 1,
|
||||
})
|
||||
|
||||
p1.refresh()
|
||||
self.assertEqual(5.0, p1.potential_qty)
|
||||
|
||||
# Changing to virtual (same as immediately in current config)
|
||||
self.config.set_param('stock_available_mrp_based_on',
|
||||
'virtual_available')
|
||||
p1.refresh()
|
||||
|
||||
self.assertEqual(5.0, p1.potential_qty)
|
||||
|
||||
def test_potential_qty_list(self):
|
||||
# Try to highlight a bug when _get_potential_qty is called on
|
||||
# a recordset with multiple products
|
||||
|
||||
Reference in New Issue
Block a user