From 190d2a0bd6e5e9034b80f0153df38d4d6eb000f4 Mon Sep 17 00:00:00 2001 From: nobuQuartile Date: Fri, 24 Jul 2026 05:20:38 +0000 Subject: [PATCH 1/2] [7003][ADD] stock_lot_top_parent: trace top-level parent on lots/serials Add fields to stock.lot to trace where a unique serial is used, as part of moving the customer's spreadsheet-based management into Odoo: - Top lv Parent S/N: the parent assembly's serial (lot) this lot belongs to - Top lv Parent P/N: the parent's product (related field) - Physical Location: the parent serial's current internal location(s), computed on the fly from stock quants --- .../odoo/addons/stock_lot_top_parent | 1 + setup/stock_lot_top_parent/setup.py | 6 + stock_lot_top_parent/README.rst | 79 ++++ stock_lot_top_parent/__init__.py | 1 + stock_lot_top_parent/__manifest__.py | 18 + stock_lot_top_parent/i18n/ja.po | 53 +++ stock_lot_top_parent/models/__init__.py | 1 + stock_lot_top_parent/models/stock_lot.py | 44 ++ stock_lot_top_parent/readme/CONTRIBUTORS.md | 2 + stock_lot_top_parent/readme/DESCRIPTION.md | 10 + .../static/description/index.html | 431 ++++++++++++++++++ stock_lot_top_parent/tests/__init__.py | 1 + .../tests/test_stock_lot_top_parent.py | 68 +++ .../views/stock_lot_views.xml | 17 + 14 files changed, 732 insertions(+) create mode 120000 setup/stock_lot_top_parent/odoo/addons/stock_lot_top_parent create mode 100644 setup/stock_lot_top_parent/setup.py create mode 100644 stock_lot_top_parent/README.rst create mode 100644 stock_lot_top_parent/__init__.py create mode 100644 stock_lot_top_parent/__manifest__.py create mode 100644 stock_lot_top_parent/i18n/ja.po create mode 100644 stock_lot_top_parent/models/__init__.py create mode 100644 stock_lot_top_parent/models/stock_lot.py create mode 100644 stock_lot_top_parent/readme/CONTRIBUTORS.md create mode 100644 stock_lot_top_parent/readme/DESCRIPTION.md create mode 100644 stock_lot_top_parent/static/description/index.html create mode 100644 stock_lot_top_parent/tests/__init__.py create mode 100644 stock_lot_top_parent/tests/test_stock_lot_top_parent.py create mode 100644 stock_lot_top_parent/views/stock_lot_views.xml diff --git a/setup/stock_lot_top_parent/odoo/addons/stock_lot_top_parent b/setup/stock_lot_top_parent/odoo/addons/stock_lot_top_parent new file mode 120000 index 0000000..091e876 --- /dev/null +++ b/setup/stock_lot_top_parent/odoo/addons/stock_lot_top_parent @@ -0,0 +1 @@ +../../../../stock_lot_top_parent \ No newline at end of file diff --git a/setup/stock_lot_top_parent/setup.py b/setup/stock_lot_top_parent/setup.py new file mode 100644 index 0000000..28c57bb --- /dev/null +++ b/setup/stock_lot_top_parent/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_lot_top_parent/README.rst b/stock_lot_top_parent/README.rst new file mode 100644 index 0000000..f4c5672 --- /dev/null +++ b/stock_lot_top_parent/README.rst @@ -0,0 +1,79 @@ +==================== +Stock Lot Top Parent +==================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:94b5d1f66e4e12433572b8e103c9da3fcd341da805c3f922bde6e4d38e4478bc + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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-qrtl%2Fthc--custom-lightgray.png?logo=github + :target: https://github.com/qrtl/thc-custom/tree/16.0/stock_lot_top_parent + :alt: qrtl/thc-custom + +|badge1| |badge2| |badge3| + +This module adds top-level parent traceability fields to lots/serials +(*Inventory > Products > Lots/Serial Numbers*): + +- **Top lv Parent S/N**: the serial number (lot) of the top-level parent + assembly this lot belongs to. +- **Top lv Parent P/N**: the product of the top-level parent serial (a + related field, kept in sync automatically). +- **Physical Location**: the current internal location(s) of the + top-level parent serial, computed on the fly from stock quants. It is + empty when the parent serial is not stored in any internal location. + +**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 + +Maintainers +----------- + +.. |maintainer-nobuQuartile| image:: https://github.com/nobuQuartile.png?size=40px + :target: https://github.com/nobuQuartile + :alt: nobuQuartile + +Current maintainer: + +|maintainer-nobuQuartile| + +This module is part of the `qrtl/thc-custom `_ project on GitHub. + +You are welcome to contribute. diff --git a/stock_lot_top_parent/__init__.py b/stock_lot_top_parent/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/stock_lot_top_parent/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_lot_top_parent/__manifest__.py b/stock_lot_top_parent/__manifest__.py new file mode 100644 index 0000000..4c21eae --- /dev/null +++ b/stock_lot_top_parent/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2026 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Stock Lot Top Parent", + "version": "16.0.1.0.0", + "category": "Inventory", + "license": "AGPL-3", + "author": "Quartile", + "website": "https://www.quartile.co", + "maintainers": ["nobuQuartile"], + "summary": "Track the top-level parent serial, part number and current " + "physical location on lots/serials.", + "depends": ["stock"], + "data": [ + "views/stock_lot_views.xml", + ], + "installable": True, +} diff --git a/stock_lot_top_parent/i18n/ja.po b/stock_lot_top_parent/i18n/ja.po new file mode 100644 index 0000000..478c221 --- /dev/null +++ b/stock_lot_top_parent/i18n/ja.po @@ -0,0 +1,53 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_lot_top_parent +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-07-24 02:47+0000\n" +"PO-Revision-Date: 2026-07-24 02:47+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: stock_lot_top_parent +#: model:ir.model.fields,help:stock_lot_top_parent.field_stock_lot__top_parent_location_ids +msgid "" +"Current internal locations of Top lv Parent S/N, or of this lot itself when " +"it has no parent. Empty when it is not stored in any internal location." +msgstr "トップレベル親 S/N(親がない場合はこのロット自身)の現在の内部ロケーション。いずれの内部ロケーションにも保管されていない場合は空欄。" + +#. module: stock_lot_top_parent +#: model:ir.model,name:stock_lot_top_parent.model_stock_lot +msgid "Lot/Serial" +msgstr "ロット/シリアル" + +#. module: stock_lot_top_parent +#: model:ir.model.fields,field_description:stock_lot_top_parent.field_stock_lot__top_parent_location_ids +msgid "Physical Location" +msgstr "物理ロケーション" + +#. module: stock_lot_top_parent +#: model:ir.model.fields,help:stock_lot_top_parent.field_stock_lot__top_parent_lot_id +msgid "Serial number of the top-level parent assembly this lot belongs to." +msgstr "このロットが属するトップレベル親アセンブリのシリアル番号。" + +#. module: stock_lot_top_parent +#: model_terms:ir.ui.view,arch_db:stock_lot_top_parent.stock_lot_view_form +msgid "Top Level Parent" +msgstr "トップレベル親" + +#. module: stock_lot_top_parent +#: model:ir.model.fields,field_description:stock_lot_top_parent.field_stock_lot__top_parent_product_id +msgid "Top lv Parent P/N" +msgstr "トップレベル親 P/N" + +#. module: stock_lot_top_parent +#: model:ir.model.fields,field_description:stock_lot_top_parent.field_stock_lot__top_parent_lot_id +msgid "Top lv Parent S/N" +msgstr "トップレベル親 S/N" diff --git a/stock_lot_top_parent/models/__init__.py b/stock_lot_top_parent/models/__init__.py new file mode 100644 index 0000000..ee1c64f --- /dev/null +++ b/stock_lot_top_parent/models/__init__.py @@ -0,0 +1 @@ +from . import stock_lot diff --git a/stock_lot_top_parent/models/stock_lot.py b/stock_lot_top_parent/models/stock_lot.py new file mode 100644 index 0000000..e1e3c44 --- /dev/null +++ b/stock_lot_top_parent/models/stock_lot.py @@ -0,0 +1,44 @@ +# 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 + + +class StockLot(models.Model): + _inherit = "stock.lot" + + top_parent_lot_id = fields.Many2one( + "stock.lot", + string="Top lv Parent S/N", + help="Serial number of the top-level parent assembly this lot belongs to.", + ) + top_parent_product_id = fields.Many2one( + "product.product", + related="top_parent_lot_id.product_id", + string="Top lv Parent P/N", + ) + top_parent_location_ids = fields.Many2many( + "stock.location", + string="Physical Location", + compute="_compute_top_parent_location_ids", + help="Current internal locations of Top lv Parent S/N, or of this lot " + "itself when it has no parent. Empty when it is not stored in any " + "internal location.", + ) + + @api.depends("top_parent_lot_id") + def _compute_top_parent_location_ids(self): + quant_model = self.env["stock.quant"] + for lot in self: + target_lot = lot.top_parent_lot_id or lot + if not target_lot.id: + lot.top_parent_location_ids = False + continue + quants = quant_model.search( + [ + ("lot_id", "=", target_lot.id), + ("location_id.usage", "=", "internal"), + ("quantity", ">", 0), + ] + ) + lot.top_parent_location_ids = quants.location_id diff --git a/stock_lot_top_parent/readme/CONTRIBUTORS.md b/stock_lot_top_parent/readme/CONTRIBUTORS.md new file mode 100644 index 0000000..04192ea --- /dev/null +++ b/stock_lot_top_parent/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [Quartile](https://www.quartile.co): + - Toshikimi Shigenobu diff --git a/stock_lot_top_parent/readme/DESCRIPTION.md b/stock_lot_top_parent/readme/DESCRIPTION.md new file mode 100644 index 0000000..eeb37ca --- /dev/null +++ b/stock_lot_top_parent/readme/DESCRIPTION.md @@ -0,0 +1,10 @@ +This module adds top-level parent traceability fields to lots/serials +(*Inventory > Products > Lots/Serial Numbers*): + +- **Top lv Parent S/N**: the serial number (lot) of the top-level parent + assembly this lot belongs to. +- **Top lv Parent P/N**: the product of the top-level parent serial + (a related field, kept in sync automatically). +- **Physical Location**: the current internal location(s) of the top-level + parent serial, computed on the fly from stock quants. It is empty when + the parent serial is not stored in any internal location. diff --git a/stock_lot_top_parent/static/description/index.html b/stock_lot_top_parent/static/description/index.html new file mode 100644 index 0000000..5b3ec13 --- /dev/null +++ b/stock_lot_top_parent/static/description/index.html @@ -0,0 +1,431 @@ + + + + + +Stock Lot Top Parent + + + +
+

