Skip to content

Commit 4b11a55

Browse files
[FIX] stock_inventory_preparation_filter: exclude virtual locations from quant search
1 parent 00ebed0 commit 4b11a55

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

stock_inventory_preparation_filter/models/stock_inventory.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,10 @@ def _get_quants(self, locations):
4242
if self.product_selection == "domain":
4343
domain = safe_eval(self.product_domain)
4444
products = self.env["product.product"].search(domain)
45-
return self.env["stock.quant"].search([("product_id", "in", products.ids)])
45+
return self.env["stock.quant"].search(
46+
[
47+
("product_id", "in", products.ids),
48+
("location_id", "in", locations.ids),
49+
]
50+
)
4651
return super()._get_quants(locations)

stock_inventory_preparation_filter/tests/test_stock_inventory_preparation_filter.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,32 @@ def test_inventory_domain_filter(self):
146146
line1 = inventory.stock_quant_ids[0]
147147
self.assertEqual(line1.product_id, self.product1)
148148
self.assertEqual(line1.quantity, 2.0)
149+
150+
def test_inventory_domain_filter_excludes_virtual_locations(self):
151+
"""Test that domain filter does not include quants from virtual locations."""
152+
153+
virtual_location = self.env.ref("stock.stock_location_customers")
154+
self.env["stock.quant"].create(
155+
{
156+
"product_id": self.product1.id,
157+
"product_uom_id": self.product1.uom_id.id,
158+
"location_id": virtual_location.id,
159+
"quantity": 5.0,
160+
}
161+
)
162+
163+
inventory = self.inventory_model.create(
164+
{
165+
"name": "Domain inventory excluding virtual locations",
166+
"product_selection": "domain",
167+
"product_domain": [("id", "=", self.product1.id)],
168+
"location_ids": self.env.ref("stock.stock_location_stock"),
169+
}
170+
)
171+
inventory.action_state_to_in_progress()
172+
173+
self.assertEqual(len(inventory.stock_quant_ids), 1)
174+
self.assertEqual(
175+
inventory.stock_quant_ids.location_id,
176+
self.env.ref("stock.stock_location_stock"),
177+
)

0 commit comments

Comments
 (0)