Skip to content

Commit

Permalink
fixup! [FIX] repair_picking: fix migration
Browse files Browse the repository at this point in the history
  • Loading branch information
LoisRForgeFlow committed Feb 17, 2025
1 parent da71de2 commit f921a9d
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 34 deletions.
4 changes: 2 additions & 2 deletions repair_picking/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The main features are:

- Customize repair steps: Choose between a 1-step, 2-step, or 3-step
repair process.
- Add and remove components during the repair process using separate
- Add and recycle components during the repair process using separate
picking types.
- Associate repair orders with pickings for improved traceability.
- Automatic creation of pickings and procurement routes based on the
Expand All @@ -60,7 +60,7 @@ Configuration
component, repair", or "Pick component, repair, store removed
component" to define the repair process.
3. Define the "Repair Location", "Add Component to Repair" picking type,
"Remove component from Repair" picking type, and "Repair Route" as
"Recycle component from Repair" picking type, and "Repair Route" as
needed.

Usage
Expand Down
25 changes: 25 additions & 0 deletions repair_picking/migrations/17.0.1.0.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (C) 2025 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)

from openupgradelib import openupgrade # pylint: disable=W7936

_field_renames = [
("stock.warehouse", "stock_warehouse", "remove_c_type_id", "recycle_c_type_id"),
]


@openupgrade.migrate()
def migrate(env, version):
cr = env.cr
# Rename operation types
for wh in env["stock.warehouse"].search([]):
if hasattr(wh, "remove_c_type_id") and wh.remove_c_type_id:
wh.recycle_c_type_id.name = wh.recycle_c_type_id.name.replace(
"Remove", "Recycle"
)
# Rename fields
for field in _field_renames:
if openupgrade.table_exists(cr, field[1]) and openupgrade.column_exists(
cr, field[1], field[2]
):
openupgrade.rename_fields(env, _field_renames)
2 changes: 1 addition & 1 deletion repair_picking/models/repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _prepare_procurement_repair(self, line):
location = (
self.location_id
if line.repair_line_type == "add"
else warehouse.remove_c_type_id.default_location_dest_id
else warehouse.recycle_c_type_id.default_location_dest_id
)
procurement = self.env["procurement.group"].Procurement(
line.product_id,
Expand Down
38 changes: 23 additions & 15 deletions repair_picking/models/stock_warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ class StockWarehouse(models.Model):
default="1_step",
)
add_c_type_id = fields.Many2one(
"stock.picking.type", string="Add Component to Repair"
comodel_name="stock.picking.type",
string="Add Component to Repair",
help="This operation will be used to move components to repair location "
"when needed by repair lines of type 'Add'.",
)
remove_c_type_id = fields.Many2one(
"stock.picking.type", string="Remove component from Repair"
recycle_c_type_id = fields.Many2one(
comodel_name="stock.picking.type",
string="Recycle component from Repair",
help="This operation will be used to move components out of the repair "
"location when needed by repair lines of type 'Recycle'.",
)
repair_route_id = fields.Many2one("stock.route", string="Repair Route")
repair_location_id = fields.Many2one("stock.location", string="Repair Location")
Expand All @@ -30,12 +36,14 @@ def update_picking_types(self, repair_steps, repair_location_id):
if repair_steps == "1_step":
self.add_c_type_id.active = False
if repair_steps == "3_steps":
self.remove_c_type_id.active = True
self.recycle_c_type_id.active = True
if repair_steps in ["1_step", "2_steps"]:
self.remove_c_type_id.active = False
self.recycle_c_type_id.active = False
if repair_location_id:
self.add_c_type_id.write({"default_location_dest_id": repair_location_id})
self.remove_c_type_id.write({"default_location_src_id": repair_location_id})
self.recycle_c_type_id.write(
{"default_location_src_id": repair_location_id}
)
rep_type_vals = {
"default_recycle_location_dest_id": repair_location_id,
}
Expand Down Expand Up @@ -72,11 +80,11 @@ def update_repair_routes(self, repair_steps, repair_location_id):
lambda r: r.picking_type_id == self.add_c_type_id
).write({"location_dest_id": repair_location_id})
self.repair_route_id.rule_ids.filtered(
lambda r: r.picking_type_id == self.remove_c_type_id
lambda r: r.picking_type_id == self.recycle_c_type_id
).write({"location_src_id": repair_location_id})
if repair_steps in ["1_step", "2_steps"]:
self.repair_route_id.rule_ids.filtered(
lambda r: r.picking_type_id == self.remove_c_type_id
lambda r: r.picking_type_id == self.recycle_c_type_id
).active = False

