Skip to content

Commit

Permalink
[IMP] stock_inventory: adds exclude_sublocation flag
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidJForgeFlow committed Apr 17, 2024
1 parent 54970dd commit 608c718
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 5 deletions.
21 changes: 16 additions & 5 deletions stock_inventory/models/stock_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class InventoryAdjustmentsGroup(models.Model):
compute="_compute_count_stock_moves", string="Stock Moves Lines"
)

exclude_sublocation = fields.Boolean(
help="If enabled, it will only take into account "
"the locations settled, not the child ones."
)

@api.depends("stock_quant_ids")
def _compute_count_stock_quants(self):
self.count_stock_quants = len(self.stock_quant_ids)
Expand Down Expand Up @@ -99,11 +104,17 @@ def _get_quants(self, locations):
return self.env["stock.quant"].search(domain)

def _get_base_domain(self, locations):
return [
"|",
("location_id", "in", locations.mapped("id")),
("location_id", "in", locations.child_ids.ids),
]
return (
[
("location_id", "in", locations.mapped("id")),
]
if self.exclude_sublocation
else [
"|",
("location_id", "in", locations.mapped("id")),
("location_id", "child_of", locations.child_ids.ids),
]
)

def _get_domain_all_quants(self, base_domain):
return base_domain
Expand Down
45 changes: 45 additions & 0 deletions stock_inventory/tests/test_stock_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,48 @@ def test_05_category_selection(self):
self.assertEqual(inventory1.stock_move_ids.product_id.id, self.product2.id)
self.assertEqual(inventory1.stock_move_ids.location_id.id, self.location3.id)
inventory1.action_state_to_done()

def test_06_exclude_sub_locations(self):
inventory1 = self.inventory_model.create(
{
"name": "Inventory_Test_1",
"product_selection": "all",
"location_ids": [self.location1.id],
"exclude_sublocation": True,
}
)
inventory1.action_state_to_in_progress()
inventory2 = self.inventory_model.create(
{
"name": "Inventory_Test_2",
"product_selection": "all",
"location_ids": [self.location1.id],
"exclude_sublocation": True,
}
)
with self.assertRaises(ValidationError), self.cr.savepoint():
inventory2.action_state_to_in_progress()
self.assertEqual(inventory1.state, "in_progress")
self.assertEqual(
inventory1.stock_quant_ids.ids,
[self.quant1.id],
)
inventory1.action_state_to_draft()
self.assertEqual(inventory1.stock_quant_ids.ids, [])
inventory1.action_state_to_in_progress()
self.assertEqual(inventory1.count_stock_moves, 0)
self.assertEqual(inventory1.count_stock_quants, 1)
self.assertEqual(inventory1.count_stock_quants_string, "1 / 1")
inventory1.action_view_inventory_adjustment()
self.quant1.inventory_quantity = 92
self.quant1.action_apply_inventory()
inventory1._compute_count_stock_quants()
inventory1.action_view_stock_moves()
self.assertEqual(inventory1.count_stock_moves, 1)
self.assertEqual(inventory1.count_stock_quants, 1)
self.assertEqual(inventory1.count_stock_quants_string, "0 / 1")
self.assertEqual(inventory1.stock_move_ids.qty_done, 8)
self.assertEqual(inventory1.stock_move_ids.product_id.id, self.product.id)
self.assertEqual(inventory1.stock_move_ids.lot_id.id, self.lot_1.id)
self.assertEqual(inventory1.stock_move_ids.location_id.id, self.location1.id)
inventory1.action_state_to_done()
5 changes: 5 additions & 0 deletions stock_inventory/views/stock_inventory.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
attrs="{'readonly':[('state', 'in', ['in_progress', 'done'])]}"
required="1"
/>
<field
name="exclude_sublocation"
attrs="{'readonly':[('state', 'in', ['in_progress', 'done'])]}"
required="1"
/>
</group>
<group>
<field name="date" />
Expand Down

0 comments on commit 608c718

Please sign in to comment.