Skip to content

Commit

Permalink
[FIX] stock: Improve date_deadline propagation
Browse files Browse the repository at this point in the history
The date_deadline propagation would update the sale records multiple times depending on some configuration (check example below).
This happens because 'already_propagate_ids' is copied at the beginning of _set_date_deadline (set | set = new set).
So, when a child move propagates to multiple other moves, it is not known by the parent move, which will redo the propagation.

To prevent this, we always keep the same reference for 'already_propagate_ids' (context: 'date_deadline_propagate_ids'). This means that a parent and child move share the exact same Set, and when the child move updates the Set, it also updates the parent Set.
So when a child move propagates, the parent will know which moves have been done.

   MOVES LINKAGE
       Move B
      /   |   \
  Move A  |  Move D
      \   |   /
       Move C

PROPAGATION GRAPHS:
  BEFORE    |  AFTER
------------+--------
    A       |    A
  /   \     |    |
  C   B     |    B
 / \ / \    |    |
 B D C D    |    C
 | | | |    |    |
 D B D C    |    D
------------+--------
    11      |    4     NUMBER OF CALLS

OPW-3904178

closes odoo#164734

Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com>
Co-authored-by: Mathieu Walravens <wama@odoo.com>
  • Loading branch information
DavidFesquet and mwath committed May 8, 2024
1 parent ded04d5 commit 85ec121
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion addons/stock/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,8 @@ def key_virtual_available(move, incoming=False):

def _set_date_deadline(self, new_deadline):
# Handle the propagation of `date_deadline` fields (up and down stream - only update by up/downstream documents)
already_propagate_ids = self.env.context.get('date_deadline_propagate_ids', set()) | set(self.ids)
already_propagate_ids = self.env.context.get('date_deadline_propagate_ids', set())
already_propagate_ids.update(self.ids)
self = self.with_context(date_deadline_propagate_ids=already_propagate_ids)
for move in self:
moves_to_update = (move.move_dest_ids | move.move_orig_ids)
Expand Down

0 comments on commit 85ec121

Please sign in to comment.