Skip to content

Commit

Permalink
Merge PR #769 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by jbaudoux
  • Loading branch information
OCA-git-bot committed Nov 9, 2023
2 parents 16a9419 + 76f8461 commit a0149c7
Showing 1 changed file with 33 additions and 24 deletions.
57 changes: 33 additions & 24 deletions stock_available_to_promise_release/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,29 +146,40 @@ def _previous_promised_qty_sql_main_query(self):
GROUP BY move.id;
"""

def _previous_promised_qty_sql_moves_before_matches(self):
return "COALESCE(m.need_release, False) = COALESCE(move.need_release, False)"

def _previous_promised_qty_sql_moves_before(self):
sql = """
m.priority > move.priority
OR
(
m.priority = move.priority
AND m.date_priority < move.date_priority
)
OR (
m.priority = move.priority
AND m.date_priority = move.date_priority
AND m.picking_type_id = move.picking_type_id
AND m.id < move.id
)
OR (
m.priority = move.priority
AND m.date_priority = move.date_priority
AND m.picking_type_id != move.picking_type_id
AND m.id > move.id
{moves_matches}
AND (
m.priority > move.priority
OR
(
m.priority = move.priority
AND m.date_priority < move.date_priority
)
OR (
m.priority = move.priority
AND m.date_priority = move.date_priority
AND m.picking_type_id = move.picking_type_id
AND m.id < move.id
)
OR (
m.priority = move.priority
AND m.date_priority = move.date_priority
AND m.picking_type_id != move.picking_type_id
AND m.id > move.id
)
)
"""
""".format(
moves_matches=self._previous_promised_qty_sql_moves_before_matches()
)
return sql

def _previous_promised_qty_sql_moves_no_release(self):
return "m.need_release IS false OR m.need_release IS null"

def _previous_promised_qty_sql_lateral_where(self):
locations = self._ordered_available_to_promise_locations()
sql = """
Expand All @@ -177,20 +188,18 @@ def _previous_promised_qty_sql_lateral_where(self):
AND p_type.code = 'outgoing'
AND loc.parent_path LIKE ANY(%(location_paths)s)
AND (
COALESCE(m.need_release, False) = COALESCE(move.need_release, False)
AND (
{moves_before}
)
{moves_before}
OR (
move.need_release IS true
AND (m.need_release IS false OR m.need_release IS null)
AND ({moves_no_release})
)
)
AND m.state IN (
'waiting', 'confirmed', 'partially_available', 'assigned'
)
""".format(
moves_before=self._previous_promised_qty_sql_moves_before()
moves_before=self._previous_promised_qty_sql_moves_before(),
moves_no_release=self._previous_promised_qty_sql_moves_no_release(),
)
params = {
"location_paths": [
Expand Down

0 comments on commit a0149c7

Please sign in to comment.