def write(self, vals):
Expand Down Expand Up @@ -117,10 +125,10 @@ def _create_repair_picking_types(self):
warehouse.add_c_type_id.write(
{"default_location_dest_id": repair_location_id}
)
if not warehouse.remove_c_type_id:
if not warehouse.recycle_c_type_id:
par_type = self.env["stock.picking.type"].create(
{
"name": "Remove component from Repair",
"name": "Recycle component from Repair",
"code": "internal",
"sequence_code": "RCR",
"warehouse_id": warehouse.id,
Expand All @@ -129,9 +137,9 @@ def _create_repair_picking_types(self):
"company_id": warehouse.company_id.id,
}
)
warehouse.remove_c_type_id = par_type.id
warehouse.recycle_c_type_id = par_type.id
else:
warehouse.remove_c_type_id.write(
warehouse.recycle_c_type_id.write(
{"default_location_src_id": repair_location_id}
)

Expand Down Expand Up @@ -169,7 +177,7 @@ def _create_remove_rule(self):
.with_context(active_test=False)
.search(
[
("picking_type_id", "=", warehouse.remove_c_type_id.id),
("picking_type_id", "=", warehouse.recycle_c_type_id.id),
("route_id", "=", warehouse.repair_route_id.id),
],
limit=1,
Expand All @@ -178,8 +186,8 @@ def _create_remove_rule(self):
if not existing_rule:
self.env["stock.rule"].create(
{
"name": "Remove component from Repair",
"picking_type_id": warehouse.remove_c_type_id.id,
"name": "Recycle component from Repair",
"picking_type_id": warehouse.recycle_c_type_id.id,
"route_id": warehouse.repair_route_id.id,
"location_src_id": warehouse.repair_location_id.id
or warehouse.view_location_id.id,
Expand Down
2 changes: 1 addition & 1 deletion repair_picking/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
component, repair", or "Pick component, repair, store removed
component" to define the repair process.
3. Define the "Repair Location", "Add Component to Repair" picking
type, "Remove component from Repair" picking type, and "Repair
type, "Recycle component from Repair" picking type, and "Repair
Route" as needed.
2 changes: 1 addition & 1 deletion repair_picking/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The main features are:

- Customize repair steps: Choose between a 1-step, 2-step, or 3-step
repair process.
- Add and remove components during the repair process using separate
- Add and recycle components during the repair process using separate
picking types.
- Associate repair orders with pickings for improved traceability.
- Automatic creation of pickings and procurement routes based on the
Expand Down
4 changes: 2 additions & 2 deletions repair_picking/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ <h1 class="title">Repair Picking</h1>
<ul class="simple">
<li>Customize repair steps: Choose between a 1-step, 2-step, or 3-step
repair process.</li>
<li>Add and remove components during the repair process using separate
<li>Add and recycle components during the repair process using separate
picking types.</li>
<li>Associate repair orders with pickings for improved traceability.</li>
<li>Automatic creation of pickings and procurement routes based on the
Expand Down Expand Up @@ -409,7 +409,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
component, repair”, or “Pick component, repair, store removed
component” to define the repair process.</li>
<li>Define the “Repair Location”, “Add Component to Repair” picking type,
Remove component from Repair” picking type, and “Repair Route” as
Recycle component from Repair” picking type, and “Repair Route” as
needed.</li>
</ol>
</div>
Expand Down
4 changes: 2 additions & 2 deletions repair_picking/tests/test_stock_repair_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test_3steps_repair_order_flow(self):
self.assertEqual(pick.state, "assigned")
self.assertEqual(pick.move_ids.move_dest_ids.repair_id, repair_order)
recycle = pickings.filtered(
lambda p: p.picking_type_id == self.warehouse.remove_c_type_id
lambda p: p.picking_type_id == self.warehouse.recycle_c_type_id
)
self.assertTrue(recycle)
self.assertEqual(len(recycle.move_ids.move_orig_ids), 1)
Expand Down Expand Up @@ -247,7 +247,7 @@ def test_update_related_pickings(self):
)
self.repair_line_model.create(
{
"name": "Repair Line Remove",
"name": "Repair Line Recycle",
"repair_id": repair_order.id,
"product_id": self.product2.id,
"repair_line_type": "recycle",
Expand Down
18 changes: 9 additions & 9 deletions repair_picking/tests/test_stock_repair_warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@ def test_02_update_repair_steps(self):

self.assertEqual(self.warehouse_1.repair_steps, "2_steps")
self.assertTrue(self.warehouse_1.add_c_type_id.active)
self.assertFalse(self.warehouse_1.remove_c_type_id.active)
self.assertFalse(self.warehouse_1.recycle_c_type_id.active)
self.assertTrue(self.warehouse_1.repair_route_id.active)

def test_03_update_repair_steps_to_3_steps(self):
self.warehouse_1.repair_steps = "3_steps"

self.assertEqual(self.warehouse_1.repair_steps, "3_steps")
self.assertTrue(self.warehouse_1.add_c_type_id.active)
self.assertTrue(self.warehouse_1.remove_c_type_id.active)
self.assertTrue(self.warehouse_1.recycle_c_type_id.active)
self.assertTrue(self.warehouse_1.repair_route_id.active)

def test_04_reverse_and_update_repair_steps(self):
self.warehouse_1.repair_steps = "1_step"
self.warehouse_1.repair_steps = "2_steps"
self.assertEqual(self.warehouse_1.repair_steps, "2_steps")
self.assertTrue(self.warehouse_1.add_c_type_id.active)
self.assertFalse(self.warehouse_1.remove_c_type_id.active)
self.assertFalse(self.warehouse_1.recycle_c_type_id.active)
self.assertTrue(self.warehouse_1.repair_route_id.active)
add_rule = self.env["stock.rule"].search(
[
Expand All @@ -63,7 +63,7 @@ def test_04_reverse_and_update_repair_steps(self):

remove_rule = self.env["stock.rule"].search(
[
("picking_type_id", "=", self.warehouse_1.remove_c_type_id.id),
("picking_type_id", "=", self.warehouse_1.recycle_c_type_id.id),
("route_id", "=", self.warehouse_1.repair_route_id.id),
]
)
Expand All @@ -72,7 +72,7 @@ def test_04_reverse_and_update_repair_steps(self):
self.warehouse_1.repair_steps = "3_steps"
self.assertEqual(self.warehouse_1.repair_steps, "3_steps")
self.assertTrue(self.warehouse_1.add_c_type_id.active)
self.assertTrue(self.warehouse_1.remove_c_type_id.active)
self.assertTrue(self.warehouse_1.recycle_c_type_id.active)
self.assertTrue(self.warehouse_1.repair_route_id.active)
add_rule = self.env["stock.rule"].search(
[
Expand All @@ -83,7 +83,7 @@ def test_04_reverse_and_update_repair_steps(self):
self.assertTrue(add_rule.active)
remove_rule = self.env["stock.rule"].search(
[
("picking_type_id", "=", self.warehouse_1.remove_c_type_id.id),
("picking_type_id", "=", self.warehouse_1.recycle_c_type_id.id),
("route_id", "=", self.warehouse_1.repair_route_id.id),
]
)
Expand All @@ -92,7 +92,7 @@ def test_04_reverse_and_update_repair_steps(self):
self.warehouse_1.repair_steps = "2_steps"
self.assertEqual(self.warehouse_1.repair_steps, "2_steps")
self.assertTrue(self.warehouse_1.add_c_type_id.active)
self.assertFalse(self.warehouse_1.remove_c_type_id.active)
self.assertFalse(self.warehouse_1.recycle_c_type_id.active)
self.assertTrue(self.warehouse_1.repair_route_id.active)
add_rule = self.env["stock.rule"].search(
[
Expand All @@ -104,13 +104,13 @@ def test_04_reverse_and_update_repair_steps(self):

remove_rule = self.env["stock.rule"].search(
[
("picking_type_id", "=", self.warehouse_1.remove_c_type_id.id),
("picking_type_id", "=", self.warehouse_1.recycle_c_type_id.id),
("route_id", "=", self.warehouse_1.repair_route_id.id),
]
)
self.assertFalse(remove_rule)

self.warehouse_1.repair_steps = "1_step"
self.assertFalse(self.warehouse_1.add_c_type_id.active)
self.assertFalse(self.warehouse_1.remove_c_type_id.active)
self.assertFalse(self.warehouse_1.recycle_c_type_id.active)
self.assertFalse(self.warehouse_1.repair_route_id.active)
2 changes: 1 addition & 1 deletion repair_picking/views/stock_warehouse_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
readonly="1"
/>
<field
name="remove_c_type_id"
name="recycle_c_type_id"
invisible="repair_steps != '3_steps'"
readonly="1"
/>
Expand Down

0 comments on commit f921a9d

Please sign in to comment.