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:
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:
Internally uses search_operator="SMART" which supports fuzzy matching.
is_supplier_valid()
Checks if a supplier exists in the lookup data.
Parameters:
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:
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:
Duplicate protection: Already verified PO numbers are stored in already_verified_po_numbers and will not be matched again.
get_next_sequence_number()
Gets and atomically increments a sequence number in the database.
Parameters:
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:
Naming rule: The sequence_name must start or end with "sequence", or contain "SEQUENCE_". Otherwise the function returns None.
create_document_task()
Creates a task for the current document.
Parameters:
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_idindocument_jsonSaves directly to the database (if
doc_idis present)
Example — Route based on supplier:
update_document_status_with_doc_id()
Changes the status of a document.
Parameters:
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:
Caution: Status changes trigger downstream actions (DocFlow workflows, status-change hooks). Only use when necessary.
get_document_content()
Returns the full OCR text of the document.
Returns: str — Concatenated text of all pages
Example — Search fulltext for keywords:
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:
None == None→TrueNone != non-None→FalseStrings that are numbers → numeric comparison (
"1.0" == "1.00"→True)Strings → case-insensitive, space-insensitive (
"ABC " == " abc"→True)Bool vs String → string comparison (
True == "true"→True)Decimal comparison as fallback
Example — Verify amounts match:
get_lov_values()
Retrieves List-of-Values (LOV) entries.
Parameters:
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?