Predictive Billing AI in Telecom/Energy Running on Oracle Solaris
In the Distributed Generation and recurring billing sector, customer default (both corporate and residential) is one of the main factors affecting operational cash flow. Identifying which customers are most likely to delay their invoice payments even before the due date allows for the automation of friendly reminders and preemptive renegotiations.
In this article, I detail the implementation of a predictive model based on the RandomForestClassifier algorithm, fed by a read-only extract from the SAP Business One ERP on the SAP HANA database, executed on a schedule within a robust Oracle Solaris UNIX environment.
Choice of Environment
Oracle Solaris is renowned for its stability and advanced virtualization features (like Solaris Zones). We kept the Python script running natively in an isolated zone on the same SAP HANA data subnet, to shorten the network path and limit who can reach the database. Sub-millisecond latency is not a property of the zone: it depends on the distance to the HANA host.
The Predictive Pipeline
The Python script performs the following key operations:
- Two extracts: training reads closed invoices (
DocStatus = 'C'). Scoring reads only open ones (DocStatus = 'O'). Both come fromOINV, through a read-only user. The training label for lateness comes from accounts receivable, not from the invoice header alone. - Feature Engineering: Grouping by variables of historical days late, current invoice value, and past punctuality.
- Classification via Machine Learning: A
RandomForestClassifierretrained periodically on the payment history. - Probability Calculator (Risk Score): For each open invoice, the probability of default (
predict_proba) is generated.
from sklearn.ensemble import RandomForestClassifier
# Model retrained periodically on paid and late invoice history
clf = RandomForestClassifier(n_estimators=100, random_state=42)
clf.fit(X_train, y_train)
risk_score = clf.predict_proba(X_open)[:, 1]
Extract on HANA, schedule in the zone
The classifier does not see OINV directly. A read-only user returns two slices, and the Solaris zone cron runs the score before business hours.
-- Training: invoices already closed. Real delay comes from the receipt, not this date.
SELECT "CardCode", "DocEntry", "DocTotal", "DocDueDate"
FROM "SBO_PROD"."OINV"
WHERE "DocStatus" = 'C';
-- Score: only what is still open.
SELECT "CardCode", "DocEntry", "DocTotal",
DAYS_BETWEEN("DocDueDate", CURRENT_DATE) AS "DelayDays"
FROM "SBO_PROD"."OINV"
WHERE "DocStatus" = 'O';
# Solaris zone crontab, 06:15
15 6 * * * /opt/billing/venv/bin/python /opt/billing/score_invoices.py
score_invoices.py writes only the CardCode and Risk_Score of invoices scoring above 0.85. The ERP sends the notice. The model does not need a route to the internet.
Business Integration
When the risk score exceeds the threshold configured for this case (85%), the ERP API sends a preventive notice by email or WhatsApp. On the portfolio I measured, accounts receivable improved by about 35%. That figure belongs to that book of invoices, not to the algorithm.
Related Articles
SAP Business One with SAP HANA on AWS: Architecture and Day-to-Day Operations
How to run SAP Business One on SAP HANA on AWS: instance, data and log volumes, port 30015, and backup. Power BI reads the replica, not production HANA.
Building a Local RAG Agent with Python, Ollama (Llama 3), and CPU
Local RAG on CPU with Python, LangChain, and Ollama (Llama 3): commands to pull the model, index documents, and keep data off the cloud.