Skip to content

Commit

Permalink
[MIG] repair_picking: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JasminSForgeFlow committed Feb 4, 2025
1 parent dee53f9 commit 25e009b
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 120 deletions.
16 changes: 8 additions & 8 deletions repair_picking/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Repair Picking
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github
:target: https://github.com/OCA/manufacture/tree/17.0/repair_picking
:alt: OCA/manufacture
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frepair-lightgray.png?logo=github
:target: https://github.com/OCA/repair/tree/17.0/repair_picking
:alt: OCA/repair
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/manufacture-17-0/manufacture-17-0-repair_picking
:target: https://translation.odoo-community.org/projects/repair-17-0/repair-17-0-repair_picking
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/manufacture&target_branch=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/repair&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -79,10 +79,10 @@ Usage
Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/manufacture/issues>`_.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/repair/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/manufacture/issues/new?body=module:%20repair_picking%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/repair/issues/new?body=module:%20repair_picking%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -112,6 +112,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/manufacture <https://github.com/OCA/manufacture/tree/17.0/repair_picking>`_ project on GitHub.
This module is part of the `OCA/repair <https://github.com/OCA/repair/tree/17.0/repair_picking>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 0 additions & 1 deletion repair_picking/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from . import models
from . import tests
6 changes: 3 additions & 3 deletions repair_picking/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

{
"name": "Repair Picking",
"version": "14.0.1.0.1",
"version": "17.0.1.0.0",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"category": "Repair",
"website": "https://github.com/OCA/manufacture",
"website": "https://github.com/OCA/repair",
"summary": "Enhanced repair order management with pickings "
"for adding and removing components",
"depends": ["stock_move_forced_lot", "repair_stock_move", "repair_stock"],
"depends": ["stock_restrict_lot", "repair_stock"],
"data": [
"views/stock_warehouse_views.xml",
],
Expand Down
2 changes: 2 additions & 0 deletions repair_picking/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from . import stock_warehouse
from . import repair
from . import stock_rule
from . import procurement_group
from . import stock_move
17 changes: 17 additions & 0 deletions repair_picking/models/procurement_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import api, models


class ProcurementGroup(models.Model):
_inherit = "procurement.group"

@api.model
def _get_rule_domain(self, location, values):
domain = super()._get_rule_domain(location, values)
if values.get("source_repair_location_id"):
domain.append(
("location_src_id", "=", values.get("source_repair_location_id"))
)
return domain
94 changes: 28 additions & 66 deletions repair_picking/models/repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def action_repair_cancel(self):

def _action_launch_stock_rule(self, repair_lines):
for line in repair_lines:
self._run_procurement_repair(line)
self.with_context(should_be_assigned=True)._run_procurement_repair(line)
return True

def _run_procurement_repair(self, line):
Expand All @@ -54,7 +54,7 @@ def _run_procurement_repair(self, line):

@api.model
def _get_procurement_data_repair(self, line):
warehouse = self.location_id.get_warehouse()
warehouse = self.location_id.warehouse_id
if not self.procurement_group_id:
group_id = self.env["procurement.group"].create({"name": self.name})
self.procurement_group_id = group_id
Expand All @@ -69,10 +69,11 @@ def _get_procurement_data_repair(self, line):
"company_id": self.company_id,
"warehouse_id": warehouse,
"repair_line_id": line.id,
"repair_id": line.repair_id.id,
}
if line.lot_id:
procurement_data["lot_id"] = line.lot_id.id
if line.type == "remove":
# if line.lot_id:
# procurement_data["lot_id"] = line.lot_id.id
if line.repair_line_type == "remove":
procurement_data[
"source_repair_location_id"
] = line.repair_id.location_id.id
Expand All @@ -81,10 +82,10 @@ def _get_procurement_data_repair(self, line):
@api.model
def _prepare_procurement_repair(self, line):
values = self._get_procurement_data_repair(line)
warehouse = self.location_id.get_warehouse()
warehouse = self.location_id.warehouse_id
location = (
self.location_id
if line.type == "add"
if line.repair_line_type == "add"
else warehouse.remove_c_type_id.default_location_dest_id
)
procurement = self.env["procurement.group"].Procurement(
Expand All @@ -104,12 +105,8 @@ def _update_stock_moves_and_picking_state(self):
for picking in repair.picking_ids:
if picking.location_dest_id.id == self.location_id.id:
for move_line in picking.move_ids_without_package:
stock_moves = repair.stock_move_ids.filtered(
lambda m: m.product_id.id
== repair.operations.filtered(
lambda l: l.type == "add"
and l.product_id.id == m.product_id.id
).product_id.id
stock_moves = repair.move_ids.filtered(
lambda m: m.repair_line_type == "add"
and m.location_id.id == self.location_id.id
)
if stock_moves:
Expand All @@ -121,12 +118,8 @@ def _update_stock_moves_and_picking_state(self):
)
if picking.location_id.id == self.location_id.id:
for move_line in picking.move_ids_without_package:
stock_moves = repair.stock_move_ids.filtered(
lambda m: m.product_id.id
== repair.operations.filtered(
lambda l: l.type == "remove"
and l.product_id.id == m.product_id.id
).product_id.id
stock_moves = repair.move_ids.filtered(
lambda m: m.repair_line_type == "remove"
and m.location_dest_id.id == self.location_id.id
)
if stock_moves:
Expand All @@ -142,64 +135,33 @@ def _update_stock_moves_and_picking_state(self):
# and then recompute the state of the picking.
picking._compute_state()

def action_repair_confirm(self):
res = super().action_repair_confirm()
def _action_repair_confirm(self):
res = super()._action_repair_confirm()
for repair in self:
warehouse = repair.location_id.get_warehouse()
warehouse = repair.location_id.warehouse_id
if warehouse.repair_steps in ["2_steps", "3_steps"]:
repair._action_launch_stock_rule(
repair.operations.filtered(lambda l: l.type == "add"),
repair.move_ids.filtered(
lambda move: move.repair_line_type == "add"
),
)
if warehouse.repair_steps == "3_steps":
repair._action_launch_stock_rule(
repair.operations.filtered(lambda l: l.type == "remove"),
repair.move_ids.filtered(
lambda move: move.repair_line_type == "remove"
),
)
repair._update_stock_moves_and_picking_state()
return res

@api.onchange("location_id")
def _onchange_location_id(self):
warehouse = self.location_id.get_warehouse()
for line in self.operations:
if line.type == "add":
warehouse = self.location_id.warehouse_id
for line in self.move_ids:
if line.repair_line_type == "add":
line.location_id = self.location_id
elif line.type == "remove" and warehouse.repair_steps == "3_steps":
elif (
line.repair_line_type == "remove"
and warehouse.repair_steps == "3_steps"
):
line.location_dest_id = self.location_id


class RepairLine(models.Model):
_inherit = "repair.line"

@api.onchange("type", "product_id")
def onchange_operation_type(self):
super().onchange_operation_type()
production_location = self.env["stock.location"].search(
[("usage", "=", "production")], limit=1
)
warehouse = self.repair_id.location_id.get_warehouse()
if self.type == "add":
self.write(
{
"location_id": self.repair_id.location_id.id,
"location_dest_id": production_location.id,
}
)
elif self.type == "remove":
self.write({"location_id": production_location.id})
if warehouse.repair_steps in ["1_step", "2_steps"]:
scrap_location = self.env["stock.location"].search(
[
("scrap_location", "=", True),
("company_id", "=", warehouse.company_id.id),
],
limit=1,
)
self.write({"location_dest_id": scrap_location.id})
else:
self.write({"location_dest_id": self.repair_id.location_id.id})

def create(self, vals):
line = super().create(vals)
if line.repair_id.state in ["confirmed", "under_repair", "ready"]:
line.repair_id._action_launch_stock_rule(line)
return line
22 changes: 22 additions & 0 deletions repair_picking/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import api, models


class StockMove(models.Model):
_inherit = "stock.move"

def _should_be_assigned(self):
if self.repair_id and self._context.get("should_be_assigned", False):
return True
return super()._should_be_assigned()

@api.model_create_multi
def create(self, vals_list):
moves = super().create(vals_list)
if not self._context.get("should_be_assigned", False):
for move in moves:
if move.repair_id.state in ["confirmed", "under_repair"]:
move.repair_id._action_launch_stock_rule(move)
return moves
20 changes: 9 additions & 11 deletions repair_picking/models/stock_rule.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import api, models
from odoo import models


class ProcurementGroup(models.Model):
_inherit = "procurement.group"
class StockRule(models.Model):
_inherit = "stock.rule"

@api.model
def _get_rule_domain(self, location, values):
domain = super(ProcurementGroup, self)._get_rule_domain(location, values)
if values.get("source_repair_location_id"):
domain.append(
("location_src_id", "=", values.get("source_repair_location_id"))
)
return domain
def _get_custom_move_fields(self):
move_fields = super()._get_custom_move_fields()
move_fields += [
"repair_id",
]
return move_fields
13 changes: 6 additions & 7 deletions repair_picking/models/stock_warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class StockWarehouse(models.Model):
("2_steps", "Pick component, repair"),
("3_steps", "Pick component, repair, store removed component"),
],
string="Repair Steps",
default="1_step",
)
add_c_type_id = fields.Many2one(
Expand All @@ -22,7 +21,7 @@ class StockWarehouse(models.Model):
remove_c_type_id = fields.Many2one(
"stock.picking.type", string="Remove component from Repair"
)
repair_route_id = fields.Many2one("stock.location.route", string="Repair Route")
repair_route_id = fields.Many2one("stock.route", string="Repair Route")
repair_location_id = fields.Many2one("stock.location", string="Repair Location")

def update_picking_types(self, repair_steps, repair_location_id):
Expand Down Expand Up @@ -60,7 +59,7 @@ def update_repair_routes(self, repair_steps, repair_location_id):
if repair_location_id:
self.repair_route_id.rule_ids.filtered(
lambda r: r.picking_type_id == self.add_c_type_id
).write({"location_id": repair_location_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
).write({"location_src_id": repair_location_id})
Expand All @@ -70,7 +69,7 @@ def update_repair_routes(self, repair_steps, repair_location_id):
).active = False

def write(self, vals):
res = super(StockWarehouse, self).write(vals)
res = super().write(vals)
for warehouse in self:
repair_steps = vals.get("repair_steps")
repair_location_id = vals.get("repair_location_id")
Expand Down Expand Up @@ -128,7 +127,7 @@ def _create_repair_picking_types(self):
def _create_repair_route(self):
for warehouse in self:
if not warehouse.repair_route_id:
route = self.env["stock.location.route"].create(
route = self.env["stock.route"].create(
{
"name": "Repair Route for %s" % warehouse.name,
"warehouse_selectable": True,
Expand All @@ -144,7 +143,7 @@ def _create_repair_route(self):
"picking_type_id": warehouse.add_c_type_id.id,
"route_id": route.id,
"location_src_id": warehouse.lot_stock_id.id,
"location_id": warehouse.repair_location_id.id
"location_dest_id": warehouse.repair_location_id.id
or warehouse.view_location_id.id,
"action": "pull",
"company_id": warehouse.company_id.id,
Expand Down Expand Up @@ -173,7 +172,7 @@ def _create_remove_rule(self):
"route_id": warehouse.repair_route_id.id,
"location_src_id": warehouse.repair_location_id.id
or warehouse.view_location_id.id,
"location_id": warehouse.view_location_id.id,
"location_dest_id": warehouse.view_location_id.id,
"action": "pull",
"company_id": warehouse.company_id.id,
"warehouse_id": warehouse.id,
Expand Down
Loading

0 comments on commit 25e009b

Please sign in to comment.