Skip to content

Commit

Permalink
[IMP] repair_picking_after_done: Implement auto-transfer functionalit…
Browse files Browse the repository at this point in the history
…y for completed repair orders
  • Loading branch information
ppyczko committed Dec 11, 2024
1 parent c5f40d9 commit 70b94cc
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 34 deletions.
37 changes: 31 additions & 6 deletions repair_picking_after_done/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,15 @@ Repair picking after done

|badge1| |badge2| |badge3| |badge4| |badge5|

This module adds the functionality to create transfer of repaired move
once repair order is done.
This module enhances Odoo's repair process by introducing automatic
stock transfers for repaired products.

- **Automatic Transfer:** When a repair order is marked as done, a
stock transfer for the remaining repaired products is automatically
created and validated if the **auto_transfer_repair** parameter is
enabled.
- **Manual Transfer:** Users can manually create stock transfers when
automatic transfer is disabled.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Expand All @@ -44,14 +51,32 @@ once repair order is done.
Configuration
=============

No configuration needed for this module.
To enable automatic transfers for repaired products when a repair order
is completed:

- Navigate to Repairs → Configuration → Settings.
- Enable the **Automatic Transfer on Repair Completion** setting.

When enabled, internal transfers for repaired products are automatically
created and validated upon completing the repair order.

Usage
=====

After repair order is done, You will be able to see button "Transfer" on
repair order's form view. You will be able to create internal transfer
between repair location to any destination location.
**Manual Transfers**

1. After a repair order is marked as **Done**, a **Create Transfer**
button will appear on the repair order's form view.
2. Click the Create Transfer button to create an internal transfer for
the repaired products.
3. Specify the destination location and quantity to complete the
transfer.

**Automatic Transfers**

1. If the **auto_transfer_repair** configuration parameter is enabled,
an internal transfer is automatically created and validated when the
repair order is marked as **Done**.

Known issues / Roadmap
======================
Expand Down
8 changes: 7 additions & 1 deletion repair_picking_after_done/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@
"website": "https://github.com/OCA/repair",
"summary": "Transfer repaired move to another location directly from repair order",
"category": "Repair",
"depends": ["repair_type", "repair_stock"],
"depends": [
"base_repair_config",
"repair_type",
"repair_stock",
"repair_type_product_destination",
],
"data": [
"security/ir.model.access.csv",
"views/repair.xml",
"views/res_config_settings_views.xml",
"wizards/repair_move_transfer_views.xml",
],
"installable": True,
Expand Down
1 change: 1 addition & 0 deletions repair_picking_after_done/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import repair
from . import res_config_settings
41 changes: 40 additions & 1 deletion repair_picking_after_done/models/repair.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright (C) 2022 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)

from odoo import fields, models
from odoo import _, fields, models
from odoo.exceptions import ValidationError


class Repair(models.Model):
Expand Down Expand Up @@ -38,3 +39,41 @@ def action_transfer_done_moves(self):
},
"target": "new",
}

def _get_auto_transfer_value(self):
return (
self.env["ir.config_parameter"]
.sudo()
.get_param("repair.auto_transfer_repair", default=False)
)

def action_validate(self):
auto_transfer = self._get_auto_transfer_value()

if auto_transfer and not self.product_id:
raise ValidationError(

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

View check run for this annotation

Codecov / codecov/patch

repair_picking_after_done/models/repair.py#L54

Added line #L54 was not covered by tests
_(
"Automatic transfer cannot be completed because no product is specified for this repair order. "
"Please ensure that a product is assigned to the repair order before proceeding with the transfer."
)
)

return super().action_validate()

def action_repair_done(self):
super().action_repair_done()

auto_transfer = self._get_auto_transfer_value()
if auto_transfer:
for repair in self:
if repair.remaining_quantity > 0:
transfer_wizard = self.env["repair.move.transfer"].create(
{
"repair_order_id": repair.id,
"location_dest_id": repair.product_location_dest_id.id,
"quantity": repair.remaining_quantity,
}
)
transfer_wizard.action_create_transfer()
repair.picking_ids.button_validate()
return True
15 changes: 15 additions & 0 deletions repair_picking_after_done/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2024 Patryk Pyczko (APSL-Nagarro)<ppyczko@apsl.net>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