Stock Lot Top Parent

+ + +

Beta License: AGPL-3 qrtl/thc-custom

+

This module adds top-level parent traceability fields to lots/serials +(Inventory > Products > Lots/Serial Numbers):

+
    +
  • Top lv Parent S/N: the serial number (lot) of the top-level parent +assembly this lot belongs to.
  • +
  • Top lv Parent P/N: the product of the top-level parent serial (a +related field, kept in sync automatically).
  • +
  • Physical Location: the current internal location(s) of the +top-level parent serial, computed on the fly from stock quants. It is +empty when the parent serial is not stored in any internal location.
  • +
+

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

+ +
+
+

Maintainers

+

Current maintainer:

+

nobuQuartile

+

This module is part of the qrtl/thc-custom project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/stock_lot_top_parent/tests/__init__.py b/stock_lot_top_parent/tests/__init__.py new file mode 100644 index 0000000..522320e --- /dev/null +++ b/stock_lot_top_parent/tests/__init__.py @@ -0,0 +1 @@ +from . import test_stock_lot_top_parent diff --git a/stock_lot_top_parent/tests/test_stock_lot_top_parent.py b/stock_lot_top_parent/tests/test_stock_lot_top_parent.py new file mode 100644 index 0000000..8e78479 --- /dev/null +++ b/stock_lot_top_parent/tests/test_stock_lot_top_parent.py @@ -0,0 +1,68 @@ +# Copyright 2026 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests import TransactionCase + + +class TestStockLotTopParent(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + stock_location = cls.env.ref("stock.stock_location_stock") + cls.loc_a = cls.env["stock.location"].create( + {"name": "TP Loc A", "usage": "internal", "location_id": stock_location.id} + ) + cls.loc_b = cls.env["stock.location"].create( + {"name": "TP Loc B", "usage": "internal", "location_id": stock_location.id} + ) + cls.loc_customer = cls.env["stock.location"].create( + {"name": "TP Customer", "usage": "customer"} + ) + cls.parent_product = cls.env["product.product"].create( + { + "name": "Top Parent Product", + "detailed_type": "product", + "tracking": "lot", + } + ) + cls.child_product = cls.env["product.product"].create( + {"name": "Child Product", "detailed_type": "product", "tracking": "lot"} + ) + cls.parent_lot = cls.env["stock.lot"].create( + { + "name": "PARENT-0001", + "product_id": cls.parent_product.id, + "company_id": cls.env.company.id, + } + ) + cls.child_lot = cls.env["stock.lot"].create( + { + "name": "CHILD-0001", + "product_id": cls.child_product.id, + "company_id": cls.env.company.id, + } + ) + + def _add_quant(self, lot, location, quantity): + self.env["stock.quant"]._update_available_quantity( + lot.product_id, location, quantity, lot_id=lot + ) + + def test_physical_location_internal_only(self): + self._add_quant(self.parent_lot, self.loc_a, 5) + self._add_quant(self.parent_lot, self.loc_b, 3) + self._add_quant(self.parent_lot, self.loc_customer, 2) + self.child_lot.top_parent_lot_id = self.parent_lot + self.assertEqual( + self.child_lot.top_parent_location_ids, self.loc_a | self.loc_b + ) + + def test_physical_location_no_parent_uses_self(self): + self._add_quant(self.child_lot, self.loc_a, 4) + self.assertFalse(self.child_lot.top_parent_lot_id) + self.assertEqual(self.child_lot.top_parent_location_ids, self.loc_a) + + def test_no_parent_no_stock_is_empty(self): + self.assertFalse(self.child_lot.top_parent_lot_id) + self.assertFalse(self.child_lot.top_parent_product_id) + self.assertFalse(self.child_lot.top_parent_location_ids) diff --git a/stock_lot_top_parent/views/stock_lot_views.xml b/stock_lot_top_parent/views/stock_lot_views.xml new file mode 100644 index 0000000..dc81466 --- /dev/null +++ b/stock_lot_top_parent/views/stock_lot_views.xml @@ -0,0 +1,17 @@ + + + + stock.lot.form.top.parent + stock.lot + + + + + + + + + + + + From c126a1f48df5fb2976bdfdae99d3f47e99792d57 Mon Sep 17 00:00:00 2001 From: nobuQuartile Date: Tue, 28 Jul 2026 08:28:39 +0000 Subject: [PATCH 2/2] fixup --- stock_lot_top_parent/__manifest__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stock_lot_top_parent/__manifest__.py b/stock_lot_top_parent/__manifest__.py index 4c21eae..b917d78 100644 --- a/stock_lot_top_parent/__manifest__.py +++ b/stock_lot_top_parent/__manifest__.py @@ -2,14 +2,14 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). { "name": "Stock Lot Top Parent", + "summary": "Track the top-level parent serial, part number and current " + "physical location on lots/serials.", "version": "16.0.1.0.0", "category": "Inventory", "license": "AGPL-3", "author": "Quartile", "website": "https://www.quartile.co", "maintainers": ["nobuQuartile"], - "summary": "Track the top-level parent serial, part number and current " - "physical location on lots/serials.", "depends": ["stock"], "data": [ "views/stock_lot_views.xml",