Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions setup/stock_lot_top_parent/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
79 changes: 79 additions & 0 deletions stock_lot_top_parent/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/qrtl/thc-custom/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 <https://github.com/qrtl/thc-custom/issues/new?body=module:%20stock_lot_top_parent%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* Quartile

Contributors
------------

- `Quartile <https://www.quartile.co>`__:

- 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 <https://github.com/qrtl/thc-custom/tree/16.0/stock_lot_top_parent>`_ project on GitHub.

You are welcome to contribute.
1 change: 1 addition & 0 deletions stock_lot_top_parent/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions stock_lot_top_parent/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
"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"],
"depends": ["stock"],
"data": [
"views/stock_lot_views.xml",
],
"installable": True,
}
53 changes: 53 additions & 0 deletions stock_lot_top_parent/i18n/ja.po
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions stock_lot_top_parent/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_lot
44 changes: 44 additions & 0 deletions stock_lot_top_parent/models/stock_lot.py
Comment thread
nobuQuartile marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -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.",
)
Comment thread
nobuQuartile marked this conversation as resolved.
top_parent_product_id = fields.Many2one(
Comment thread
nobuQuartile marked this conversation as resolved.
"product.product",
related="top_parent_lot_id.product_id",
string="Top lv Parent P/N",
)
top_parent_location_ids = fields.Many2many(
Comment thread
nobuQuartile marked this conversation as resolved.
"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")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a major issue, but worth addressing it before we get hiccups.

Suggested change
@api.depends("top_parent_lot_id")
@api.depends(
"top_parent_lot_id",
"top_parent_lot_id.quant_ids.quantity",
"top_parent_lot_id.quant_ids.location_id",
"quant_ids",
"quant_ids.quantity",
"quant_ids.location_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),
]
)
Comment on lines +37 to +43

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
quants = quant_model.search(
[
("lot_id", "=", target_lot.id),
("location_id.usage", "=", "internal"),
("quantity", ">", 0),
]
)
quants = target_lot.quant_ids.filtered(
lambda q: q.location_id.usage == "internal"
and float_compare(
q.quantity, 0, precision_rounding=q.product_uom_id.rounding
)
> 0
)

lot.top_parent_location_ids = quants.location_id
2 changes: 2 additions & 0 deletions stock_lot_top_parent/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [Quartile](https://www.quartile.co):
- Toshikimi Shigenobu
10 changes: 10 additions & 0 deletions stock_lot_top_parent/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -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.
Loading
Loading