diff --git a/mrp_unbuild_lot_location/README.rst b/mrp_unbuild_lot_location/README.rst new file mode 100644 index 00000000..bb40ccfe --- /dev/null +++ b/mrp_unbuild_lot_location/README.rst @@ -0,0 +1,85 @@ +======================== +MRP Unbuild Lot Location +======================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:4f9697c06fd8dbb3a982668b55249262d59735b25801624826dd0d07eb0c3677 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/16.0/mrp_unbuild_lot_location + :alt: OCA/manufacture +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/manufacture-16-0/manufacture-16-0-mrp_unbuild_lot_location + :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=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +When a lot/serial number is selected on an unbuild order, this module +filters the available source locations to only those where the +lot/serial number is currently stocked. + +If stock exists in a single location, it is automatically set as the +source location. If stock exists in multiple locations, the list is +narrowed down for the user to choose from. A warning is displayed if +no stock is found for the selected lot/serial number. + +**Table of contents** + +.. contents:: + :local: + +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 `_: + * Toshikimi Shigenobu + * Aung Ko Ko Lin + +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/mrp_unbuild_lot_location/__init__.py b/mrp_unbuild_lot_location/__init__.py new file mode 100644 index 00000000..13161700 --- /dev/null +++ b/mrp_unbuild_lot_location/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2025 Quartile Limited +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/mrp_unbuild_lot_location/__manifest__.py b/mrp_unbuild_lot_location/__manifest__.py new file mode 100644 index 00000000..e29f4b88 --- /dev/null +++ b/mrp_unbuild_lot_location/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2026 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "MRP Unbuild Lot Location", + "summary": "Filter unbuild source locations by lot/serial stock", + "category": "Manufacturing", + "license": "AGPL-3", + "author": "Quartile, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/manufacture", + "version": "16.0.1.0.0", + "depends": ["mrp"], + "data": ["views/mrp_unbuild_views.xml"], + "installable": True, +} diff --git a/mrp_unbuild_lot_location/i18n/ja.po b/mrp_unbuild_lot_location/i18n/ja.po new file mode 100644 index 00000000..13b3df48 --- /dev/null +++ b/mrp_unbuild_lot_location/i18n/ja.po @@ -0,0 +1,33 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_unbuild_lot_location +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-02-27 04:51+0000\n" +"PO-Revision-Date: 2026-02-27 04:51+0000\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_lot_location +#: model:ir.model.fields,field_description:mrp_unbuild_lot_location.field_mrp_unbuild__location_id_domain +msgid "Location Id Domain" +msgstr "ロケーションIDドメイン" + +#. module: mrp_unbuild_lot_location +#. odoo-python +#: code:addons/mrp_unbuild_lot_location/models/mrp_unbuild.py:0 +#, python-format +msgid "No stock found for lot/serial number %s." +msgstr "ロット/シリアル番号 %s の在庫がありません。" + +#. module: mrp_unbuild_lot_location +#: model:ir.model,name:mrp_unbuild_lot_location.model_mrp_unbuild +msgid "Unbuild Order" +msgstr "解体オーダ" diff --git a/mrp_unbuild_lot_location/models/__init__.py b/mrp_unbuild_lot_location/models/__init__.py new file mode 100644 index 00000000..d576b950 --- /dev/null +++ b/mrp_unbuild_lot_location/models/__init__.py @@ -0,0 +1 @@ +from . import mrp_unbuild diff --git a/mrp_unbuild_lot_location/models/mrp_unbuild.py b/mrp_unbuild_lot_location/models/mrp_unbuild.py new file mode 100644 index 00000000..fca74317 --- /dev/null +++ b/mrp_unbuild_lot_location/models/mrp_unbuild.py @@ -0,0 +1,63 @@ +# Copyright 2026 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError +from odoo.osv import expression + + +class MrpUnbuild(models.Model): + _inherit = "mrp.unbuild" + + location_id_domain = fields.Binary(compute="_compute_location_id_domain") + + @api.depends("lot_id", "product_id", "company_id") + def _compute_location_id_domain(self): + for record in self: + # Standard location filter (applies even without a lot) + base_domain = [ + ("usage", "in", ["internal", "transit"]), + "|", + ("company_id", "=", False), + ("company_id", "=", record.company_id.id), + ] + if record.lot_id: + location_ids = ( + self.env["stock.quant"] + .search( + [ + ("product_id", "=", record.product_id.id), + ("lot_id", "=", record.lot_id.id), + ("quantity", ">", 0), + ] + ) + .location_id.ids + ) + base_domain = expression.AND( + [ + base_domain, + [("id", "in", location_ids)], + ] + ) + record.location_id_domain = base_domain + + @api.depends("company_id", "location_id_domain") + def _compute_location_id(self): + super()._compute_location_id() + for record in self.filtered("lot_id"): + locations = self.env["stock.location"].search(record.location_id_domain) + if len(locations) == 1: + record.location_id = locations + return + + @api.constrains("lot_id") + def _check_lot_location(self): + for record in self: + if not record.lot_id: + continue + if not self.env["stock.location"].search( + record.location_id_domain, limit=1 + ): + raise ValidationError( + _("No stock found for lot/serial number %s.") % record.lot_id.name + ) diff --git a/mrp_unbuild_lot_location/readme/CONTRIBUTORS.rst b/mrp_unbuild_lot_location/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..cb949fb0 --- /dev/null +++ b/mrp_unbuild_lot_location/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Quartile `_: + * Toshikimi Shigenobu + * Aung Ko Ko Lin diff --git a/mrp_unbuild_lot_location/readme/DESCRIPTION.rst b/mrp_unbuild_lot_location/readme/DESCRIPTION.rst new file mode 100644 index 00000000..b796670a --- /dev/null +++ b/mrp_unbuild_lot_location/readme/DESCRIPTION.rst @@ -0,0 +1,8 @@ +When a lot/serial number is selected on an unbuild order, this module +filters the available source locations to only those where the +lot/serial number is currently stocked. + +If stock exists in a single location, it is automatically set as the +source location. If stock exists in multiple locations, the list is +narrowed down for the user to choose from. A warning is displayed if +no stock is found for the selected lot/serial number. diff --git a/mrp_unbuild_lot_location/static/description/index.html b/mrp_unbuild_lot_location/static/description/index.html new file mode 100644 index 00000000..32240446 --- /dev/null +++ b/mrp_unbuild_lot_location/static/description/index.html @@ -0,0 +1,437 @@ + + + + + +MRP Unbuild Lot Location + + + +
+

