Skip to content

Commit

Permalink
[IMP] stock_available_to_promise_release: Make previous sql hookable
Browse files Browse the repository at this point in the history
  • Loading branch information
mt-software-de committed Oct 22, 2023
1 parent 232e040 commit 76f8461
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 76f8461

Please sign in to comment.