Skip to content
Open
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
107 changes: 107 additions & 0 deletions product_restricted_tracking/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

===========================
Product Restricted Tracking
===========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b65fa4c533fef8a0750c7dae1be3e2afd44df9ad1f330793cee4d7990fe259f4
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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-OCA%2Fproduct--attribute-lightgray.png?logo=github
:target: https://github.com/OCA/product-attribute/tree/16.0/product_restricted_tracking
:alt: OCA/product-attribute
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/product-attribute-16-0/product-attribute-16-0-product_restricted_tracking
: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/product-attribute&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module adds a 'restricted_tracking' field to the product category
model. With this optional selection field, you can enforce that all
products in a category must use a specific tracking method (Serial
Number, Lot, or None).

**Table of contents**

.. contents::
:local:

Configuration
=============

To configure this module:

1. Go to *Inventory > Configuration > Product Categories*
2. Select a category and set a *Restricted Tracking* value (Serial
Number, Lot, or None)
3. When creating or editing products in this category, only the allowed
tracking method can be selected

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-attribute/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/OCA/product-attribute/issues/new?body=module:%20product_restricted_tracking%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>

- 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.

.. |maintainer-aungkokolin1997| image:: https://github.com/aungkokolin1997.png?size=40px
:target: https://github.com/aungkokolin1997
:alt: aungkokolin1997
.. |maintainer-yostashiro| image:: https://github.com/yostashiro.png?size=40px
:target: https://github.com/yostashiro
:alt: yostashiro

Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-aungkokolin1997| |maintainer-yostashiro|

This module is part of the `OCA/product-attribute <https://github.com/OCA/product-attribute/tree/16.0/product_restricted_tracking>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions product_restricted_tracking/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions product_restricted_tracking/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2026 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Product Restricted Tracking",
"version": "16.0.1.0.0",
"author": "Quartile, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/product-attribute",
"license": "AGPL-3",
"category": "Product",
"depends": ["stock"],
"data": [
"views/product_category_views.xml",
],
"installable": True,
"maintainers": ["aungkokolin1997", "yostashiro"],
}
2 changes: 2 additions & 0 deletions product_restricted_tracking/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import product_category
from . import product_template
65 changes: 65 additions & 0 deletions product_restricted_tracking/models/product_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 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


class ProductCategory(models.Model):
_inherit = "product.category"

restricted_tracking = fields.Selection(
selection=lambda self: self.env["product.template"]
._fields["tracking"]
._description_selection(self.env),
)
Comment thread
AungKoKoLin1997 marked this conversation as resolved.

@api.constrains("restricted_tracking")
def _check_restricted_tracking(self):
for categ in self:
if not categ.restricted_tracking:
continue
conflicting_products = self.env["product.template"].search(
[
("categ_id", "=", categ.id),
("tracking", "!=", categ.restricted_tracking),
]
)
if conflicting_products:
tracking_label = dict(
categ._fields["restricted_tracking"]._description_selection(
self.env
)
).get(categ.restricted_tracking)
tracking_selection_dict = dict(
conflicting_products._fields["tracking"]._description_selection(
self.env
)
)
total_count = len(conflicting_products)
product_list = "\n".join(
[
"- %s (%s)"
% (
product.display_name,
tracking_selection_dict.get(product.tracking),
)
for product in conflicting_products[:10]
]
)
more_info = (
_("\n... and %s more product(s)", total_count - 10)
if total_count > 10
else ""
)
raise ValidationError(
_(
"Cannot set restricted tracking to '%(tracking)s' because "
"%(count)s product(s) in this category have different "
"tracking:\n%(products)s%(more)s",
tracking=tracking_label,
count=total_count,
products=product_list,
more=more_info,
)
)
31 changes: 31 additions & 0 deletions product_restricted_tracking/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2026 Quartile (https://www.quartile.co)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, models
from odoo.exceptions import ValidationError


class ProductTemplate(models.Model):
_inherit = "product.template"

@api.constrains("tracking", "categ_id")
def _check_tracking_matches_category(self):
tracking_dict = dict(self._fields["tracking"]._description_selection(self.env))
for product in self:
if (
product.categ_id.restricted_tracking
and product.tracking != product.categ_id.restricted_tracking
):
raise ValidationError(
_(
"Product '%(product)s' has tracking '%(tracking)s' but is "
"assigned to category '%(category)s' which requires "
"tracking '%(required_tracking)s'.",
product=product.display_name,
tracking=tracking_dict.get(product.tracking),
category=product.categ_id.display_name,
required_tracking=tracking_dict.get(
product.categ_id.restricted_tracking
),
)
)
5 changes: 5 additions & 0 deletions product_restricted_tracking/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
To configure this module:

1. Go to *Inventory > Configuration > Product Categories*
2. Select a category and set a *Restricted Tracking* value (Serial Number, Lot, or None)
3. When creating or editing products in this category, only the allowed tracking method can be selected
3 changes: 3 additions & 0 deletions product_restricted_tracking/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Quartile \<<https://www.quartile.co>\>
- Aung Ko Ko Lin
- Sanami Koshita
3 changes: 3 additions & 0 deletions product_restricted_tracking/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module adds a 'restricted_tracking' field to the product category model.
With this optional selection field, you can enforce that all products in a
category must use a specific tracking method (Serial Number, Lot, or None).
Loading
Loading