-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] repair_picking_after_done: Allow backorders for stock moves lin…
…ked to completed repair orders
- Loading branch information
Showing
5 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,5 @@ | |
"development_status": "Alpha", | ||
"license": "AGPL-3", | ||
"application": False, | ||
"post_load": "post_load_hook", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'.") |