Policy Mixin
Description
Policy Mixin is a core mixin module in the
@simetri-sinergi-id/ssi-mixin technology suite for Odoo 15.
It provides a reusable abstract model — mixin.policy —
that implements a policy-template mechanism for controlling which
action buttons are available on a document at any given time.
Each inheriting model declares boolean policy fields (e.g. confirm_ok,
cancel_ok) via _get_policy_field and links to a
policy.template that evaluates Python conditions against the current
record to set those fields automatically.
-
policy.template — master-data record holding Python evaluation code
(matching criteria) and ordered detail lines.
-
policy.template.detail — maps a policy field to its computed value
for records that match the template.
-
action_reload_policy_template — manually re-selects the active
template based on the record's current state.
Key Features
- Abstract Mixin Design: Inherit
mixin.policy in any transactional model — no structural changes required.
- Policy Template Resolution: Automatically selects the correct
policy.template based on model and matching criteria.
- Python-Based Conditions: Template detail lines evaluate arbitrary Python expressions against the current record.
- Dynamic Button Visibility: Boolean policy fields are recomputed whenever the policy template is reloaded.
- Company-Scoped Templates: Each template is scoped to a company, allowing multi-company policy configurations.
- Reload Action:
action_reload_policy_template allows manual policy re-evaluation from the form view.
- Open Source: AGPL-3.0 license with community-driven improvements.
Use Cases / Context
Use this mixin for any transactional document where button availability depends on configurable business rules:
- Sales / Purchase Orders: Control which approval or cancellation buttons appear based on order state and amount.
- HR Leave / Attendance: Allow or deny actions depending on employee type or leave balance.
- Warehouse Transfers: Restrict validate/cancel based on stock availability or user role.
- Accounting Documents: Fine-grained control over posting, resetting, and cancellation of journal entries.
- Any Stateful Document: Any model with states that needs configurable per-state button policies.
Simply set _inherit = ["mixin.policy"] on your model and define your policy fields and templates via the UI.
Installation & Usage
- Clone branch 15.0 of the repository: https://github.com/simetri-sinergi-id/ssi-mixin
- Add the path to this repository in your Odoo configuration (
addons-path).
- Update the module list (ensure you are in developer mode).
- Go to Apps → Apps → Main Apps, search for Policy Mixin, and install.
- In your custom model:
_inherit = ["mixin.policy"]
- Declare your policy fields via
_get_policy_field() and configure policy.template records through the UI.
FAQ
-
Standalone?
No — it is a mixin foundation. Install it as a dependency of your custom module.
-
Odoo Version?
Odoo 15.0.
-
Multiple templates per model?
Yes — templates have matching criteria (Python conditions) and only the first matching template applies to a given record.
-
Can templates differ per company?
Yes — each policy template is scoped to a company, enabling multi-company policy configurations.
-
Contribute?
Fork, branch, and submit a pull request on GitHub.
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 smash it by providing detailed and welcomed feedback.
Credits & Contributors
This module is developed and maintained by PT. Simetri Sinergi Indonesia.
- Core Development:
- Maintenance: PT. Simetri Sinergi Indonesia
- Special Thanks: To the Odoo Community Association (OCA) for the development guidelines and best practices.