[IMP] stock_location_orderpoint: Improve loop and add a test

This commit is contained in:
Denis Roussel
2023-04-19 16:07:47 +02:00
committed by Michael Tietz
parent 288c56f413
commit ef1a3ba655
3 changed files with 37 additions and 3 deletions

View File

@@ -43,9 +43,7 @@ class StockMove(models.Model):
locations_products = defaultdict(set)
location_ids = set()
product_obj = self.env["product.product"]
for move in self:
if not move.filtered_domain(domain):
continue
for move in self.filtered_domain(domain):
location = getattr(move, location_field)
locations_products[location].add(move.product_id.id)
location_ids.add(location.id)

View File

@@ -90,6 +90,15 @@ class TestLocationOrderpointCommon(SavepointCase):
move._action_confirm()
return move
def _create_scrap_move(self, qty, location):
scrap = self.env["stock.location"].search(
[("scrap_location", "=", True)], limit=1
)
move = self._create_move("Scrap", qty, location, scrap)
move.move_line_ids.write({"qty_done": qty})
move._action_done()
return move
def _create_incoming_move(self, qty, location):
move = self._create_move(
"Receive", qty, self.env.ref("stock.stock_location_suppliers"), location

View File

@@ -155,6 +155,33 @@ class TestLocationOrderpoint(TestLocationOrderpointCommon):
self.assertEqual(replenish_move, replenish_move_new)
self._check_replenishment_move(replenish_move, move_qty * 2, orderpoint)
def test_auto_no_replenishment(self):
"""
Create a stock move that should not create a replenishment:
- A move from a new stock location 'WH/Stock 2' to Scrap
"""
job_func = self.env["stock.location.orderpoint"].run_auto_replenishment
with trap_jobs() as trap:
new_location = self.env["stock.location"].create(
{
"name": "Other Stock",
"location_id": self.location_dest.location_id.id,
}
)
_, _ = self._create_orderpoint_complete("Stock2", trigger="auto")
self.location_dest = new_location
self._create_quants(self.product, self.location_dest, 10.0)
move = self._create_scrap_move(10.0, self.location_dest)
trap.assert_jobs_count(0, only=job_func)
trap.perform_enqueued_jobs()
replenish_move = self.env["stock.move"].search(
[
("product_id", "=", move.product_id.id),
("location_dest_id", "=", move.location_id.id),
]
)
self.assertFalse(replenish_move)
def test_orderpoint_count(self):
"""
One orderpoint has already been created in demo data.