diff --git a/repair_picking_after_done/README.rst b/repair_picking_after_done/README.rst new file mode 100644 index 000000000..aff9e43bd --- /dev/null +++ b/repair_picking_after_done/README.rst @@ -0,0 +1,91 @@ +========================= +Repair picking after done +========================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |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/14.0/repair_picking_after_done + :alt: OCA/manufacture +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/manufacture-14-0/manufacture-14-0-repair_picking_after_done + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/129/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds the functionality to create transfer of repaired move once repair order is done. + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +No configuration needed for this module. + +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. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* `ForgeFlow `_: + + * Dhaval Talpada + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/repair_picking_after_done/__init__.py b/repair_picking_after_done/__init__.py new file mode 100644 index 000000000..aee8895e7 --- /dev/null +++ b/repair_picking_after_done/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizards diff --git a/repair_picking_after_done/__manifest__.py b/repair_picking_after_done/__manifest__.py new file mode 100644 index 000000000..47ee87e91 --- /dev/null +++ b/repair_picking_after_done/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2021 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Repair picking after done", + "version": "14.0.1.0.1", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/manufacture", + "summary": "Transfer repaired move to another location directly from repaire order", + "category": "Repair", + "depends": ["repair_type"], + "data": [ + "security/ir.model.access.csv", + "views/repair.xml", + "wizards/repair_move_transfer_views.xml", + ], + "installable": True, + "development_status": "Alpha", + "license": "AGPL-3", + "application": False, +} diff --git a/repair_picking_after_done/models/__init__.py b/repair_picking_after_done/models/__init__.py new file mode 100644 index 000000000..3985e5580 --- /dev/null +++ b/repair_picking_after_done/models/__init__.py @@ -0,0 +1 @@ +from . import repair diff --git a/repair_picking_after_done/models/repair.py b/repair_picking_after_done/models/repair.py new file mode 100644 index 000000000..27e054956 --- /dev/null +++ b/repair_picking_after_done/models/repair.py @@ -0,0 +1,54 @@ +# Copyright (C) 2022 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from odoo import _, fields, models + + +class Repair(models.Model): + _inherit = "repair.order" + + picking_ids = fields.Many2many("stock.picking", string="Transfers") + remaining_quantity = fields.Float( + "Remaining quantity to be transferred", compute="_compute_remaining_quantity" + ) + + def _compute_remaining_quantity(self): + for rec in self: + remaining_quantity = rec.product_qty + if rec.picking_ids: + stock_moves = rec.picking_ids.mapped("move_lines").filtered( + lambda x: x.state != "cancel" + ) + remaining_quantity = rec.product_qty - sum( + stock_moves.mapped("product_uom_qty") + ) + rec.remaining_quantity = remaining_quantity + + def action_transfer_done_moves(self): + self.ensure_one() + return { + "name": "Transfer repair moves", + "type": "ir.actions.act_window", + "view_type": "form", + "view_mode": "form", + "res_model": "repair.move.transfer", + "context": { + "default_repair_order_id": self.id, + "default_quantity": self.remaining_quantity, + }, + "target": "new", + } + + def action_open_transfers(self): + self.ensure_one() + domain = [("id", "in", self.picking_ids.ids)] + action = { + "name": _("Transfers"), + "view_type": "tree", + "view_mode": "list,form", + "res_model": "stock.picking", + "type": "ir.actions.act_window", + "context": self.env.context, + "domain": domain, + } + return action diff --git a/repair_picking_after_done/readme/CONFIGURE.rst b/repair_picking_after_done/readme/CONFIGURE.rst new file mode 100644 index 000000000..029bb402b --- /dev/null +++ b/repair_picking_after_done/readme/CONFIGURE.rst @@ -0,0 +1 @@ +No configuration needed for this module. diff --git a/repair_picking_after_done/readme/CONTRIBUTORS.rst b/repair_picking_after_done/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..11ca5ed3a --- /dev/null +++ b/repair_picking_after_done/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `ForgeFlow `_: + + * Dhaval Talpada diff --git a/repair_picking_after_done/readme/DESCRIPTION.rst b/repair_picking_after_done/readme/DESCRIPTION.rst new file mode 100644 index 000000000..954374c3a --- /dev/null +++ b/repair_picking_after_done/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module adds the functionality to create transfer of repaired move once repair order is done. diff --git a/repair_picking_after_done/readme/ROADMAP.rst b/repair_picking_after_done/readme/ROADMAP.rst new file mode 100644 index 000000000..e69de29bb diff --git a/repair_picking_after_done/readme/USAGE.rst b/repair_picking_after_done/readme/USAGE.rst new file mode 100644 index 000000000..1b2a1d9d2 --- /dev/null +++ b/repair_picking_after_done/readme/USAGE.rst @@ -0,0 +1,2 @@ +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. diff --git a/repair_picking_after_done/security/ir.model.access.csv b/repair_picking_after_done/security/ir.model.access.csv new file mode 100644 index 000000000..08fa9b717 --- /dev/null +++ b/repair_picking_after_done/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_repair_move_transfer_all,repair.move.transfer.all,model_repair_move_transfer,,1,1,1,1 diff --git a/repair_picking_after_done/static/description/icon.png b/repair_picking_after_done/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/repair_picking_after_done/static/description/icon.png differ diff --git a/repair_picking_after_done/static/description/index.html b/repair_picking_after_done/static/description/index.html new file mode 100644 index 000000000..95cbbd28a --- /dev/null +++ b/repair_picking_after_done/static/description/index.html @@ -0,0 +1,442 @@ + + + + + + +Repair picking after done + + + +
+

