githubEdit

Business Logic Functions

Functions for lookups, PO matching, tasks, user/group management, and status changes.

Source: module/script/helper/document_script_functions.py


get_lookup_records()

Queries master data from lookup tables (suppliers, items, GL accounts, etc.).

get_lookup_records(org_id, sub_org_id, lookup_name, filters, **kwargs)

Parameters:

Name
Type
Description

org_id

str

Organization UUID

sub_org_id

str/None

Sub-organization UUID (or None)

lookup_name

str

Name of the lookup (e.g., "supplier", "item", "gl_account")

filters

list

Filter conditions (see formats below)

skip

int

Offset for pagination (default: 0)

limit

int

Max results (default: 100)

match_all

bool

True = AND, False = OR (default: True)

sort_order

list

Sorting (optional)

Filter Formats

Three formats are supported:

Sorting

Example — Lookup supplier by vendor ID:

Example — Search GL accounts with multiple filters:

circle-info

Internally uses search_operator="SMART" which supports fuzzy matching.


is_supplier_valid()

Checks if a supplier exists in the lookup data.

Parameters:

Name
Type
Description

user

UserAuthentication

The user context object

filter_data_json

dict

Filter in format {"match_all": True, "filters": [...]}

sub_org_id

str/None

Sub-organization

Returns: True if at least 1 match, otherwise False

Example — Validate supplier:


auto_po_match_for_purchase_orders()

Triggers automatic PO matching via the po-match-service microservice.

Parameters:

Name
Type
Description

user

UserAuthentication

Must be a real user object

document_data

dict

Document context

po_numbers

str/list

PO numbers (comma-separated or list)

Returns: Updated document_data with po_items, po_match_status, po_multi_matched

Example — Auto-match PO:

circle-exclamation

get_next_sequence_number()

Gets and atomically increments a sequence number in the database.

Parameters:

Name
Type
Description

org_id

str

Organization UUID

sequence_name

str

Must contain "sequence" (e.g., "invoice_sequence")

default_value

int

Start value when sequence is newly created

Returns: int — the next number, or None if name is invalid

Example — Generate internal document number:

triangle-exclamation

create_document_task()

Creates a task for the current document.

Parameters:

Name
Type
Description

user

UserAuthentication

User context

title

str

Task title

description

str

Description

priority

str/int

Priority

assigned_to_user_id

str/None

Assigned user

assigned_to_group_id

str/None

Assigned group

send_email

bool

Send email notification

Example — Create task for high-amount invoices:


set_document_sub_org_id()

Assigns a sub-organization to a document.

Side effects:

  • Sets sub_org_id in document_json

  • Saves directly to the database (if doc_id is present)

Example — Route based on supplier:


update_document_status_with_doc_id()

Changes the status of a document.

Parameters:

Name
Type
Description

doc_id

str

Document UUID

status

str

New status (e.g., "error", "ready_for_validation")

message

str/None

Status message

doc_classification_class

str/None

For CLASSIFIED status: new document type

Example — Set document to error status:

circle-exclamation

get_document_content()

Returns the full OCR text of the document.

Returns: str — Concatenated text of all pages

Example — Search fulltext for keywords:

circle-info

The result is cached for 60 seconds (TTL cache with max 128 entries).


get_user_by_id() / get_user_by_email()

Looks up a user by ID or email.

Returns: UsersCache object with attributes like .email, .first_name, .last_name, .user_id

Example — Assign task to specific user:


get_group_by_id() / get_group_by_name()

Looks up a user group by ID or name.

Returns: GroupCache object

Example — Find group for task assignment:


compare_values()

Intelligent value comparison with type conversion.

Comparison logic:

  1. None == NoneTrue

  2. None != non-NoneFalse

  3. Strings that are numbers → numeric comparison ("1.0" == "1.00"True)

  4. Strings → case-insensitive, space-insensitive ("ABC " == " abc"True)

  5. Bool vs String → string comparison (True == "true"True)

  6. Decimal comparison as fallback

Example — Verify amounts match:


get_lov_values()

Retrieves List-of-Values (LOV) entries.

Parameters:

Name
Type
Description

org_id

str

Organization UUID

key

str

LOV key

return_type

str

"list_of_objects" or "list_of_values"

sub_org_id

str/None

Optional sub-organization filter

language_code

str

Language code (e.g., "en", "de")

Returns: LOV values as a list of objects or as a flat list.

Example — Get configured tax codes:

Last updated

Was this helpful?