Skip to content

Commit 814fec8

Browse files
LoisRForgeFlowBhaveshHeliconia
authored andcommitted
[IMP] repair_stock: use a non conflicting field for auxiliar transfers
`repair_id` is reserved to the stock.moves directly related to the execution of the repair order and has associated logic in odoo core code (like assigning the picking type) To avoid unexpected behaviors, we use `related_repair_id` to signal auxiliar stock moves that are not directly related to repair execution. To not break existing modules depending on it, support for `repair_id` is kept but it is recommended to remove in v18.
1 parent 850e290 commit 814fec8

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

repair_stock/models/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com)
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
33
from . import repair
4+
from . import stock_move
5+
from . import stock_rule

repair_stock/models/repair.py

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ def action_view_pickings(self):
2727

2828
def _compute_picking_ids(self):
2929
for order in self:
30+
# TODO: migration note: `repair_id` should not be used here
31+
# in v18, use `related_repair_id` instead while migrating
32+
# modules depending on this.
3033
moves = self.env["stock.move"].search(
3134
[
3235
("related_repair_id", "=", order.id),

repair_stock/models/stock_move.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
3+
4+
from odoo import fields, models
5+
6+
7+
class StockMove(models.Model):
8+
_inherit = "stock.move"
9+
10+
# `repair_id` is reserved to the stock.moves directly related
11+
# to the execution of the repair order and has associated logic
12+
# in odoo core code (like assigning the picking type)
13+
# To avoid unexpected behaviors, we use `related_repair_id` to
14+
# signal auxiliar stock moves that are not directly related to
15+
# repair execution.
16+
related_repair_id = fields.Many2one(
17+
comodel_name="repair.order",
18+
readonly=True,
19+
)

repair_stock/models/stock_rule.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com)
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
3+
4+
from odoo import models
5+
6+
7+
class StockRule(models.Model):
8+
_inherit = "stock.rule"
9+
10+
def _get_custom_move_fields(self):
11+
move_fields = super()._get_custom_move_fields()
12+
move_fields += [
13+
"related_repair_id",
14+
]
15+
return move_fields

repair_stock/tests/test_stock_repair_order.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def _create_picking_and_move(self, repair_order):
102102
"picking_type_id": self.warehouse.int_type_id.id,
103103
"product_uom_qty": 1,
104104
"product_uom": repair_order.product_id.uom_id.id,
105-
"repair_id": repair_order.id,
105+
"related_repair_id": repair_order.id,
106106
}
107107
)
108108
return picking
@@ -123,6 +123,7 @@ def test_action_view_pickings(self):
123123
repair_order._action_repair_confirm()
124124

125125
picking = self._create_picking_and_move(repair_order)
126+
self.assertEqual(picking.picking_type_id, self.warehouse.int_type_id)
126127
repair_order._compute_picking_ids()
127128

128129
action = repair_order.action_view_pickings()

0 commit comments

Comments
 (0)