Skip to main content
Odoo Community Association

Product Attribute Value Dependent Mixin

Beta License: AGPL-3 OCA/product-attribute Translate me on Weblate Try me on Runboat

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.

Table of contents

Usage

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

Bug Tracker

Bugs are tracked on GitHub 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.

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

Credits

Authors

  • Akretion

Contributors

Maintainers

This module is maintained by the OCA.

Odoo Community Association

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.

This module is part of the OCA/product-attribute project on GitHub.

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

Release files for odoo-addon-product-attribute-value-dependent-mixin 18.0.1.0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for odoo-addon-product-attribute-value-dependent-mixin 18.0.1.0.0.2
File Interpreter ABI Platform
odoo_addon_product_attribute_value_dependent_mixin-18.0.1.0.0.2-py3-none-any.whl Python 3 none any Details

Release files / odoo_addon_product_attribute_value_dependent_mixin-18.0.1.0.0.2-py3-none-any.whl

Download URL odoo_addon_product_attribute_value_dependent_mixin-18.0.1.0.0.2-py3-none-any.whl
Size 30.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2f91da8ee8709438f0d1bbf5722fe3add14d31f97676975704c47e247d3a01d4
BLAKE2b-256 checksum
How to use checksums
8cab7c07bfdfd7c53ce243e791b8403caac61a9130afd3d0a56f89834439e0ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

18.0.1.0.0.2 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page