Frappe.db.sql not work in workflow condition


i try to write this condition to check the balance before submit in draft status
but i get this error

App Versions

{
	"erpnext": "15.20.3",
	"frappe": "15.22.0",
	"hrms": "15.17.0"
}

Route

Form/Sales Invoice/new-sales-invoice-mgjdcawevc

Traceback

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 110, in application
    response = frappe.api.handle(request)
  File "apps/frappe/frappe/api/__init__.py", line 49, in handle
    data = endpoint(**arguments)
  File "apps/frappe/frappe/api/v1.py", line 36, in handle_rpc_call
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 49, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 85, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1718, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
    return func(*args, **kwargs)
  File "apps/frappe/frappe/model/workflow.py", line 68, in get_transitions
    if not is_transition_condition_satisfied(transition, doc):
  File "apps/frappe/frappe/model/workflow.py", line 95, in is_transition_condition_satisfied
    return frappe.safe_eval(transition.condition, get_workflow_safe_globals(), dict(doc=doc.as_dict()))
  File "apps/frappe/frappe/__init__.py", line 2322, in safe_eval
    return safe_eval(code, eval_globals, eval_locals)
  File "apps/frappe/frappe/utils/safe_exec.py", line 122, in safe_eval
    return eval(
  File "<safe_eval>", line 1, in <module>
TypeError: 'NoneType' object is not callable

Request Data

{
	"type": "POST",
	"args": {
		"doc": "{\"name\":\"ACC-SINV-2024-00014\",\"owner\":\"Administrator\",\"creation\":\"2024-04-16 15:13:08.234110\",\"modified\":\"2024-04-16 15:13:23.366905\",\"modified_by\":\"Administrator\",\"docstatus\":0,\"idx\":0,\"workflow_state\":\"Write\",\"title\":\"naser\",\"naming_series\":\"ACC-SINV-.YYYY.-\",\"customer\":\"naser\",\"customer_name\":\"naser\",\"company\":\"Test (Demo)\",\"posting_date\":\"2024-04-16\",\"posting_time\":\"15:13:23.455065\",\"set_posting_time\":0,\"due_date\":\"2024-04-16\",\"is_pos\":0,\"is_consolidated\":0,\"is_return\":0,\"update_outstanding_for_self\":1,\"update_billed_amount_in_sales_order\":0,\"update_billed_amount_in_delivery_note\":1,\"is_debit_note\":0,\"currency\":\"YER\",\"conversion_rate\":1,\"selling_price_list\":\"Standard Selling\",\"price_list_currency\":\"YER\",\"plc_conversion_rate\":1,\"ignore_pricing_rule\":0,\"update_stock\":0,\"total_qty\":1,\"total_net_weight\":0,\"base_total\":100,\"base_net_total\":100,\"total\":100,\"net_total\":100,\"tax_category\":\"\",\"base_total_taxes_and_charges\":0,\"total_taxes_and_charges\":0,\"base_grand_total\":100,\"base_rounding_adjustment\":0,\"base_rounded_total\":100,\"base_in_words\":\"YER One Hundred only.\",\"grand_total\":100,\"rounding_adjustment\":0,\"use_company_roundoff_cost_center\":0,\"rounded_total\":100,\"in_words\":\"YER One Hundred only.\",\"total_advance\":0,\"outstanding_amount\":100,\"disable_rounded_total\":0,\"apply_discount_on\":\"Grand Total\",\"base_discount_amount\":0,\"is_cash_or_non_trade_discount\":0,\"additional_discount_percentage\":0,\"discount_amount\":0,\"total_billing_hours\":0,\"total_billing_amount\":0,\"base_paid_amount\":0,\"paid_amount\":0,\"base_change_amount\":0,\"change_amount\":0,\"allocate_advances_automatically\":0,\"only_include_allocated_payments\":0,\"write_off_amount\":0,\"base_write_off_amount\":0,\"write_off_outstanding_amount_automatically\":0,\"redeem_loyalty_points\":0,\"loyalty_points\":0,\"loyalty_amount\":0,\"company_address\":\"\",\"company_address_display\":\"\",\"ignore_default_payment_terms_template\":0,\"po_no\":\"\",\"debit_to\":\"1310 - Debtors - TD\",\"party_account_currency\":\"YER\",\"is_opening\":\"No\",\"against_income_account\":\"4110 - Sales - TD\",\"amount_eligible_for_commission\":100,\"commission_rate\":0,\"total_commission\":0,\"letter_head\":\"test\",\"group_same_items\":0,\"language\":\"en\",\"status\":\"Draft\",\"is_internal_customer\":0,\"is_discounted\":0,\"remarks\":\"No Remarks\",\"repost_required\":0,\"doctype\":\"Sales Invoice\",\"sales_team\":[],\"timesheets\":[],\"payments\":[],\"packed_items\":[],\"items\":[{\"name\":\"ff964d1420\",\"owner\":\"Administrator\",\"creation\":\"2024-04-16 15:13:08.234110\",\"modified\":\"2024-04-16 15:13:23.366905\",\"modified_by\":\"Administrator\",\"docstatus\":0,\"idx\":1,\"has_item_scanned\":0,\"item_code\":\"SKU005\",\"item_name\":\"Sneakers\",\"description\":\"Sneakers\",\"item_group\":\"Demo Item Group\",\"image\":\"https://images.pexels.com/photos/1598505/pexels-photo-1598505.jpeg\",\"qty\":1,\"stock_uom\":\"Nos\",\"uom\":\"Nos\",\"conversion_factor\":1,\"stock_qty\":1,\"price_list_rate\":100,\"base_price_list_rate\":100,\"margin_type\":\"\",\"margin_rate_or_amount\":0,\"rate_with_margin\":0,\"discount_percentage\":0,\"discount_amount\":0,\"base_rate_with_margin\":0,\"rate\":100,\"amount\":100,\"base_rate\":100,\"base_amount\":100,\"pricing_rules\":\"\",\"stock_uom_rate\":100,\"is_free_item\":0,\"grant_commission\":1,\"net_rate\":100,\"net_amount\":100,\"base_net_rate\":100,\"base_net_amount\":100,\"delivered_by_supplier\":0,\"income_account\":\"4110 - Sales - TD\",\"is_fixed_asset\":0,\"expense_account\":\"5111 - Cost of Goods Sold - TD\",\"enable_deferred_revenue\":0,\"weight_per_unit\":0,\"total_weight\":0,\"use_serial_batch_fields\":0,\"allow_zero_valuation_rate\":0,\"incoming_rate\":523,\"item_tax_rate\":\"{}\",\"actual_batch_qty\":0,\"actual_qty\":0,\"delivered_qty\":0,\"cost_center\":\"Main - TD\",\"page_break\":0,\"parent\":\"ACC-SINV-2024-00014\",\"parentfield\":\"items\",\"parenttype\":\"Sales Invoice\",\"doctype\":\"Sales Invoice Item\"}],\"pricing_rules\":[],\"advances\":[],\"payment_schedule\":[{\"name\":\"70b28a8405\",\"owner\":\"Administrator\",\"creation\":\"2024-04-16 15:13:08.322112\",\"modified\":\"2024-04-16 15:13:23.366905\",\"modified_by\":\"Administrator\",\"docstatus\":0,\"idx\":1,\"due_date\":\"2024-04-16\",\"invoice_portion\":100,\"discount\":0,\"payment_amount\":100,\"outstanding\":100,\"paid_amount\":0,\"discounted_amount\":0,\"base_payment_amount\":100,\"parent\":\"ACC-SINV-2024-00014\",\"parentfield\":\"payment_schedule\",\"parenttype\":\"Sales Invoice\",\"doctype\":\"Payment Schedule\"}],\"taxes\":[],\"__onload\":{\"make_payment_via_journal_entry\":0},\"__last_sync_on\":\"2024-04-16T12:21:11.275Z\"}"
	},
	"headers": {},
	"error_handlers": {},
	"url": "/api/method/frappe.model.workflow.get_transitions",
	"request_id": null
}

Response Data

{
	"exception": "TypeError: 'NoneType' object is not callable",
	"exc_type": "TypeError"
}

You can’t use the sql because certain operations are restricted in safe_exec. and also mentioned allowed functions on the right side.

i read it but how could i check the balance in the workflow ?

use frappe.db.get_list and try your own way.

okey i will try it