mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[FIX] mrp_multi_level: starting qty on hand wrong when using lots
Unify the way to get the starting on hand whenever needed in MRP calculations.
This commit is contained in:
committed by
BernatPForgeFlow
parent
fc8ffcd594
commit
6ed19deb8c
@@ -26,6 +26,8 @@ class TestMrpMultiLevelCommon(SavepointCase):
|
||||
cls.mrp_inventory_obj = cls.env["mrp.inventory"]
|
||||
cls.mrp_move_obj = cls.env["mrp.move"]
|
||||
cls.planned_order_obj = cls.env["mrp.planned.order"]
|
||||
cls.lot_model = cls.env["stock.production.lot"]
|
||||
cls.quant_model = cls.env["stock.quant"]
|
||||
|
||||
cls.fp_1 = cls.env.ref("mrp_multi_level.product_product_fp_1")
|
||||
cls.fp_2 = cls.env.ref("mrp_multi_level.product_product_fp_2")
|
||||
@@ -221,6 +223,53 @@ class TestMrpMultiLevelCommon(SavepointCase):
|
||||
cls.product_mrp_area_obj.create(
|
||||
{"product_id": cls.prod_uom_test.id, "mrp_area_id": cls.mrp_area.id}
|
||||
)
|
||||
# Product to test lots
|
||||
cls.product_lots = cls.product_obj.create(
|
||||
{
|
||||
"name": "Product Tracked by Lots",
|
||||
"type": "product",
|
||||
"tracking": "lot",
|
||||
"uom_id": cls.env.ref("uom.product_uom_unit").id,
|
||||
"list_price": 100.0,
|
||||
"produce_delay": 5.0,
|
||||
"route_ids": [(6, 0, [route_buy])],
|
||||
"seller_ids": [(0, 0, {"name": vendor1.id, "price": 25.0})],
|
||||
}
|
||||
)
|
||||
cls.product_mrp_area_obj.create(
|
||||
{"product_id": cls.product_lots.id, "mrp_area_id": cls.mrp_area.id}
|
||||
)
|
||||
cls.lot_1 = cls.lot_model.create(
|
||||
{
|
||||
"product_id": cls.product_lots.id,
|
||||
"name": "Lot 1",
|
||||
"company_id": cls.company.id,
|
||||
}
|
||||
)
|
||||
cls.lot_2 = cls.lot_model.create(
|
||||
{
|
||||
"product_id": cls.product_lots.id,
|
||||
"name": "Lot 2",
|
||||
"company_id": cls.company.id,
|
||||
}
|
||||
)
|
||||
cls.quant_model.sudo().create(
|
||||
{
|
||||
"product_id": cls.product_lots.id,
|
||||
"lot_id": cls.lot_1.id,
|
||||
"quantity": 100.0,
|
||||
"location_id": cls.stock_location.id,
|
||||
}
|
||||
)
|
||||
cls.quant_model.sudo().create(
|
||||
{
|
||||
"product_id": cls.product_lots.id,
|
||||
"lot_id": cls.lot_2.id,
|
||||
"quantity": 110.0,
|
||||
"location_id": cls.stock_location.id,
|
||||
}
|
||||
)
|
||||
|
||||
# Product MRP Parameter to test supply method computation
|
||||
cls.env.ref("stock.route_warehouse0_mto").active = True
|
||||
cls.env["stock.rule"].create(
|
||||
@@ -447,6 +496,9 @@ class TestMrpMultiLevelCommon(SavepointCase):
|
||||
cls.create_demand_sec_loc(cls.date_20, 46.0)
|
||||
cls.create_demand_sec_loc(cls.date_22, 33.0)
|
||||
|
||||
# Create pickings:
|
||||
cls._create_picking_out(cls.product_lots, 25, today)
|
||||
|
||||
cls.mrp_multi_level_wiz.create({}).run_mrp_multi_level()
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -23,23 +23,6 @@ class MultiLevelMrp(models.TransientModel):
|
||||
help="If empty, all areas will be computed.",
|
||||
)
|
||||
|
||||
@api.model
|
||||
def _prepare_product_mrp_area_data(self, product_mrp_area):
|
||||
qty_available = 0.0
|
||||
product_obj = self.env["product.product"]
|
||||
location_ids = product_mrp_area._get_locations()
|
||||
for location in location_ids:
|
||||
product_l = product_obj.with_context({"location": location.id}).browse(
|
||||
product_mrp_area.product_id.id
|
||||
)
|
||||
qty_available += product_l.qty_available
|
||||
|
||||
return {
|
||||
"product_mrp_area_id": product_mrp_area.id,
|
||||
"mrp_qty_available": qty_available,
|
||||
"mrp_llc": product_mrp_area.product_id.llc,
|
||||
}
|
||||
|
||||
@api.model
|
||||
def _prepare_mrp_move_data_from_stock_move(
|
||||
self, product_mrp_area, move, direction="in"
|
||||
@@ -893,9 +876,7 @@ class MultiLevelMrp(models.TransientModel):
|
||||
[("product_mrp_area_id", "=", product_mrp_area.id)], order="due_date"
|
||||
).mapped("due_date")
|
||||
mrp_dates = set(moves_dates + action_dates)
|
||||
on_hand_qty = product_mrp_area.product_id.with_context(
|
||||
location=product_mrp_area._get_locations().ids
|
||||
)._product_available()[product_mrp_area.product_id.id]["qty_available"]
|
||||
on_hand_qty = product_mrp_area.qty_available
|
||||
running_availability = on_hand_qty
|
||||
mrp_inventory_vals = []
|
||||
for mdt in sorted(mrp_dates):
|
||||
|
||||
Reference in New Issue
Block a user