Skip to content

[7003][ADD] stock_lot_top_parent: trace top-level parent on lots/serials - #29

Closed
nobuQuartile wants to merge 2 commits into
16.0from
7003-add-stock_lot_top_parent
Closed

[7003][ADD] stock_lot_top_parent: trace top-level parent on lots/serials#29
nobuQuartile wants to merge 2 commits into
16.0from
7003-add-stock_lot_top_parent

Conversation

@nobuQuartile

Copy link
Copy Markdown
Contributor

QT7003

What

New module stock_lot_top_parent adding top-level parent traceability fields to lots/serials (Inventory > Products > Lots/Serial Numbers):

  • Top lv Parent S/N (top_parent_lot_id): Many2one to the parent assembly's serial (lot) this lot belongs to.
  • Top lv Parent P/N (top_parent_product_id): the parent's product — a related field (no compute, per maintainability guidance).
  • Physical Location (top_parent_location_ids): Many2many of the parent serial's current internal location(s), computed on the fly from stock.quant (empty when not in any internal location).

Why

Trace where a unique serial is used, as part of moving the customer's spreadsheet-based management into Odoo. Per task-7003.

Test

  • Installs on 16.0; pre-commit clean.
  • Functionally verified on staging data: Physical Location resolves all internal locations of the parent serial (confirmed with a lot split across 2 locations), related P/N resolves, and it is empty when no parent is set.

@nobuQuartile

Copy link
Copy Markdown
Contributor Author

Add ja.po

Translation notes

"Lot/Serial" is referenced from the existing Odoo translation (odoo/stock). The remaining terms are module-specific and translated independently:

msgid msgstr
Physical Location 物理ロケーション
Top Level Parent トップレベル親
Top lv Parent P/N トップレベル親 P/N
Top lv Parent S/N トップレベル親 S/N
Serial number of the top-level parent assembly this lot belongs to. このロットが属するトップレベル親アセンブリのシリアル番号。
Current internal locations of the top-level parent serial. Empty when it is not stored in any internal location. トップレベル親シリアルの現在の内部ロケーション。いずれの内部ロケーションにも保管されていない場合は空欄。

@nobuQuartile
nobuQuartile force-pushed the 7003-add-stock_lot_top_parent branch 6 times, most recently from 2ceb403 to eb9681b Compare July 27, 2026 06:18
@nobuQuartile
nobuQuartile marked this pull request as ready for review July 27, 2026 06:54
@nobuQuartile

Copy link
Copy Markdown
Contributor Author

Ready for review

@AungKoKoLin1997 AungKoKoLin1997 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Module name suggestion: stock_lot_parent.

Comment thread stock_lot_top_parent/models/stock_lot.py
Comment thread stock_lot_top_parent/models/stock_lot.py
Comment thread stock_lot_top_parent/models/stock_lot.py
Comment thread stock_lot_top_parent/models/stock_lot.py
@keinak

keinak commented Jul 27, 2026

Copy link
Copy Markdown

御社の中で検討いただき問題無ければ、無視頂いて大丈夫です。

新規レコード(未保存フォーム)でのcompute動作 — [stock_lot.py:31-43] の _compute_top_parent_location_ids は、親未設定時に target_lot = lot として lot.id を search ドメインに渡します。新規作成フォームでは id が NewId(仮ID)のため、Odooのバージョン・パッチ状況によっては search がエラーになるか予期しない挙動になります。新規ロット作成フォームを開いた時にエラーが出ないか要確認です。防御的に以下のガードを推奨します:

for lot in self:
if not lot.id:
lot.top_parent_location_ids = False
continue

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
@nobuQuartile
nobuQuartile force-pushed the 7003-add-stock_lot_top_parent branch from eb9681b to 190d2a0 Compare July 28, 2026 02:39

@AungKoKoLin1997 AungKoKoLin1997 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review: LGTM

Comment thread stock_lot_top_parent/__manifest__.py Outdated

@yostashiro yostashiro left a comment

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.

Partial review.

"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",
)

Comment on lines +37 to +43
quants = quant_model.search(
[
("lot_id", "=", target_lot.id),
("location_id.usage", "=", "internal"),
("quantity", ">", 0),
]
)

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
)

@nobuQuartile

Copy link
Copy Markdown
Contributor Author

We decided not to follow up on this.
The clients will create the compute fields by themselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants