Built-ins
BehaviorActionDefinition
Register an action that a form rule can run against a draft.
A layout stores a BehaviorAction declaration that refers to this definition by ID. The caller checks field access and eligibility, validates the options, and calls the executor. The result can update draft values and presentation state or show messages.
| Setting | Type | Default | Description |
|---|---|---|---|
id | str | Required | Stable ID stored in the layout's action declaration. |
documentation | str | '' | Markdown and tagged examples included in the generated developer reference. |
label | str | Promise | Required | Name shown when choosing the action in the form editor. |
description | str | Promise | Required | Short explanation of what the action does. |
requires_target_field | bool | Required | Whether the rule author must select a target field. |
execute | Callable[[BehaviorContext, Mapping[str, Any], AbstractBaseUser | AnonymousUser], BehaviorResult] | Required | Callback that receives the draft, validated options, and user, and returns form updates. |
config_form_factory | Callable[[ApplicationField | None, ApplicationField | None, HttpRequest | None], type[Form]] | empty_config_form_factory | Builds the Django options form for the selected target, listener, and optional request. |
config_forms_for_docs | Mapping[str, Callable[[], type[Form] | Form]] | {} | Named ways to build the options form without live model fields for documentation. Use an empty name for a single configuration. Omit when the normal factory can run without context. |
get_listener_fields | Callable[[QuerySet], QuerySet] | all_listener_fields | Narrows the caller's queryset to fields that can trigger this action. |
get_target_fields | Callable[[QuerySet, ApplicationField | None], QuerySet] | all_target_fields | Narrows the caller's queryset to suitable targets for the selected listener. |
group | str | Promise | 'Default' | Category used to group the action in the form editor. |
Add an action that trims a draft value
Use the selected listener’s string value to update a text target. The layout supplies the listener and target fields.
from bloomerp.form_behaviors.definition import (
BehaviorActionDefinition,
BehaviorContext,
BehaviorResult,
BehaviorUser,
CleanedConfigData,
FieldValueUpdate,
)
from bloomerp.form_behaviors.registry import ACTION_REGISTRY
def trim_text(
context: BehaviorContext,
config: CleanedConfigData,
user: BehaviorUser,
) -> BehaviorResult:
'''Copy the trimmed listener value to the target field.'''
value = context.listener_value
if not isinstance(value, str):
return BehaviorResult()
return BehaviorResult(
values=(FieldValueUpdate(field=context.target_field, value=value.strip()),)
)
trim_action = BehaviorActionDefinition(
id="example_trim_draft_text",
label="Trim draft text",
description="Copy text to another field and trim surrounding whitespace.",
requires_target_field=True,
execute=trim_text,
)
ACTION_REGISTRY.register(trim_action.id, trim_action)Add an action that only shows a message
A message action can run when a rule matches without a separate target field.
from bloomerp.form_behaviors.definition import (
BehaviorActionDefinition,
BehaviorContext,
BehaviorMessage,
BehaviorResult,
BehaviorUser,
CleanedConfigData,
)
from bloomerp.form_behaviors.registry import ACTION_REGISTRY
def show_review_note(
context: BehaviorContext,
config: CleanedConfigData,
user: BehaviorUser,
) -> BehaviorResult:
'''Return a reminder for the user reviewing the draft.'''
return BehaviorResult(
messages=(BehaviorMessage(type="info", message="Review the details before saving."),)
)
review_note = BehaviorActionDefinition(
id="example_review_note",
label="Show review note",
description="Show a review reminder on the form.",
requires_target_field=False,
execute=show_review_note,
)
ACTION_REGISTRY.register(review_note.id, review_note)Set field visibility
ID set_field_visibility
Show or hide the target field without changing its value or interaction state.
| Field | Value |
|---|---|
requires_target_field | True |
Hide the delivery address for pickup
Usage example
Listen to shipping_method and put this action in the rule that matches
pickup. Use a second rule with visible to show the address for delivery.
from bloomerp.form_behaviors.definition import BehaviorAction
action = BehaviorAction(
action="set_field_visibility",
target_field="delivery_address",
config={"visibility": "hidden"},
)Set field interaction
ID set_field_interaction
Enable or disable the target field without changing its value or visibility.
| Field | Value |
|---|---|
requires_target_field | True |
Disable the reference field on closed records
Usage example
Listen to status. Add this action to a rule that matches the closed
status to disable reference in the form.
from bloomerp.form_behaviors.definition import BehaviorAction
action = BehaviorAction(
action="set_field_interaction",
target_field="reference",
config={"interaction": "disabled"},
)Set value
ID set_value
Replace the target field value, including with an empty value.
| Field | Value |
|---|---|
requires_target_field | True |
Set a collection instruction for pickup
Usage example
Listen to shipping_method and run the action in a rule that matches
pickup. Use a text field for shipping_note.
from bloomerp.form_behaviors.definition import BehaviorAction
action = BehaviorAction(
action="set_value",
target_field="shipping_note",
config={"value": "Collect from the front desk"},
)Set relative date
ID set_relative_date
Set a date relative to today in whole days, or a datetime relative to now in whole minutes.
| Field | Value |
|---|---|
requires_target_field | True |
Suggest a due date two weeks from today
Usage example
Use an initial rule and target a date field. The offset is in days for a
date field and in minutes for a datetime field. The write policy fills an
empty due date.
from bloomerp.form_behaviors.definition import BehaviorAction
action = BehaviorAction(
action="set_relative_date",
target_field="due_date",
config={
"offset": 14,
"write_policy": "if_empty",
},
)Set related-row value
ID set_o2m_value
Copy each active row's source column or related accessor into a compatible column.
| Field | Value |
|---|---|
requires_target_field | True |
Copy product prices into invoice lines
Usage example
Use lines as the listener and target. Each row has a product relation
and a compatible numeric unit_price column. sales_price is a field on
the related product.
from bloomerp.form_behaviors.definition import BehaviorAction
action = BehaviorAction(
action="set_o2m_value",
target_field="lines",
config={
"from_column": "product",
"accessor": "sales_price",
"to_column": "unit_price",
},
)Populate dates from week
ID populate_week_dates
Generate five or seven dated rows from the source ISO week.
| Field | Value |
|---|---|
requires_target_field | True |
Plan the five working days of a week
Usage example
Listen to the week field delivery_week. Choose the one-to-many field
lines with a date column called planned_date. The rule only fills an
empty collection.
from bloomerp.form_behaviors.definition import BehaviorAction
action = BehaviorAction(
action="populate_week_dates",
target_field="lines",
config={
"source": "delivery_week",
"column": "planned_date",
"days": 5,
"write_policy": "if_empty",
},
)Copy field value
ID copy_field_value
Copy the listener or one field from its selected related record into the target.
| Field | Value |
|---|---|
requires_target_field | True |
Prefill the shipping contact name
Usage example
Use billing_contact_name as the listener. Both fields are text fields.
The write policy preserves an existing shipping contact name.
from bloomerp.form_behaviors.definition import BehaviorAction
action = BehaviorAction(
action="copy_field_value",
target_field="shipping_contact_name",
config={
"source": "listener",
"write_policy": "if_empty",
},
)Show message
ID show_message
Show a message to the form user.
| Field | Value |
|---|---|
requires_target_field | False |
Remind the user about a pickup requirement
Usage example
Listen to shipping_method and match pickup in the rule conditions. The
message appears in the form without a target field.
from bloomerp.form_behaviors.definition import BehaviorAction
action = BehaviorAction(
action="show_message",
config={
"type": "info",
"message": "Bring your order confirmation when collecting.",
},
)Increment o2m value
ID increment_o2m_value
Fill blank integer cells in a collection with sequential values.
| Field | Value |
|---|---|
requires_target_field | False |
Number new invoice lines
Usage example
Listen to the lines collection, which has an integer position column.
The action fills blank positions after the highest existing one.
from bloomerp.form_behaviors.definition import BehaviorAction
action = BehaviorAction(
action="increment_o2m_value",
config={"field": "position"},
)Calculate
ID calculate
Calculate numeric values or scalar date/datetime offsets (days for dates, minutes for datetimes) from a safe formula.
| Field | Value |
|---|---|
requires_target_field | True |
Sum invoice lines
Usage example
Use lines as the listener. Give the collection a numeric total column
and the draft a numeric invoice_total field.
from bloomerp.form_behaviors.definition import BehaviorAction
action = BehaviorAction(
action="calculate",
target_field="invoice_total",
config={"expression": "sum(lines.total)"},
)Clear value
ID clear_value
Clear the target using its field type's empty-value semantics.
| Field | Value |
|---|---|
requires_target_field | True |
Clear a stale delivery note
Usage example
Listen to shipping_method and run this action when the method changes.
Use an optional text field for delivery_note.
from bloomerp.form_behaviors.definition import BehaviorAction
action = BehaviorAction(
action="clear_value",
target_field="delivery_note",
)Transform text
ID transform_text
Apply a deterministic text normalization to the listener value.
| Field | Value |
|---|---|
requires_target_field | True |
Make a slug from a title
Usage example
Listen to the text field title and write its slug to the text field
slug. Use a separate target to preserve the original title.
from bloomerp.form_behaviors.definition import BehaviorAction
action = BehaviorAction(
action="transform_text",
target_field="slug",
config={"transformation": "slug"},
)Fetch
ID fetch
Find accessible records with filters and copy one value or populate collection rows.
| Field | Value |
|---|---|
requires_target_field | True |
Find a work order by name
Usage example
Listen to work_order_name. The target work_order is a relation to
orders.WorkOrder. The filter uses the current draft name and finds
records the user can read.
from bloomerp.form_behaviors.definition import BehaviorAction
action = BehaviorAction(
action="fetch",
target_field="work_order",
config={
"model": "orders.workorder",
"value_source": "record",
"fetch": "first",
"order_by": "name",
"filters": [
{
"connector": "AND",
"conditions": [
{
"field_path": "name",
"lookup_id": "equals",
"value": "{{ object.work_order_name }}",
}
],
}
],
},
)Set user field to current user
ID set_user_field_to_current_user
Set the selected user field to the authenticated user evaluating the form.
| Field | Value |
|---|---|
requires_target_field | True |
Assign a new record to its creator
Usage example
Use this action in an initial rule on a create form that requires login.
Target a user field such as assigned_to.
from bloomerp.form_behaviors.definition import BehaviorAction
action = BehaviorAction(
action="set_user_field_to_current_user",
target_field="assigned_to",
)