Skip to content

Commit daedbd4

Browse files
[MIG] mrp_component_operation: Migration to 17.0
1 parent e19859c commit daedbd4

File tree

11 files changed

+110
-80
lines changed

11 files changed

+110
-80
lines changed

mrp_component_operation/__manifest__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
{
55
"name": "MRP Components Operations",
6-
"version": "14.0.1.2.0",
6+
"version": "17.0.1.0.0",
77
"author": "ForgeFlow, Odoo Community Association (OCA)",
88
"summary": "Allows to operate the components from a MO",
99
"website": "https://github.com/OCA/manufacture",
1010
"category": "Manufacturing",
11-
"depends": ["mrp", "stock_move_forced_lot"],
11+
"depends": ["mrp", "stock_restrict_lot"],
1212
"data": [
1313
"security/ir.model.access.csv",
1414
"views/mrp_component_operation_views.xml",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
2+
3+
from openupgradelib import openupgrade
4+
5+
6+
@openupgrade.migrate()
7+
def migrate(env, version):
8+
field_spec = [
9+
(
10+
"mrp_component_operation",
11+
"mrp_component_operation",
12+
"source_location_id",
13+
"manufacture_location_id",
14+
),
15+
]
16+
openupgrade.rename_fields(env=env, field_spec=field_spec, no_deep=True)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from . import mrp_component_operation
22
from . import mrp_production
3-
from . import stock_location_route
3+
from . import stock_route

mrp_component_operation/models/mrp_component_operation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ class MrpComponentOperation(models.Model):
1010

1111
name = fields.Char(help="Component Operation Reference", required=True)
1212

13-
source_location_id = fields.Many2one(
13+
manufacture_location_id = fields.Many2one(
1414
"stock.location",
15-
"Source Location",
15+
"Manufacture Location",
1616
help="The Location where the components are.",
1717
)
1818

1919
source_route_id = fields.Many2one(
20-
comodel_name="stock.location.route",
20+
comodel_name="stock.route",
2121
string="Source Route",
2222
help="The Route used to pick the components.",
2323
domain=[("mo_component_selectable", "=", True)],
@@ -30,7 +30,7 @@ class MrpComponentOperation(models.Model):
3030
)
3131

3232
destination_route_id = fields.Many2one(
33-
comodel_name="stock.location.route",
33+
comodel_name="stock.route",
3434
string="Destination Route",
3535
help="The Route used to transfer the components to the destination location.",
3636
domain=[("mo_component_selectable", "=", True)],

mrp_component_operation/models/stock_location_route.py renamed to mrp_component_operation/models/stock_route.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from odoo import fields, models
44

55

6-
class StockLocationRoute(models.Model):
7-
_inherit = "stock.location.route"
6+
class StockRoute(models.Model):
7+
_inherit = "stock.route"
88

99
mo_component_selectable = fields.Boolean(string="Selectable on MO Components")

mrp_component_operation/tests/test_component_operate.py

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
33

44
from odoo import api, fields
5-
from odoo.tests import common
5+
from odoo.tests.common import TransactionCase
66

77

8-
class TestComponentOperation(common.SavepointCase):
8+
class TestComponentOperation(TransactionCase):
99
@classmethod
1010
def setUpClass(cls):
1111
super().setUpClass()
@@ -14,7 +14,6 @@ def setUpClass(cls):
1414
cls.ProcurementGroup = cls.env["procurement.group"]
1515
cls.MrpProduction = cls.env["mrp.production"]
1616
cls.env.user.company_id.manufacturing_lead = 0
17-
cls.env.user.tz = False # Make sure there's no timezone in user
1817

1918
cls.picking_type = cls.env["stock.picking.type"].search(
2019
[
@@ -30,7 +29,6 @@ def setUpClass(cls):
3029
(6, 0, [cls.env.ref("mrp.route_warehouse0_manufacture").id])
3130
],
3231
"type": "product",
33-
"produce_delay": 0,
3432
}
3533
)
3634
cls.product2 = cls.env["product.product"].create(
@@ -43,6 +41,7 @@ def setUpClass(cls):
4341
{
4442
"product_id": cls.product1.id,
4543
"product_tmpl_id": cls.product1.product_tmpl_id.id,
44+
"produce_delay": 0,
4645
"type": "normal",
4746
"bom_line_ids": [
4847
(0, 0, {"product_id": cls.product2.id, "product_qty": 2}),
@@ -56,7 +55,7 @@ def setUpClass(cls):
5655
)
5756
cls.warehouse.manufacture_steps = "pbm"
5857
cls.ressuply_loc1 = cls.warehouse.lot_stock_id
59-
cls.source_location = cls.env.ref("stock.stock_location_stock")
58+
cls.manufacture_location = cls.warehouse.pbm_loc_id
6059
cls.destination_location = cls.env.ref("stock.stock_location_output")
6160
stock_location_locations_virtual = cls.env["stock.location"].create(
6261
{"name": "Virtual Locations", "usage": "view", "posz": 1}
@@ -69,15 +68,15 @@ def setUpClass(cls):
6968
"usage": "inventory",
7069
}
7170
)
72-
cls.source_route = cls.env["stock.location.route"].create(
71+
cls.source_route = cls.env["stock.route"].create(
7372
{
7473
"name": "Source Route",
7574
"mo_component_selectable": True,
7675
"sequence": 10,
7776
}
7877
)
7978

80-
cls.destination_route = cls.env["stock.location.route"].create(
79+
cls.destination_route = cls.env["stock.route"].create(
8180
{
8281
"name": "Destination Route",
8382
"mo_component_selectable": True,
@@ -90,7 +89,7 @@ def setUpClass(cls):
9089
"name": "Transfer",
9190
"route_id": cls.source_route.id,
9291
"location_src_id": cls.ressuply_loc1.id,
93-
"location_id": cls.source_location.id,
92+
"location_dest_id": cls.manufacture_location.id,
9493
"action": "pull",
9594
"picking_type_id": cls.warehouse.int_type_id.id,
9695
"procure_method": "make_to_stock",
@@ -102,8 +101,8 @@ def setUpClass(cls):
102101
{
103102
"name": "Transfer 2",
104103
"route_id": cls.destination_route.id,
105-
"location_src_id": cls.source_location.id,
106-
"location_id": cls.destination_location.id,
104+
"location_src_id": cls.manufacture_location.id,
105+
"location_dest_id": cls.destination_location.id,
107106
"action": "pull",
108107
"picking_type_id": cls.warehouse.int_type_id.id,
109108
"procure_method": "make_to_stock",
@@ -117,7 +116,7 @@ def setUpClass(cls):
117116
"name": "Operation Scrap and Replace",
118117
"incoming_operation": "replace",
119118
"outgoing_operation": "scrap",
120-
"source_location_id": cls.source_location.id,
119+
"manufacture_location_id": cls.manufacture_location.id,
121120
"source_route_id": cls.source_route.id,
122121
"scrap_location_id": cls.scrapped_location.id,
123122
}
@@ -128,7 +127,7 @@ def setUpClass(cls):
128127
"name": "Operation Scrap and Replace",
129128
"incoming_operation": "no",
130129
"outgoing_operation": "no",
131-
"source_location_id": cls.source_location.id,
130+
"manufacture_location_id": cls.manufacture_location.id,
132131
}
133132
)
134133

@@ -137,7 +136,7 @@ def setUpClass(cls):
137136
"name": "Operation Move",
138137
"incoming_operation": "replace",
139138
"outgoing_operation": "move",
140-
"source_location_id": cls.source_location.id,
139+
"manufacture_location_id": cls.manufacture_location.id,
141140
"source_route_id": cls.source_route.id,
142141
"destination_location_id": cls.destination_location.id,
143142
"destination_route_id": cls.destination_route.id,
@@ -149,17 +148,17 @@ def _do_picking(cls, picking):
149148
picking.action_assign()
150149
date = fields.Datetime.now()
151150
picking.action_confirm()
152-
picking.move_lines.quantity_done = picking.move_lines.product_uom_qty
151+
picking.move_ids.picked = True
153152
picking._action_done()
154-
for move in picking.move_lines:
153+
for move in picking.move_ids:
155154
move.date = date
156155

157156
def test_01_scrap_and_replace(self):
158157
nb_product_todo = 5
159158
serials_p2 = []
160159
for i in range(nb_product_todo):
161160
serials_p2.append(
162-
self.env["stock.production.lot"].create(
161+
self.env["stock.lot"].create(
163162
{
164163
"name": f"lot_consumed_2_{i}",
165164
"product_id": self.product3.id,
@@ -180,20 +179,21 @@ def test_01_scrap_and_replace(self):
180179
"product_qty": 2,
181180
"product_uom_id": self.product1.uom_id.id,
182181
"date_deadline": "2023-01-01 15:00:00",
183-
"date_planned_start": "2023-01-01 15:00:00",
182+
"date_start": "2023-01-01 15:00:00",
184183
}
185184
)
186-
mo._onchange_move_raw()
187-
mo._onchange_move_finished()
188185
mo.action_confirm()
186+
picking = mo.move_raw_ids.move_orig_ids.picking_id
187+
picking.move_ids.write({"picked": True})
188+
picking.button_validate()
189189
mo.action_assign()
190190
move_product_2 = mo.move_raw_ids.filtered(
191191
lambda m: m.product_id == self.product2
192192
)
193193
raw_move_product_3 = mo.move_raw_ids.filtered(
194194
lambda m: m.product_id == self.product3
195195
)
196-
self.assertEqual(move_product_2.move_line_ids.product_uom_qty, 4)
196+
self.assertEqual(move_product_2.move_line_ids.quantity_product_uom, 4)
197197
self.assertEqual(len(raw_move_product_3.move_line_ids), 2)
198198
lot = raw_move_product_3.move_line_ids[0].lot_id
199199
wizard = self.env["mrp.component.operate"].create(
@@ -205,29 +205,28 @@ def test_01_scrap_and_replace(self):
205205
}
206206
)
207207
self.assertEqual(wizard.product_qty, 1)
208+
old_pickings = mo.picking_ids
208209
wizard.action_operate_component()
209-
self.assertEqual(len(mo.picking_ids), 1)
210+
new_pickings = mo.picking_ids - old_pickings
210211
self.assertEqual(mo.scrap_ids.product_id, self.product3)
211212
self.assertEqual(mo.scrap_ids.lot_id, lot)
212213
self.assertEqual(mo.scrap_ids.state, "done")
213214
self.assertEqual(len(raw_move_product_3.move_line_ids), 1)
214-
self.assertEqual(len(raw_move_product_3.move_orig_ids.move_line_ids), 0)
215-
self.assertEqual(mo.picking_ids.product_id, self.product3)
216-
self._do_picking(mo.picking_ids)
217-
self.assertEqual(mo.picking_ids.state, "done")
215+
self._do_picking(new_pickings)
216+
self.assertEqual(new_pickings.state, "done")
218217
self.assertEqual(
219218
len(raw_move_product_3.move_line_ids),
220219
2,
221220
"Two lines, the operated one and the other one. (2 units required)",
222221
)
223-
self.assertEqual(len(raw_move_product_3.move_orig_ids.move_line_ids), 1)
222+
self.assertEqual(len(raw_move_product_3.move_orig_ids[-1].move_line_ids), 1)
224223

225224
def test_02_move_and_replace(self):
226225
nb_product_todo = 5
227226
serials_p2 = []
228227
for i in range(nb_product_todo):
229228
serials_p2.append(
230-
self.env["stock.production.lot"].create(
229+
self.env["stock.lot"].create(
231230
{
232231
"name": f"lot_consumed_2_{i}",
233232
"product_id": self.product3.id,
@@ -248,12 +247,13 @@ def test_02_move_and_replace(self):
248247
"product_qty": 1,
249248
"product_uom_id": self.product1.uom_id.id,
250249
"date_deadline": "2023-01-01 15:00:00",
251-
"date_planned_start": "2023-01-01 15:00:00",
250+
"date_start": "2023-01-01 15:00:00",
252251
}
253252
)
254-
mo._onchange_move_raw()
255-
mo._onchange_move_finished()
256253
mo.action_confirm()
254+
picking = mo.move_raw_ids.move_orig_ids.picking_id
255+
picking.move_ids.write({"picked": True})
256+
picking.button_validate()
257257
mo.action_assign()
258258
self.assertEqual(len(mo.move_raw_ids), 2)
259259
move_product_2 = mo.move_raw_ids.filtered(
@@ -262,10 +262,9 @@ def test_02_move_and_replace(self):
262262
raw_move_product_3 = mo.move_raw_ids.filtered(
263263
lambda m: m.product_id == self.product3
264264
)
265-
self.assertEqual(move_product_2.move_line_ids.product_uom_qty, 2)
265+
self.assertEqual(move_product_2.move_line_ids.quantity_product_uom, 2)
266266
self.assertEqual(len(raw_move_product_3.move_line_ids), 1)
267267
lot = raw_move_product_3.move_line_ids[0].lot_id
268-
self.assertFalse(raw_move_product_3.move_orig_ids)
269268
wizard = self.env["mrp.component.operate"].create(
270269
{
271270
"product_id": self.product3.id,
@@ -275,10 +274,12 @@ def test_02_move_and_replace(self):
275274
}
276275
)
277276
self.assertEqual(wizard.product_qty, 1)
278-
self.assertEqual(len(mo.picking_ids), 0)
277+
old_pickings = mo.picking_ids
278+
self.assertEqual(len(old_pickings), 1)
279279
wizard.action_operate_component()
280-
self.assertEqual(len(mo.picking_ids), 2)
281-
moves_for_replacement = mo.mapped("picking_ids.move_lines")
280+
self.assertEqual(len(mo.picking_ids), 3)
281+
new_pickings = mo.picking_ids - old_pickings
282+
moves_for_replacement = new_pickings.mapped("move_ids")
282283
self.assertEqual(len(moves_for_replacement), 2)
283284
for move in moves_for_replacement:
284285
self.assertEqual(
@@ -290,16 +291,15 @@ def test_02_move_and_replace(self):
290291
)
291292
self.assertTrue(replacement_first_move)
292293
replacement_second_move = moves_for_replacement.filtered(
293-
lambda m: m.location_dest_id == self.source_location
294+
lambda m: m.location_dest_id == self.manufacture_location
294295
)
295296
self.assertTrue(replacement_second_move)
296297
self.assertEqual(
297298
len(raw_move_product_3.move_line_ids),
298299
0,
299300
"Reservation for product3 should have been cleared",
300301
)
301-
self.assertEqual(raw_move_product_3.move_orig_ids, replacement_second_move)
302-
self.assertEqual(len(replacement_second_move.move_line_ids), 0)
302+
self.assertEqual(raw_move_product_3.move_orig_ids[-1], replacement_second_move)
303303
self._do_picking(replacement_first_move.picking_id)
304304
self.assertEqual(replacement_first_move.state, "done")
305305
self.assertEqual(replacement_first_move.move_line_ids.lot_id, lot)
@@ -308,7 +308,6 @@ def test_02_move_and_replace(self):
308308
0,
309309
"raw move for product 3 still not reserved.",
310310
)
311-
self.assertEqual(len(replacement_second_move.move_line_ids), 0)
312311
self._do_picking(replacement_second_move.picking_id)
313312
self.assertEqual(replacement_second_move.state, "done")
314313
self.assertEqual(replacement_first_move.product_id, self.product3)
@@ -320,7 +319,7 @@ def test_03_nothing_and_nothing(self):
320319
serials_p2 = []
321320
for i in range(nb_product_todo):
322321
serials_p2.append(
323-
self.env["stock.production.lot"].create(
322+
self.env["stock.lot"].create(
324323
{
325324
"name": f"lot_consumed_2_{i}",
326325
"product_id": self.product3.id,
@@ -341,20 +340,21 @@ def test_03_nothing_and_nothing(self):
341340
"product_qty": 2,
342341
"product_uom_id": self.product1.uom_id.id,
343342
"date_deadline": "2023-01-01 15:00:00",
344-
"date_planned_start": "2023-01-01 15:00:00",
343+
"date_start": "2023-01-01 15:00:00",
345344
}
346345
)
347-
mo._onchange_move_raw()
348-
mo._onchange_move_finished()
349346
mo.action_confirm()
347+
picking = mo.move_raw_ids.move_orig_ids.picking_id
348+
picking.move_ids.write({"picked": True})
349+
picking.button_validate()
350350
mo.action_assign()
351351
move_product_2 = mo.move_raw_ids.filtered(
352352
lambda m: m.product_id == self.product2
353353
)
354354
raw_move_product_3 = mo.move_raw_ids.filtered(
355355
lambda m: m.product_id == self.product3
356356
)
357-
self.assertEqual(move_product_2.move_line_ids.product_uom_qty, 4)
357+
self.assertEqual(move_product_2.move_line_ids.quantity_product_uom, 4)
358358
self.assertEqual(len(raw_move_product_3.move_line_ids), 2)
359359
wizard = self.env["mrp.component.operate"].create(
360360
{
@@ -367,6 +367,5 @@ def test_03_nothing_and_nothing(self):
367367
self.assertEqual(wizard.product_qty, 1)
368368
self.assertEqual(wizard.product_id, self.product3)
369369
wizard.action_operate_component()
370-
self.assertEqual(len(mo.picking_ids), 0)
371-
self.assertEqual(move_product_2.move_line_ids.product_uom_qty, 4)
370+
self.assertEqual(move_product_2.move_line_ids.quantity_product_uom, 4)
372371
self.assertEqual(len(mo.move_raw_ids[1].move_line_ids), 2)

0 commit comments

Comments
 (0)