Metadata-Version: 2.1
Name: odoo-addon-product_class
Version: 19.0.1.0.0.2
Requires-Dist: odoo==19.0.*
Summary: Product classification and attribute constraints
Home-page: https://github.com/OCA/product-attribute
License: AGPL-3
Author: Camptocamp, Odoo Community Association (OCA)
Author-email: support@odoo-community.org
Classifier: Programming Language :: Python
Classifier: Framework :: Odoo
Classifier: Framework :: Odoo :: 19.0
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
Description-Content-Type: text/x-rst

.. image:: https://odoo-community.org/readme-banner-image
   :target: https://odoo-community.org/get-involved?utm_source=readme
   :alt: Odoo Community Association

=============
Product Class
=============

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

.. |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//product_class
    :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-/product-attribute--product_class
    :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=
    :alt: Try me on Runboat

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

Product Class
-------------

This module introduces **Product Classes** for standardizing product
setup and attribute management. It allows you to:

1. **Define Product Classes** — Group related products into classes
   (e.g., "Furniture", "Electronics")
2. **Constrain Attributes per Class** — Specify which attributes are
   allowed for each class
3. **Mark Required Attributes** — Designate certain attributes as
   mandatory for products in that class
4. **Enforce Validation** — Prevent products from using attributes
   outside their class or missing required attributes

Key Features
~~~~~~~~~~~~

- **Bridge Model (``product.class.attribute.line``)** — Manages the
  relationship between classes and attributes, storing both allowed
  attributes and a ``required`` flag
- **Strict Validation** — Products assigned to a class must:

  - Use only attributes defined in that class
  - Provide values for all required attributes

- **UI Enforcement** — Attribute selection in product forms is
  restricted by the class domain filter
- **Management Views** — Full CRUD interface for product classes
  (Inventory > Configuration > Product Classes, Sales > Configuration >
  Product Classes)

Technical Architecture
~~~~~~~~~~~~~~~~~~~~~~

- ``product.class`` — Main product classification model
- ``product.class.attribute.line`` — Bridge model linking classes to
  attributes with a ``required`` flag
- ``product.attribute`` (inherited) — Extended with reverse one-to-many
  to track which classes use it
- ``product.template`` (inherited) — Added class validation and computed
  required-attribute tracking

**Table of contents**

.. contents::
   :local:

Usage
=====

Usage
-----

1. Create a Product Class
~~~~~~~~~~~~~~~~~~~~~~~~~

**Navigation:** Inventory → Configuration → Product Classes (or Sales →
Configuration → Product Classes)

1. Click **Create** button

2. Enter a **Product Class Name** (e.g., "Chairs")

3. In the **Attributes** section:

   - Click **Add a line**
   - Select an **Attribute** from the dropdown
   - Check **Required** if products of this class must define this
     attribute
   - Repeat to add more attributes

4. Click **Save**

**Example: "Furniture" Class**

========= ======== ================================
Attribute Required Notes
========= ======== ================================
Color     ✓        All furniture must have a color
Size      ✓        Sizes vary by product
Material           Optional (not all items specify)
Finish             Optional polish/coating
========= ======== ================================

2. Assign a Product to a Class
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**Navigation:** Inventory → Products → Products

1. Create or edit a product
2. Find the **Product Class** field in the Attributes & Variants tab
   (added by this module)
3. Select the class (e.g., "Furniture")
4. The form will now restrict **Attributes** to only those allowed by
   the class

3. Add Attribute Lines to a Classed Product
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Once a class is selected, you can add attribute lines:

1. Go to the **Attributes & Variants** tab
2. In **Attribute Lines**, click **Add a line**
3. The **Attribute** field dropdown is now filtered to show only
   class-allowed attributes
4. Select an attribute and provide values
5. **Validation will fail if:**

   - You select an attribute not in the class → Error: "has attribute
     lines that do not belong"
   - You leave out a required attribute → Error: "is missing required
     attributes"

4. Remove an Attribute from a Class
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**Scenario:** Your "Furniture" class allowed "Color" but wants to retire
it.

1. Navigate to the class
2. In **Attributes**, find the "Color" line and delete it
3. **Odoo will raise an error if products in this class still use
   Color**

   - Fix: Remove Color from all products in the class first, then retry
     the class update

Workflow Example
~~~~~~~~~~~~~~~~

**Step 1: Set Up "Chairs" Class**

- Color (required)
- Size (required)
- Leg Material (optional)

**Step 2: Create a "Wooden Chair" Product**

- Assign class: "Chairs"
- Add attribute "Color" = Red (satisfies required)
- Add attribute "Size" = Large (satisfies required)
- Add attribute "Leg Material" = Oak (optional, still valid)
- **Save** ✓ Success

**Step 3: Try Invalid Assignment**

- Assign class: "Chairs"
- Add attribute "Color" = Blue (satisfies required)
- **Try to save without Size** → Error: "is missing required attributes
  for the selected class 'Chairs': Size"
- Add Size = Medium
- **Save** ✓ Success

Class Attribute Line Model
~~~~~~~~~~~~~~~~~~~~~~~~~~

The bridge model ``product.class.attribute.line`` stores:

============ ======== ========================================
Field        Type     Purpose
============ ======== ========================================
class_id     Many2one Product class (required, cascade delete)
attribute_id Many2one Product attribute (required)
required     Boolean  If true, products must define it
============ ======== ========================================

**Constraint:** A class cannot configure the same attribute twice
(unique on class_id + attribute_id).

Constraints & Validations
~~~~~~~~~~~~~~~~~~~~~~~~~

1. **Class Constraint** (``_check_attribute_ids_used_by_products``)

   - Prevents removing an attribute from a class if products still use
     it
   - Error: "Cannot remove attributes used in products assigned to
     class..."

2. **Product Constraint** (``_check_class_attributes``)

   - Ensures all attribute lines belong to the class
   - Ensures all required attributes are defined
   - Error: "Product '...' has attribute lines that do not belong to the
     selected class '...'"
   - Error: "Product '...' is missing required attributes for the
     selected class '...'"

Advanced: Access Control
~~~~~~~~~~~~~~~~~~~~~~~~

- **User (base.group_user):** Can create/read/write product classes and
  their attributes
- **System/Admin (base.group_system):** Full CRUD including delete

Product class attribute lines follow the same access rules.

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_class%0Aversion:%20%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
-------

* Camptocamp

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-Ricardoalso| image:: https://github.com/Ricardoalso.png?size=40px
    :target: https://github.com/Ricardoalso
    :alt: Ricardoalso
.. |maintainer-ivantodorovich| image:: https://github.com/ivantodorovich.png?size=40px
    :target: https://github.com/ivantodorovich
    :alt: ivantodorovich

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

|maintainer-Ricardoalso| |maintainer-ivantodorovich| 

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

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
