diff --git a/mrp_unbuild_restore_origin/README.rst b/mrp_unbuild_restore_origin/README.rst new file mode 100644 index 00000000000..a023720a523 --- /dev/null +++ b/mrp_unbuild_restore_origin/README.rst @@ -0,0 +1,108 @@ +========================== +Mrp Unbuild Restore Origin +========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:25f5082feb1040b2404f6d5d61e8b6447cd261444c6d8d11c2b49e9b2e609a7a + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |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/18.0/mrp_unbuild_restore_origin + :alt: OCA/manufacture +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/manufacture-18-0/manufacture-18-0-mrp_unbuild_restore_origin + :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=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +| This module enhances the unbuild process of Manufacturing Orders by + retaining +| information from the original move lines. + +- **Location Retention (Optional):** A boolean field is available to + retain the original + source and destination locations of the move lines during the unbuild + process, if needed. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +| If you want the components to be returned to the same locations they + were originally +| consumed from, enable the checkbox labeled **"Restore Components to + Original Location"** +| when creating the Unbuild Order. If this option is not enabled, Odoo + will follow its standard behavior. + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Quartile + +Contributors +------------ + +- `Quartile `__: + + - Aung Ko Ko Lin + - Yoshi Tashiro + - Toshikimi Shigenobu + +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. + +.. |maintainer-yostashiro| image:: https://github.com/yostashiro.png?size=40px + :target: https://github.com/yostashiro + :alt: yostashiro +.. |maintainer-aungkokolin1997| image:: https://github.com/aungkokolin1997.png?size=40px + :target: https://github.com/aungkokolin1997 + :alt: aungkokolin1997 + +Current `maintainers `__: + +|maintainer-yostashiro| |maintainer-aungkokolin1997| + +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/mrp_unbuild_restore_origin/__init__.py b/mrp_unbuild_restore_origin/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/mrp_unbuild_restore_origin/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mrp_unbuild_restore_origin/__manifest__.py b/mrp_unbuild_restore_origin/__manifest__.py new file mode 100644 index 00000000000..b048d5dafec --- /dev/null +++ b/mrp_unbuild_restore_origin/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Mrp Unbuild Restore Origin", + "version": "18.0.1.0.0", + "author": "Quartile, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/manufacture", + "category": "Stock", + "license": "AGPL-3", + "depends": ["mrp"], + "data": ["views/mrp_unbuild_views.xml"], + "maintainers": ["yostashiro", "aungkokolin1997"], + "installable": True, +} diff --git a/mrp_unbuild_restore_origin/i18n/it.po b/mrp_unbuild_restore_origin/i18n/it.po new file mode 100644 index 00000000000..41056d92e49 --- /dev/null +++ b/mrp_unbuild_restore_origin/i18n/it.po @@ -0,0 +1,52 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_unbuild_restore_origin +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2025-06-04 08:14+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.10.4\n" + +#. module: mrp_unbuild_restore_origin +#: model:ir.model.fields,help:mrp_unbuild_restore_origin.field_mrp_unbuild__restore_rm_stock_in_origin_loc +msgid "" +"If selected, components will be returned to the same location they were " +"taken from during manufacturing." +msgstr "" +"Se selezionata, i componenti verranno restituiti nella stessa ubicazione da " +"cui sono stati prelevati durante la produzione." + +#. module: mrp_unbuild_restore_origin +#: model:ir.model.fields,field_description:mrp_unbuild_restore_origin.field_mrp_unbuild__restore_rm_stock_in_origin_loc +msgid "Return Components to Original Location" +msgstr "Reso componenti nell'ubicazione di origine" + +#. module: mrp_unbuild_restore_origin +#: model:ir.model,name:mrp_unbuild_restore_origin.model_stock_move +msgid "Stock Move" +msgstr "Movimento di magazzino" + +#. module: mrp_unbuild_restore_origin +#: model:ir.model,name:mrp_unbuild_restore_origin.model_mrp_unbuild +msgid "Unbuild Order" +msgstr "Ordine di smontaggio" + +#~ msgid "" +#~ "If enabled, the source location of the component stock move lines will be " +#~ "used as the destination location for the unbuild move lines." +#~ msgstr "" +#~ "Se abilitata, l'ubicazione origine delle righe movimento di magazzino del " +#~ "componente verrà usata come ubicazione destinazione per le righe di " +#~ "movimento non completate." + +#~ msgid "Restore Raw Materials to Consumed Location" +#~ msgstr "Ripristina materiali grezzi nella ubicazioni utilizzate" diff --git a/mrp_unbuild_restore_origin/i18n/mrp_unbuild_restore_origin.pot b/mrp_unbuild_restore_origin/i18n/mrp_unbuild_restore_origin.pot new file mode 100644 index 00000000000..47ab9d03417 --- /dev/null +++ b/mrp_unbuild_restore_origin/i18n/mrp_unbuild_restore_origin.pot @@ -0,0 +1,36 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_unbuild_restore_origin +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mrp_unbuild_restore_origin +#: model:ir.model.fields,help:mrp_unbuild_restore_origin.field_mrp_unbuild__restore_rm_stock_in_origin_loc +msgid "" +"If selected, components will be returned to the same location they were " +"taken from during manufacturing." +msgstr "" + +#. module: mrp_unbuild_restore_origin +#: model:ir.model.fields,field_description:mrp_unbuild_restore_origin.field_mrp_unbuild__restore_rm_stock_in_origin_loc +msgid "Return Components to Original Location" +msgstr "" + +#. module: mrp_unbuild_restore_origin +#: model:ir.model,name:mrp_unbuild_restore_origin.model_stock_move +msgid "Stock Move" +msgstr "" + +#. module: mrp_unbuild_restore_origin +#: model:ir.model,name:mrp_unbuild_restore_origin.model_mrp_unbuild +msgid "Unbuild Order" +msgstr "" diff --git a/mrp_unbuild_restore_origin/models/__init__.py b/mrp_unbuild_restore_origin/models/__init__.py new file mode 100644 index 00000000000..fbdd317fcce --- /dev/null +++ b/mrp_unbuild_restore_origin/models/__init__.py @@ -0,0 +1,2 @@ +from . import mrp_unbuild +from . import stock_move_line diff --git a/mrp_unbuild_restore_origin/models/mrp_unbuild.py b/mrp_unbuild_restore_origin/models/mrp_unbuild.py new file mode 100644 index 00000000000..0d6a712eb6c --- /dev/null +++ b/mrp_unbuild_restore_origin/models/mrp_unbuild.py @@ -0,0 +1,27 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class MrpUnbuild(models.Model): + _inherit = "mrp.unbuild" + + restore_rm_stock_in_origin_loc = fields.Boolean( + string="Return Components to Original Location", + help="If selected, components will be returned to the same location" + " they were taken from during manufacturing.", + ) + + def action_unbuild(self): + self.ensure_one() + if self.mo_id and self.restore_rm_stock_in_origin_loc: + self = self.with_context(exact_location=True) + return super().action_unbuild() + + def _prepare_move_line_vals(self, move, origin_move_line, taken_quantity): + vals = super()._prepare_move_line_vals(move, origin_move_line, taken_quantity) + if self.env.context.get("exact_location"): + vals["location_id"] = origin_move_line.location_dest_id.id + vals["location_dest_id"] = origin_move_line.location_id.id + return vals diff --git a/mrp_unbuild_restore_origin/models/stock_move_line.py b/mrp_unbuild_restore_origin/models/stock_move_line.py new file mode 100644 index 00000000000..2cd8f672bf5 --- /dev/null +++ b/mrp_unbuild_restore_origin/models/stock_move_line.py @@ -0,0 +1,21 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class StockMoveLine(models.Model): + _inherit = "stock.move.line" + + def _apply_putaway_strategy(self): + # Avoid changing locations if exact_location context is set + location_id = False + location_dest_id = False + if self.env.context.get("exact_location"): + location_id = self.location_id.id + location_dest_id = self.location_dest_id.id + super()._apply_putaway_strategy() + if location_id and location_dest_id: + self.location_id = location_id + self.location_dest_id = location_dest_id + return diff --git a/mrp_unbuild_restore_origin/pyproject.toml b/mrp_unbuild_restore_origin/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/mrp_unbuild_restore_origin/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/mrp_unbuild_restore_origin/readme/CONTRIBUTORS.md b/mrp_unbuild_restore_origin/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..9fc009d10a7 --- /dev/null +++ b/mrp_unbuild_restore_origin/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- [Quartile](https://www.quartile.co): + - Aung Ko Ko Lin + - Yoshi Tashiro + - Toshikimi Shigenobu diff --git a/mrp_unbuild_restore_origin/readme/DESCRIPTION.md b/mrp_unbuild_restore_origin/readme/DESCRIPTION.md new file mode 100644 index 00000000000..568c01865af --- /dev/null +++ b/mrp_unbuild_restore_origin/readme/DESCRIPTION.md @@ -0,0 +1,5 @@ +This module enhances the unbuild process of Manufacturing Orders by retaining +information from the original move lines. + +- **Location Retention (Optional):** A boolean field is available to retain the original + source and destination locations of the move lines during the unbuild process, if needed. diff --git a/mrp_unbuild_restore_origin/readme/USAGE.md b/mrp_unbuild_restore_origin/readme/USAGE.md new file mode 100644 index 00000000000..66eabc8ec4c --- /dev/null +++ b/mrp_unbuild_restore_origin/readme/USAGE.md @@ -0,0 +1,4 @@ +If you want the components to be returned to the same locations they were originally +consumed from, enable the checkbox labeled **"Restore Components to Original Location"** +when creating the Unbuild Order. If this option is not enabled, Odoo will follow its standard +behavior. diff --git a/mrp_unbuild_restore_origin/static/description/icon.png b/mrp_unbuild_restore_origin/static/description/icon.png new file mode 100644 index 00000000000..1dcc49c24f3 Binary files /dev/null and b/mrp_unbuild_restore_origin/static/description/icon.png differ diff --git a/mrp_unbuild_restore_origin/static/description/index.html b/mrp_unbuild_restore_origin/static/description/index.html new file mode 100644 index 00000000000..39eed73ff56 --- /dev/null +++ b/mrp_unbuild_restore_origin/static/description/index.html @@ -0,0 +1,452 @@ + + + + + +Mrp Unbuild Restore Origin + + + +
+

