Skip to content

Commit f12d6e0

Browse files
committed
sale_stock_available_to_promise_release: improve '_get_next_replenishment_date' perf
Checking ongoing states instead of finished ones (done and canceled) helps PostgreSQL to perform the filter on far less lines (done lines are increasing a lot over time), speeding up the query to get the next replenishment date.
1 parent c114af4 commit f12d6e0

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

sale_stock_available_to_promise_release/models/product_product.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ def _get_next_replenishment_date(self):
1212
move_line = self.env["stock.move"].search(
1313
[
1414
("product_id", "=", self.id),
15-
("state", "not in", ["done", "cancel"]),
15+
(
16+
"state",
17+
"in",
18+
[
19+
"draft",
20+
"waiting",
21+
"confirmed",
22+
"partially_available",
23+
"assigned",
24+
],
25+
),
1626
("picking_type_id.code", "=", "incoming"),
1727
],
1828
limit=1,

sale_stock_available_to_promise_release/models/stock_move.py

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ class StockMove(models.Model):
1111
sale_date_expected = fields.Date(
1212
"Delivery Date", related="group_id.date_expected", store="True"
1313
)
14+
# Add index on picking_type_id to speedup '_get_next_replenishment_date'
15+
# method on 'product.product'
16+
picking_type_id = fields.Many2one(index=True)

0 commit comments

Comments
 (0)