Mixins
Contents
Mixins#
For: developers
OpenSPP provides several mixins that add common functionality to your models. Mixins are abstract models — you add them to your model's _inherit list to gain their fields and methods.
Available mixins#
Mixin |
Module |
Purpose |
|---|---|---|
|
|
Multi-tier approval workflows |
|
|
Data provenance tracking |
|
|
Conditionally disable form editing |
|
|
Link records to background jobs |
|
|
Record versioning with scheduled activation |
|
|
Consent management for data sharing |
|
|
Studio no-code configuration support |
|
|
CEL cache invalidation triggers |
|
|
Change request conflict detection |
Approval mixin#
The most commonly used mixin. Adds a multi-tier approval workflow to any model.
Usage#
class MyModel(models.Model):
_name = "spp.my.feature"
_inherit = ["mail.thread", "mail.activity.mixin", "spp.approval.mixin"]
Important
spp.approval.mixin requires mail.thread and mail.activity.mixin to be in the inherit list. The approval workflow uses mail activities to notify approvers.
What it provides#
approval_statefield with five values:draft(initial),pending(submitted),revision(changes requested),approved,rejectedapproval_review_ids— linked approval review recordsAction methods:
action_submit_for_approval(),action_approve(),action_reject(),action_request_revision(),action_reset_to_draft()Hook methods to override:
_on_submit(),_after_submit(),_on_approve(),_on_reject(reason),_on_request_revision(notes),_on_reset_to_draft()Integration with
spp.approval.definitionfor configuring who can approve
Adding to your module#
Add
spp_approvalto your manifest'sdependsAdd the mixin to your model's
_inheritAdd approval state fields to your form view
Configure an approval definition through the UI or data files
Source tracking mixin#
Tracks where data originated and how it was last updated. Useful for models that receive data from external sources (imports, APIs, field surveys).
Usage#
class MyModel(models.Model):
_name = "spp.my.feature"
_inherit = ["spp.mixin.source.tracking"]
What it provides#
Field |
Type |
Description |
|---|---|---|
|
Char |
Original source (immutable after create) |
|
Char |
External reference ID (immutable after create) |
|
Selection |
How data was collected ( |
|
Datetime |
When data was collected |
|
Char |
System that last updated the record |
|
Char |
External reference of the update |
The creation fields (source_system, source_reference) are set once on create and cannot be changed. Update fields (last_update_system, last_update_reference) are updated on each write.
Disable edit mixin#
Conditionally makes a form read-only based on a domain filter. Useful for preventing edits on records in certain states.
Usage#
class MyModel(models.Model):
_name = "spp.my.feature"
_inherit = ["spp.disable.edit.mixin"]
DISABLE_EDIT_DOMAIN = [("state", "=", "closed")]
When a record matches the DISABLE_EDIT_DOMAIN, the form view's edit button is hidden via injected CSS. This is a UI-level control, not a security mechanism — use record rules for actual access control.
Versioned mixin#
Adds record versioning with support for scheduled activation. Records can have future versions that automatically become active at a specified date.
Usage#
class MyModel(models.Model):
_name = "spp.my.feature"
_inherit = ["spp.versioned.mixin"]
Add spp_versioning to your manifest's depends.
Combining mixins#
Mixins can be combined as needed:
class MyModel(models.Model):
_name = "spp.my.feature"
_description = "My Feature"
_inherit = [
"mail.thread",
"mail.activity.mixin",
"spp.approval.mixin",
"spp.mixin.source.tracking",
"spp.disable.edit.mixin",
]
DISABLE_EDIT_DOMAIN = [("approval_state", "=", "approved")]
When combining mixins, make sure to add all their parent modules to your manifest's depends list.
openspp.org