Repair picking after done

+ + +

Alpha License: AGPL-3 OCA/manufacture Translate me on Weblate Try me on Runbot

+

This module adds the functionality to create transfer of repaired move once repair order is done.

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+ +
+

Configuration

+

No configuration needed for this module.

+
+
+

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.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • ForgeFlow
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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 project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/repair_picking_after_done/tests/__init__.py b/repair_picking_after_done/tests/__init__.py new file mode 100644 index 000000000..7d52509a9 --- /dev/null +++ b/repair_picking_after_done/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright (C) 2022 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from . import test_repair_transfers diff --git a/repair_picking_after_done/tests/test_repair_transfers.py b/repair_picking_after_done/tests/test_repair_transfers.py new file mode 100644 index 000000000..f485c08c7 --- /dev/null +++ b/repair_picking_after_done/tests/test_repair_transfers.py @@ -0,0 +1,111 @@ +# Copyright (C) 2022 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from odoo.tests.common import TransactionCase + + +class TestRepairTransfer(TransactionCase): + def setUp(self, *args, **kwargs): + super(TestRepairTransfer, self).setUp(*args, **kwargs) + + # First of all we create a repair to work with + self.repair_r1 = self.env.ref("repair.repair_r1") + self.repair_r2 = self.env.ref("repair.repair_r1") + + # Now we will create a destination location + self.stock_location_destination = self.env["stock.location"].create( + {"name": "Destination Locations", "usage": "internal"} + ) + + # Let's add some stock + self.env["stock.quant"].create( + { + "product_id": self.repair_r1.product_id.id, + "location_id": self.repair_r1.location_id.id, + "quantity": 1.0, + } + ) + + # Create a product with lot/serial tracking + product_with_lot = self.env["product.product"].create( + { + "name": "Product with lot tracking", + "type": "product", + "tracking": "lot", + "list_price": 10.0, + "categ_id": self.env.ref("product.product_category_all").id, + } + ) + lot_id = self.env["stock.production.lot"].create( + { + "name": "LOT0001", + "product_id": product_with_lot.id, + "company_id": self.env.company.id, + } + ) + # Let's add some stock + self.env["stock.quant"].create( + { + "product_id": product_with_lot.id, + "lot_id": lot_id.id, + "location_id": self.repair_r2.location_id.id, + "quantity": 1.0, + } + ) + self.repair_r2.write({"lot_id": lot_id.id, "product_id": product_with_lot.id}) + + def test_repair_transfer_1(self): + + # Validate the repair order + self.repair_r1.action_validate() + self.assertEqual(self.repair_r1.state, "confirmed") + + self.repair_r1.action_assign() + self.assertEqual(self.repair_r1.move_id.state, "assigned") + + self.repair_r1.action_repair_start() + self.assertEqual(self.repair_r1.state, "under_repair") + + self.repair_r1.action_repair_end() + self.assertEqual(self.repair_r1.state, "done") + + transfer_repair_wizard = self.env["repair.move.transfer"].create( + { + "repair_order_id": self.repair_r1.id, + "quantity": 1.0, + "location_dest_id": self.stock_location_destination.id, + } + ) + transfer_repair_wizard.action_create_transfer() + + self.assertEqual(len(self.repair_r1.picking_ids), 1) + + def test_repair_transfer_2(self): + + # Validate the repair order + self.repair_r2.action_validate() + self.assertEqual(self.repair_r2.state, "confirmed") + + self.repair_r2.action_assign() + self.assertEqual(self.repair_r2.move_id.state, "assigned") + + self.repair_r2.action_repair_start() + self.assertEqual(self.repair_r2.state, "under_repair") + + self.repair_r2.action_repair_end() + self.assertEqual(self.repair_r2.state, "done") + + transfer_repair_wizard = self.env["repair.move.transfer"].create( + { + "repair_order_id": self.repair_r2.id, + "quantity": 1.0, + "location_dest_id": self.stock_location_destination.id, + } + ) + transfer_repair_wizard.action_create_transfer() + self.assertEqual(len(self.repair_r2.picking_ids), 1) + + move_line = self.repair_r2.picking_ids.mapped("move_lines").mapped( + "move_line_ids" + )[0] + self.assertEqual(move_line.lot_id.name, "LOT0001") diff --git a/repair_picking_after_done/views/repair.xml b/repair_picking_after_done/views/repair.xml new file mode 100644 index 000000000..7b3fcf412 --- /dev/null +++ b/repair_picking_after_done/views/repair.xml @@ -0,0 +1,33 @@ + + + + repair.type.inherit + repair.order + + +
+
+ + + + + +
+
+
diff --git a/repair_picking_after_done/wizards/__init__.py b/repair_picking_after_done/wizards/__init__.py new file mode 100644 index 000000000..7cf3e0d59 --- /dev/null +++ b/repair_picking_after_done/wizards/__init__.py @@ -0,0 +1 @@ +from . import repair_move_transfer diff --git a/repair_picking_after_done/wizards/repair_move_transfer.py b/repair_picking_after_done/wizards/repair_move_transfer.py new file mode 100644 index 000000000..2a1cd7a93 --- /dev/null +++ b/repair_picking_after_done/wizards/repair_move_transfer.py @@ -0,0 +1,72 @@ +# Copyright 2022 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import _, fields, models +from odoo.exceptions import UserError +from odoo.tools.float_utils import float_compare + + +class MrpInventoryProcure(models.TransientModel): + _name = "repair.move.transfer" + _description = "Create an internal transfer from repaired moves" + + repair_order_id = fields.Many2one( + "repair.order", string="Repair Order", required=True + ) + location_dest_id = fields.Many2one( + "stock.location", string="Destination location", required=True + ) + quantity = fields.Float("Quantity to transfer", required=True) + + def _get_picking_type(self): + self.ensure_one() + warehouse = self.repair_order_id.location_id.get_warehouse() + return warehouse.int_type_id + + def _prepare_picking_vals(self): + return { + "partner_id": False, + "user_id": False, + "picking_type_id": self._get_picking_type().id, + "move_type": "direct", + "location_id": self.repair_order_id.location_id.id, + "location_dest_id": self.location_dest_id.id, + } + + def _prepare_stock_move_vals(self, picking): + self.ensure_one() + return { + "name": self.repair_order_id.product_id.name, + "product_id": self.repair_order_id.product_id.id, + "location_id": self.repair_order_id.location_id.id, + "location_dest_id": self.location_dest_id.id, + "picking_id": picking.id, + "state": "draft", + "company_id": picking.company_id.id, + "picking_type_id": self._get_picking_type().id, + "product_uom_qty": self.quantity, + "product_uom": self.repair_order_id.move_id.product_uom.id, + } + + def action_create_transfer(self): + self.ensure_one() + + if ( + float_compare( + self.quantity, + 0.0, + precision_rounding=self.repair_order_id.product_id.uom_id.rounding, + ) + <= 0 + ): + raise UserError(_("Quantity to transfer must be greater than 0.")) + picking = self.env["stock.picking"].create(self._prepare_picking_vals()) + stock_move = self.env["stock.move"].create( + self._prepare_stock_move_vals(picking) + ) + picking.action_assign() + if self.repair_order_id.lot_id: + stock_move.move_line_ids[0]._assign_production_lot( + self.repair_order_id.lot_id + ) + self.repair_order_id.write({"picking_ids": [(4, picking.id)]}) diff --git a/repair_picking_after_done/wizards/repair_move_transfer_views.xml b/repair_picking_after_done/wizards/repair_move_transfer_views.xml new file mode 100644 index 000000000..c31fd0346 --- /dev/null +++ b/repair_picking_after_done/wizards/repair_move_transfer_views.xml @@ -0,0 +1,25 @@ + + + + Transfer Repaired Moves + repair.move.transfer + +
+ + + + + +
+
+
+
diff --git a/setup/repair_picking_after_done/odoo/addons/repair_picking_after_done b/setup/repair_picking_after_done/odoo/addons/repair_picking_after_done new file mode 120000 index 000000000..8d48aa9c7 --- /dev/null +++ b/setup/repair_picking_after_done/odoo/addons/repair_picking_after_done @@ -0,0 +1 @@ +../../../../repair_picking_after_done \ No newline at end of file diff --git a/setup/repair_picking_after_done/setup.py b/setup/repair_picking_after_done/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/repair_picking_after_done/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)