From 26f6f4591002168e3b152b848f3e63b0f30d68ae Mon Sep 17 00:00:00 2001 From: AlexPForgeFlow Date: Tue, 19 Sep 2023 09:45:14 +0200 Subject: [PATCH] [FIX] stock_inventory: fix the case that corresponds to a shared location between several companies (as company_id is a related on quant location) --- stock_inventory/models/stock_quant.py | 9 +++++++-- stock_inventory/tests/test_stock_inventory.py | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/stock_inventory/models/stock_quant.py b/stock_inventory/models/stock_quant.py index 49b46c689..bea534f33 100644 --- a/stock_inventory/models/stock_quant.py +++ b/stock_inventory/models/stock_quant.py @@ -1,4 +1,4 @@ -from odoo import fields, models +from odoo import _, fields, models class StockQuant(models.Model): @@ -22,13 +22,18 @@ class StockQuant(models.Model): [ ("product_id", "=", rec.product_id.id), ("lot_id", "=", rec.lot_id.id), - ("company_id", "=", rec.company_id.id), "|", ("location_id", "=", rec.location_id.id), ("location_dest_id", "=", rec.location_id.id), ], order="create_date asc", + ).filtered( + lambda x: not x.company_id.id + or not rec.company_id.id + or rec.company_id.id == x.company_id.id ) + if len(moves) == 0: + raise ValueError(_("No move lines have been created")) move = moves[len(moves) - 1] adjustment.stock_move_ids |= move move.inventory_adjustment_id = adjustment diff --git a/stock_inventory/tests/test_stock_inventory.py b/stock_inventory/tests/test_stock_inventory.py index b02070a3c..67b2a976c 100644 --- a/stock_inventory/tests/test_stock_inventory.py +++ b/stock_inventory/tests/test_stock_inventory.py @@ -292,6 +292,8 @@ class TestStockInventory(TransactionCase): } ) inventory1.action_state_to_in_progress() + # Remove company_id from stock-quant to test it works as expected + inventory1.stock_quant_ids.write({"company_id": False}) self.assertEqual(inventory1.stock_quant_ids.ids, [self.quant4.id]) inventory1.action_state_to_draft() self.assertEqual(inventory1.stock_quant_ids.ids, [])