Skip to content

Commit

Permalink
[IMP] stock_move_auto_assign_auto_release: Release release_ready move…
Browse files Browse the repository at this point in the history
…s together

Release all release_ready moves of a transfers marked with release_policy=one together
  • Loading branch information
mt-software-de committed Jul 30, 2024
1 parent 18c4152 commit d1465d8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
13 changes: 11 additions & 2 deletions stock_move_auto_assign_auto_release/models/product_product.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2022 ACSONE SA/NV
# Copyright 2024 Michael Tietz (MT Software) <mtietz@mt-software.de>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models
Expand All @@ -17,13 +18,21 @@ def _moves_auto_release_domain(self):
def moves_auto_release(self):
"""Job trying to auto release moves based on product
It searches all* the moves auto releasable and trigger the release
available to promise process.
It searches all* the moves auto releasable and there siblings
and trigger the release available to promise process.
"""
self.ensure_one()
moves = self.env["stock.move"].search(self._moves_auto_release_domain())
pickings = moves.picking_id
if not pickings:
return
self._lock_pickings_or_retry(pickings)
move_ids = moves.ids
for picking in pickings:
if picking.release_policy != "one":
continue
for move in picking.move_lines:
if move.id not in move_ids and move.is_auto_release_allowed:
move_ids.append(move.id)
moves = moves.browse(move_ids)
moves.release_available_to_promise()
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* Laurent Mignon <laurent.mignon@acsone.eu>
* Michael Tietz (MT Software) <mtietz@mt-software.de>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2022 ACSONE SA/NV
# Copyright 2024 Michael Tietz (MT Software) <mtietz@mt-software.de>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from datetime import datetime

Expand Down Expand Up @@ -166,3 +167,34 @@ def test_move_field_is_auto_release_allowed(self):
for domain in NOT_RELEASABLE_DOMAINS:
self.assertIn(move_released, self.env["stock.move"].search(domain))
self.assertNotIn(move_not_released, self.env["stock.move"].search(domain))

def test_picking_policy_one_async_receive(self):
shipping = self._out_picking(
self._create_picking_chain(
self.wh,
[(self.product1, 10), (self.product2, 10)],
date=datetime(2019, 9, 2, 16, 0),
)
)
shipping.release_policy = "one"
shipping.move_type = "one"
self.assertTrue(
all(
move.need_release and not move.release_ready
for move in shipping.move_lines
)
)
with trap_jobs() as trap:
self._receive_product(self.product1, 100)
trap.perform_enqueued_jobs()
with trap_jobs() as trap:
self._receive_product(self.product2, 100)
trap.perform_enqueued_jobs()
move_product1 = shipping.move_lines.filtered(
lambda m: m.product_id == self.product1
)
move_product2 = shipping.move_lines - move_product1
self.assertFalse(move_product2.release_ready)
self.assertFalse(move_product2.need_release)
self.assertFalse(move_product1.need_release)
self.assertFalse(move_product1.release_ready)

0 comments on commit d1465d8

Please sign in to comment.