auto_transfer_repair = fields.Boolean(
"Automatic Transfer on Repair Completion",
config_parameter="repair.auto_transfer_repair",
help="Automatically create and validate transfers for "
"repair orders upon completion.",
)
7 changes: 6 additions & 1 deletion repair_picking_after_done/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
No configuration needed for this module.
To enable automatic transfers for repaired products when a repair order is completed:

- Navigate to Repairs → Configuration → Settings.
- Enable the **Automatic Transfer on Repair Completion** setting.

When enabled, internal transfers for repaired products are automatically created and validated upon completing the repair order.
6 changes: 4 additions & 2 deletions repair_picking_after_done/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
This module adds the functionality to create transfer of repaired move
once repair order is done.
This module enhances Odoo's repair process by introducing automatic stock transfers for repaired products.

- **Automatic Transfer:** When a repair order is marked as done, a stock transfer for the remaining repaired products is automatically created and validated if the ***auto_transfer_repair*** parameter is enabled.
- **Manual Transfer:** Users can manually create stock transfers when automatic transfer is disabled.
12 changes: 9 additions & 3 deletions repair_picking_after_done/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
After repair order is done, You will be able to see button "Transfer" on
repair order's form view. You will be able to create internal transfer
between repair location to any destination location.
**Manual Transfers**

1. After a repair order is marked as **Done**, a **Create Transfer** button will appear on the repair order's form view.
2. Click the Create Transfer button to create an internal transfer for the repaired products.
3. Specify the destination location and quantity to complete the transfer.

**Automatic Transfers**

1. If the ***auto_transfer_repair*** configuration parameter is enabled, an internal transfer is automatically created and validated when the repair order is marked as **Done**.
39 changes: 33 additions & 6 deletions repair_picking_after_done/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,16 @@ <h1 class="title">Repair picking after done</h1>
!! source digest: sha256:f11fa65acd2414cbbab2c2c100e3d976b2147ad613787ffc494bc85e0242b0bd
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/repair/tree/17.0/repair_picking_after_done"><img alt="OCA/repair" src="https://img.shields.io/badge/github-OCA%2Frepair-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/repair-17-0/repair-17-0-repair_picking_after_done"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/repair&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module adds the functionality to create transfer of repaired move
once repair order is done.</p>
<p>This module enhances Odoo’s repair process by introducing automatic
stock transfers for repaired products.</p>
<ul class="simple">
<li><strong>Automatic Transfer:</strong> When a repair order is marked as done, a
stock transfer for the remaining repaired products is automatically
created and validated if the <strong>auto_transfer_repair</strong> parameter is
enabled.</li>
<li><strong>Manual Transfer:</strong> Users can manually create stock transfers when
automatic transfer is disabled.</li>
</ul>
<div class="admonition important">
<p class="first admonition-title">Important</p>
<p class="last">This is an alpha version, the data model and design can change at any time without warning.
Expand All @@ -395,13 +403,32 @@ <h1 class="title">Repair picking after done</h1>
</div>
<div class="section" id="configuration">
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p>No configuration needed for this module.</p>
<p>To enable automatic transfers for repaired products when a repair order
is completed:</p>
<ul class="simple">
<li>Navigate to Repairs → Configuration → Settings.</li>
<li>Enable the <strong>Automatic Transfer on Repair Completion</strong> setting.</li>
</ul>
<p>When enabled, internal transfers for repaired products are automatically
created and validated upon completing the repair order.</p>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<p>After repair order is done, You will be able to see button “Transfer” on
repair order’s form view. You will be able to create internal transfer
between repair location to any destination location.</p>
<p><strong>Manual Transfers</strong></p>
<ol class="arabic simple">
<li>After a repair order is marked as <strong>Done</strong>, a <strong>Create Transfer</strong>
button will appear on the repair order’s form view.</li>
<li>Click the Create Transfer button to create an internal transfer for
the repaired products.</li>
<li>Specify the destination location and quantity to complete the
transfer.</li>
</ol>
<p><strong>Automatic Transfers</strong></p>
<ol class="arabic simple">
<li>If the <strong>auto_transfer_repair</strong> configuration parameter is enabled,
an internal transfer is automatically created and validated when the
repair order is marked as <strong>Done</strong>.</li>
</ol>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#toc-entry-3">Known issues / Roadmap</a></h1>
Expand Down
28 changes: 15 additions & 13 deletions repair_picking_after_done/tests/test_repair_transfers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def setUpClass(cls):
}
)

