mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] stock_location_orderpoint: Improve loop and add a test
This commit is contained in:
committed by
Michael Tietz
parent
288c56f413
commit
ef1a3ba655
@@ -43,9 +43,7 @@ class StockMove(models.Model):
|
|||||||
locations_products = defaultdict(set)
|
locations_products = defaultdict(set)
|
||||||
location_ids = set()
|
location_ids = set()
|
||||||
product_obj = self.env["product.product"]
|
product_obj = self.env["product.product"]
|
||||||
for move in self:
|
for move in self.filtered_domain(domain):
|
||||||
if not move.filtered_domain(domain):
|
|
||||||
continue
|
|
||||||
location = getattr(move, location_field)
|
location = getattr(move, location_field)
|
||||||
locations_products[location].add(move.product_id.id)
|
locations_products[location].add(move.product_id.id)
|
||||||
location_ids.add(location.id)
|
location_ids.add(location.id)
|
||||||
|
|||||||
@@ -90,6 +90,15 @@ class TestLocationOrderpointCommon(SavepointCase):
|
|||||||
move._action_confirm()
|
move._action_confirm()
|
||||||
return move
|
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):
|
def _create_incoming_move(self, qty, location):
|
||||||
move = self._create_move(
|
move = self._create_move(
|
||||||
"Receive", qty, self.env.ref("stock.stock_location_suppliers"), location
|
"Receive", qty, self.env.ref("stock.stock_location_suppliers"), location
|
||||||
|
|||||||
@@ -155,6 +155,33 @@ class TestLocationOrderpoint(TestLocationOrderpointCommon):
|
|||||||
self.assertEqual(replenish_move, replenish_move_new)
|
self.assertEqual(replenish_move, replenish_move_new)
|
||||||
self._check_replenishment_move(replenish_move, move_qty * 2, orderpoint)
|
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):
|
def test_orderpoint_count(self):
|
||||||
"""
|
"""
|
||||||
One orderpoint has already been created in demo data.
|
One orderpoint has already been created in demo data.
|
||||||
|
|||||||
Reference in New Issue
Block a user