Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][MIG] repair_picking_after_done: Migration to 17.0 #65

Merged
merged 12 commits into from
Nov 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[IMP] repair_picking_after_done: Allow backorders for stock moves lin…
…ked to completed repair orders
ppyczko committed Nov 26, 2024
commit c5f40d93bc2e6160c0cbda851b30ffc313ec7042
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
@@ -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
@@ -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'.")

Unchanged files with check annotations Beta

rec.remaining_quantity = remaining_quantity
def action_transfer_done_moves(self):
self.ensure_one()
return {

Check warning on line 28 in repair_picking_after_done/models/repair.py

Codecov / codecov/patch

repair_picking_after_done/models/repair.py#L27-L28

Added lines #L27 - L28 were not covered by tests
"name": "Transfer repair moves",
"type": "ir.actions.act_window",
"view_type": "form",