BloomERP

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.

SettingTypeDefaultDescription
idstrRequiredStable ID stored in the layout's action declaration.
documentationstr''Markdown and tagged examples included in the generated developer reference.
labelstr | PromiseRequiredName shown when choosing the action in the form editor.
descriptionstr | PromiseRequiredShort explanation of what the action does.
requires_target_fieldboolRequiredWhether the rule author must select a target field.
executeCallable[[BehaviorContext, Mapping[str, Any], AbstractBaseUser | AnonymousUser], BehaviorResult]RequiredCallback that receives the draft, validated options, and user, and returns form updates.
config_form_factoryCallable[[ApplicationField | None, ApplicationField | None, HttpRequest | None], type[Form]]empty_config_form_factoryBuilds the Django options form for the selected target, listener, and optional request.
config_forms_for_docsMapping[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_fieldsCallable[[QuerySet], QuerySet]all_listener_fieldsNarrows the caller's queryset to fields that can trigger this action.
get_target_fieldsCallable[[QuerySet, ApplicationField | None], QuerySet]all_target_fieldsNarrows the caller's queryset to suitable targets for the selected listener.
groupstr | 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.

python
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.

python
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.

FieldValue
requires_target_fieldTrue

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.

python
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.

FieldValue
requires_target_fieldTrue

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.

python
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.

FieldValue
requires_target_fieldTrue

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.

python
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.

FieldValue
requires_target_fieldTrue

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.

python
from bloomerp.form_behaviors.definition import BehaviorAction

action = BehaviorAction(
    action="set_relative_date",
    target_field="due_date",
    config={
        "offset": 14,
        "write_policy": "if_empty",
    },
)

ID set_o2m_value

Copy each active row's source column or related accessor into a compatible column.

FieldValue
requires_target_fieldTrue

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.

python
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.

FieldValue
requires_target_fieldTrue

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.

python
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.

FieldValue
requires_target_fieldTrue

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.

python
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.

FieldValue
requires_target_fieldFalse

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.

python
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.

FieldValue
requires_target_fieldFalse

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.

python
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.

FieldValue
requires_target_fieldTrue

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.

python
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.

FieldValue
requires_target_fieldTrue

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.

python
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.

FieldValue
requires_target_fieldTrue

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.

python
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.

FieldValue
requires_target_fieldTrue

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.

python
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.

FieldValue
requires_target_fieldTrue

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.

python
from bloomerp.form_behaviors.definition import BehaviorAction

action = BehaviorAction(
    action="set_user_field_to_current_user",
    target_field="assigned_to",
)