Mrp Unbuild Restore Origin

+ + +

Beta License: AGPL-3 OCA/manufacture Translate me on Weblate Try me on Runboat

+
+
This module enhances the unbuild process of Manufacturing Orders by +retaining
+
information from the original move lines.
+
+
    +
  • Location Retention (Optional): A boolean field is available to +retain the original +source and destination locations of the move lines during the unbuild +process, if needed.
  • +
+

Table of contents

+ +
+

Usage

+
+
If you want the components to be returned to the same locations they +were originally
+
consumed from, enable the checkbox labeled “Restore Components to +Original Location”
+
when creating the Unbuild Order. If this option is not enabled, Odoo +will follow its standard behavior.
+
+
+
+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Quartile
  • +
+
+
+

Contributors

+
    +
  • Quartile:
      +
    • Aung Ko Ko Lin
    • +
    • Yoshi Tashiro
    • +
    • Toshikimi Shigenobu
    • +
    +
  • +
+
+
+

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.

+

Current maintainers:

+

yostashiro aungkokolin1997

+

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/mrp_unbuild_restore_origin/tests/__init__.py b/mrp_unbuild_restore_origin/tests/__init__.py new file mode 100644 index 00000000000..3d7db80c9e6 --- /dev/null +++ b/mrp_unbuild_restore_origin/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mrp_unbuild_origin_location diff --git a/mrp_unbuild_restore_origin/tests/test_mrp_unbuild_origin_location.py b/mrp_unbuild_restore_origin/tests/test_mrp_unbuild_origin_location.py new file mode 100644 index 00000000000..a02d8fadea4 --- /dev/null +++ b/mrp_unbuild_restore_origin/tests/test_mrp_unbuild_origin_location.py @@ -0,0 +1,100 @@ +# Copyright 2025 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import Command +from odoo.tests import common + + +class TestMRPUnbuildOriginLocation(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.stock_location = cls.env.ref("stock.stock_location_stock") + cls.custom_location = cls.env["stock.location"].create( + { + "name": "Custom Sub Location", + "location_id": cls.stock_location.id, + "usage": "internal", + } + ) + cls.component_product = cls.env["product.product"].create( + { + "name": "Component", + "is_storable": True, + } + ) + cls.finished_product = cls.env["product.product"].create( + { + "name": "Finished Product", + "is_storable": True, + } + ) + cls.bom = cls.env["mrp.bom"].create( + { + "product_tmpl_id": cls.finished_product.product_tmpl_id.id, + "product_qty": 1.0, + "type": "normal", + "bom_line_ids": [ + Command.create( + { + "product_id": cls.component_product.id, + "product_qty": 1.0, + } + ), + ], + } + ) + quant1 = cls.env["stock.quant"].create( + { + "location_id": cls.custom_location.id, + "product_id": cls.component_product.id, + "inventory_quantity": 10, + } + ) + quant1.action_apply_inventory() + + def _create_mo(self): + mo = self.env["mrp.production"].create( + { + "product_id": self.finished_product.id, + "product_qty": 1.0, + "bom_id": self.bom.id, + } + ) + mo.action_confirm() + mo.button_mark_done() + return mo + + def _create_unbuild(self, mo, restore_rm_stock=False): + unbuild = self.env["mrp.unbuild"].create( + { + "mo_id": mo.id, + "product_id": self.finished_product.id, + "product_qty": 1.0, + "restore_rm_stock_in_origin_loc": restore_rm_stock, + } + ) + unbuild.action_unbuild() + return unbuild + + def test_unbuild_with_restore_rm_stock_true(self): + mo = self._create_mo() + unbuild = self._create_unbuild(mo, restore_rm_stock=True) + move_lines = self.env["stock.move.line"].search( + [("reference", "=", unbuild.name)] + ) + for line in move_lines.filtered( + lambda ml: ml.product_id == self.component_product + ): + self.assertEqual(line.location_dest_id, self.custom_location) + + def test_unbuild_with_restore_rm_stock_false(self): + mo = self._create_mo() + unbuild = self._create_unbuild(mo, restore_rm_stock=False) + move_lines = self.env["stock.move.line"].search( + [("reference", "=", unbuild.name)] + ) + for line in move_lines.filtered( + lambda ml: ml.product_id == self.component_product + ): + self.assertNotEqual(line.location_dest_id, self.custom_location) diff --git a/mrp_unbuild_restore_origin/views/mrp_unbuild_views.xml b/mrp_unbuild_restore_origin/views/mrp_unbuild_views.xml new file mode 100644 index 00000000000..a69022475e3 --- /dev/null +++ b/mrp_unbuild_restore_origin/views/mrp_unbuild_views.xml @@ -0,0 +1,39 @@ + + + + mrp.unbuild.form + mrp.unbuild + + + + + + + restore_rm_stock_in_origin_loc == True + + + + + mrp.unbuild.simplified.form + mrp.unbuild + + + + + + + restore_rm_stock_in_origin_loc == True + + + +