MRP Unbuild Lot Location

+ + +

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

+

When a lot/serial number is selected on an unbuild order, this module +filters the available source locations to only those where the +lot/serial number is currently stocked.

+

If stock exists in a single location, it is automatically set as the +source location. If stock exists in multiple locations, the list is +narrowed down for the user to choose from. A warning is displayed if +no stock is found for the selected lot/serial number.

+

Table of contents

+ +
+

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:
    +
      +
    • Toshikimi Shigenobu
    • +
    • Aung Ko Ko Lin
    • +
    +
    +
    +
  • +
+
+
+

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/mrp_unbuild_lot_location/tests/__init__.py b/mrp_unbuild_lot_location/tests/__init__.py new file mode 100644 index 00000000..ea457776 --- /dev/null +++ b/mrp_unbuild_lot_location/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mrp_unbuild_lot_location diff --git a/mrp_unbuild_lot_location/tests/test_mrp_unbuild_lot_location.py b/mrp_unbuild_lot_location/tests/test_mrp_unbuild_lot_location.py new file mode 100644 index 00000000..a85cf50d --- /dev/null +++ b/mrp_unbuild_lot_location/tests/test_mrp_unbuild_lot_location.py @@ -0,0 +1,86 @@ +# Copyright 2026 Quartile +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.exceptions import ValidationError +from odoo.tests.common import TransactionCase + + +class TestMrpUnbuildLotLocation(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.warehouse = cls.env["stock.warehouse"].create( + { + "name": "Test Warehouse", + "code": "TWH", + "company_id": cls.env.company.id, + } + ) + cls.location_1 = cls.env["stock.location"].create( + { + "name": "Location 1", + "location_id": cls.warehouse.lot_stock_id.id, + "usage": "internal", + } + ) + cls.location_2 = cls.env["stock.location"].create( + { + "name": "Location 2", + "location_id": cls.warehouse.lot_stock_id.id, + "usage": "internal", + } + ) + cls.product = cls.env["product.product"].create( + {"name": "Test Product", "type": "product", "tracking": "lot"} + ) + cls.lot_1 = cls.env["stock.lot"].create( + { + "name": "lot_1", + "product_id": cls.product.id, + "company_id": cls.env.company.id, + } + ) + cls.lot_2 = cls.env["stock.lot"].create( + { + "name": "lot_2", + "product_id": cls.product.id, + "company_id": cls.env.company.id, + } + ) + cls.lot_3 = cls.env["stock.lot"].create( + { + "name": "lot_3", + "product_id": cls.product.id, + "company_id": cls.env.company.id, + } + ) + cls.env["stock.quant"]._update_available_quantity( + cls.product, cls.location_1, 5, lot_id=cls.lot_1 + ) + cls.env["stock.quant"]._update_available_quantity( + cls.product, cls.location_1, 2, lot_id=cls.lot_2 + ) + cls.env["stock.quant"]._update_available_quantity( + cls.product, cls.location_2, 3, lot_id=cls.lot_2 + ) + cls.unbuild = cls.env["mrp.unbuild"].create({"product_id": cls.product.id}) + + def test_location_id_domain_no_lot(self): + # When lot_id is not set, domain returns all internal/transit locations. + locations = self.env["stock.location"].search(self.unbuild.location_id_domain) + self.assertIn(self.location_1, locations) + self.assertIn(self.location_2, locations) + + def test_lot_location_resolution(self): + # When lot has stock in one location, location_id is auto-filled. + self.unbuild.lot_id = self.lot_1 + locations = self.env["stock.location"].search(self.unbuild.location_id_domain) + self.assertEqual(self.unbuild.location_id, self.location_1) + # When lot has stock in multiple locations, location_id is not auto-filled. + self.unbuild.lot_id = self.lot_2 + locations = self.env["stock.location"].search(self.unbuild.location_id_domain) + self.assertIn(self.location_1, locations) + self.assertIn(self.location_2, locations) + # When lot has no stock, saving raises a ValidationError. + with self.assertRaises(ValidationError): + self.unbuild.lot_id = self.lot_3 diff --git a/mrp_unbuild_lot_location/views/mrp_unbuild_views.xml b/mrp_unbuild_lot_location/views/mrp_unbuild_views.xml new file mode 100644 index 00000000..a09cecf1 --- /dev/null +++ b/mrp_unbuild_lot_location/views/mrp_unbuild_views.xml @@ -0,0 +1,16 @@ + + + + mrp.unbuild.form.inherit.location + mrp.unbuild + + + + + + + location_id_domain + + + + diff --git a/setup/mrp_unbuild_lot_location/odoo/addons/mrp_unbuild_lot_location b/setup/mrp_unbuild_lot_location/odoo/addons/mrp_unbuild_lot_location new file mode 120000 index 00000000..563d6c23 --- /dev/null +++ b/setup/mrp_unbuild_lot_location/odoo/addons/mrp_unbuild_lot_location @@ -0,0 +1 @@ +../../../../mrp_unbuild_lot_location \ No newline at end of file diff --git a/setup/mrp_unbuild_lot_location/setup.py b/setup/mrp_unbuild_lot_location/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/mrp_unbuild_lot_location/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)