OdooWiki OCA HUB

Product Attribute Value Dependent Mixin

product_attribute_value_dependent_mixin folder_open OCA/product-attribute open_in_new
Product License: AGPL-3

This technical module introduces a reusable mixin designed to enable any model to establish dependencies on specific product attribute values. By inheriting from this mixin, developers can easily link business rules, configurations, or records to precise product variants without duplicating complex filtering logic.

auto_awesome What this module does

AI-generated from the code · Odoo 18.0

Technical building block that lets other Odoo models store a product template, a specific variant and a set of product attribute values, and automatically narrow the choices shown to the user. It adds no menu or screen by itself.

This is a technical module: it does not add any menu, button or report that a user can open directly. Instead, it provides a reusable base (a mixin) that other modules can plug into their own records.

When a model uses it, each record gains: - a Product Template field and a Product field (the specific variant); - an Attribute Values field where several product attribute values (for example colour or size values) can be selected; - two helper fields that are computed automatically and are not meant to be edited by hand.

Automatic behaviour: - As soon as a product template is chosen, the list of selectable product variants is restricted to the variants that really exist for that template. - In the same way, the list of selectable attribute values is restricted to the values actually used by that template's attribute lines. - A helper method checks whether a given product matches the record: it matches when the stored variant is that product, when the template is the same, and when the selected attribute values are all present on the product's variant attributes.

It touches the product template, product variant and product attribute value data. Because it is abstract, installing it alone changes nothing visible in the interface; its value appears only in modules that inherit from it.

Depends on

product

Required by other modules

Models and fields (1)
  • attribute.value.dependent.mixin · new modelproduct_id, product_tmpl_id (Product Template), attribute_value_ids (Attribute Values), available_product_domain, available_attribute_value_domain

Text generated by AI (DeepSeek) from reading the Odoo 18.0 code on GitHub; it may contain mistakes, so check the code before deciding. View the code on GitHub

Availability by version

Reviewed: 2026-11-03
Confirmed (verified in repository and branch) Estimated (unverified) No information

Confirmation status: 2 confirmed, 7 with no information of 9 versions.

Sources · Odoo 18.0

Confirmed on 2026-11-03 in branch 18.0 of OCA/product-attribute.

terminal Installation and usage

OCA documentation · Odoo 18.0

Fields

The mixin exposes the following fields:

  • product_tmpl_id: the product template to filter on (optional).
  • product_id: a specific product variant (optional).
  • attribute_value_ids: a set of attribute values to filter on (optional).
  • available_product_domain: a computed domain to restrict the selection of product_id in views, based on product_tmpl_id.
  • available_attribute_value_domain: a computed domain to restrict the selection of attribute_value_ids in views, based on product_tmpl_id.

Inheriting the Mixin

To use this mixin, inherit from attribute.value.dependent.mixin in your model alongside your base model:

from odoo import fields, models


class MyModel(models.Model):
    _name = "my.model"
    _inherit = ["my.model", "attribute.value.dependent.mixin"]

All fields from the mixin (product_tmpl_id, product_id, attribute_value_ids, available_product_domain, available_attribute_value_domain) are automatically available on your model.

Using the Domain Fields in a Form View

The computed domain fields must be referenced in the domain attribute of the corresponding fields in the view. Odoo 18.0 automatically loads fields referenced in domain attributes, so no additional declaration is needed.

<record id="view_my_model_form" model="ir.ui.view">
    <field name="name">my.model.form</field>
    <field name="model">my.model</field>
    <field name="arch" type="xml">
        <form>
            <group>
                <field name="product_tmpl_id"/>
                <field name="product_id"
                       domain="available_product_domain"
                       context="{'default_product_tmpl_id': product_tmpl_id}"/>
                <field name="attribute_value_ids"
                       domain="available_attribute_value_domain"
                       widget="many2many_tags"/>
            </group>
        </form>
    </field>
</record>

Matching Logic

The is_matching_product(product) method validates whether a given product variant satisfies the configured constraints. All fields are optional and act as independent filters combined with AND logic:

  • If product_id is set, it is the most restrictive criterion: the method returns True only if the given product is exactly that variant, regardless of other fields.
  • If product_tmpl_id is set, the given product must belong to that template.
  • If attribute_value_ids is set, the given product must match the configured attribute values with the following logic:
  • Values belonging to the same attribute are combined with OR (e.g. size S or M).
  • Values belonging to different attributes are combined with AND (e.g. size S or M and color Red).
  • Since an attribute value can exist across multiple templates, product_tmpl_id and attribute_value_ids should be used together to avoid unintended matches across templates.
  • If no field is set, the method returns True for any product (no constraint).

Using is_matching_product

The is_matching_product(product) method can be called from Python code to check whether a given product.product record satisfies the constraints defined on a mixin record:

for rule in self.env["my.model"].search([]):
    if rule.is_matching_product(product):
        # apply rule

No verified information in OCA: Installation, Configuration.

info

Data imported from GitHub: this sheet reflects the latest catalog review, not a live lookup. Always check the module documentation and staging before installing in production.