Skip to content

Commit

Permalink
[IMP] repair_picking_after_done: Allow backorders for stock moves lin…
Browse files Browse the repository at this point in the history
…ked to completed repair orders
  • Loading branch information
ppyczko committed Nov 26, 2024
1 parent f9905ee commit c5f40d9
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions repair_picking_after_done/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import models
from . import wizards
from .hooks import post_load_hook
1 change: 1 addition & 0 deletions repair_picking_after_done/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
"development_status": "Alpha",
"license": "AGPL-3",
"application": False,
"post_load": "post_load_hook",
}
25 changes: 25 additions & 0 deletions repair_picking_after_done/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2024 Patryk Pyczko (APSL-Nagarro)<[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.addons.repair.models.stock_move import StockMove


def post_load_hook():
"""
This hook modifies the stock move splitting logic to:
- Allow splitting stock moves related to repair
orders that are marked as "done", which is prevented
by the core Odoo logic.
- This change enables the creation of backorders for
these split stock moves when the associated repair is completed.
"""

def _split_for_repair_custom(self, qty, restrict_partner_id=False):
if self.repair_id and self.repair_id.state != "done":
return []

return super(StockMove, self)._split(qty, restrict_partner_id)

if not hasattr(StockMove, "_split_original"):
StockMove._split_original = StockMove._split
StockMove._split = _split_for_repair_custom
1 change: 1 addition & 0 deletions repair_picking_after_done/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)

from . import test_repair_transfers
from . import test_stock_move_split
58 changes: 58 additions & 0 deletions repair_picking_after_done/tests/test_stock_move_split.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from odoo.tests.common import TransactionCase


class TestStockMoveSplit(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
# Create a product
cls.product = cls.env["product.product"].create(
{
"name": "Test Product",
"type": "product",
}
)

# Create a stock location
cls.location = cls.env["stock.location"].create(
{
"name": "Test Location",
"usage": "internal",
}
)

# Create a repair order in 'draft' state
cls.repair = cls.env["repair.order"].create(
{
"name": "Repair Order 1",
"product_id": cls.product.id,
"state": "draft",
}
)

# Create a stock move linked to the repair order
cls.stock_move = cls.env["stock.move"].create(
{
"name": "Stock Move for Repair Order 1",
"product_id": cls.product.id,
"product_uom_qty": 10.0,
"product_uom": cls.product.uom_id.id,
"repair_id": cls.repair.id,
"state": "confirmed",
"location_id": cls.location.id,
"location_dest_id": cls.location.id,
}
)

def test_split_move_with_incomplete_repair(self):
"""Ensure a stock move linked to an incomplete repair cannot be split"""
result = self.stock_move._split(5.0)
self.assertEqual(
result, [], "Move should not split as the repair is not 'done'."
)

def test_split_move_with_completed_repair(self):
"""Ensure a stock move linked to a completed repair can be split"""
self.repair.write({"state": "done"})
result = self.stock_move._split(5.0)
self.assertTrue(result, "Move should split as the repair is 'done'.")

0 comments on commit c5f40d9

Please sign in to comment.