# Set the repair auto-transfer configuration to disabled (manual transfers)
cls.env["ir.config_parameter"].set_param("repair.auto_transfer_repair", False)

def setUpRepairOrder(self, repair_order):
# Validate and set the state of the repair order
repair_order.action_validate()
Expand All @@ -82,22 +85,14 @@ def createTransfer(self, repair_order, quantity):
)
transfer_repair_wizard.action_create_transfer()

def test_repair_transfer_1(self):
def test_repair_transfer_manual_1(self):
"""Test creating a single manual transfer."""
self.setUpRepairOrder(self.repair_r1)
self.createTransfer(self.repair_r1, 1.0)
self.assertEqual(len(self.repair_r1.picking_ids), 1)

def test_repair_transfer_2(self):
self.setUpRepairOrder(self.repair_r2)
self.createTransfer(self.repair_r2, 1.0)
self.assertEqual(len(self.repair_r2.picking_ids), 1)

move_line = self.repair_r2.picking_ids.mapped("move_ids").mapped(
"move_line_ids"
)[0]
self.assertEqual(move_line.lot_id.name, "LOT0001")

def test_multiple_transfers(self):
def test_repair_transfer_manual_multiple(self):
"""Test multiple manual transfers for the repair order."""
self.setUpRepairOrder(self.repair_r1)

# Attempt to create a transfer for 0 items.
Expand All @@ -106,7 +101,7 @@ def test_multiple_transfers(self):
):
self.createTransfer(self.repair_r1, 0.0)

# Create the first transfer for 1 item
# Create the first manual transfer for 1 item
self.createTransfer(self.repair_r1, 1.0)

# Update remaining quantity after first transfer
Expand Down Expand Up @@ -139,3 +134,10 @@ def test_multiple_transfers(self):
self.assertEqual(
total_transferred, 3.0, "Total transferred quantity should equal to 3.0"
)

def test_repair_transfer_automatic(self):
"""Test automatic transfer creation upon repair order completion."""
self.env["ir.config_parameter"].set_param("repair.auto_transfer_repair", True)
self.setUpRepairOrder(self.repair_r2)
self.assertEqual(len(self.repair_r2.picking_ids), 1)
self.assertEqual(self.repair_r2.picking_ids.state, "done")
2 changes: 1 addition & 1 deletion repair_picking_after_done/views/repair.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
name="action_transfer_done_moves"
string="Create Transfer"
type="object"
invisible="state != 'done' or remaining_quantity == 0"
invisible="state != 'done' or remaining_quantity == 0 or not product_id"
/>
</header>
</field>
Expand Down
20 changes: 20 additions & 0 deletions repair_picking_after_done/views/res_config_settings_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="res_config_settings_view_form_inherit" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit.repair</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="base_repair_config.res_config_settings_view_form" />
<field name="arch" type="xml">
<xpath expr="//block[@name='repair_setting_container']" position="inside">
<setting
id="auto_transfer_repair_setting"
help="Automatically create and validate stock transfers for completed repair orders."
>
<field name="auto_transfer_repair" />
</setting>
</xpath>
</field>
</record>

</odoo>

0 comments on commit 70b94cc

Please sign in to comment.