[FIX] stock_inventory: fix the case that corresponds to a shared location between several companies (as company_id is a related on quant location)

This commit is contained in:
AlexPForgeFlow
2023-09-19 09:45:14 +02:00
committed by Denis Roussel
parent 67297089a3
commit 26f6f45910
2 changed files with 9 additions and 2 deletions

View File

@@ -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

View File

@@ -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, [])