One Dashboard from 1C and CSV, Built in Python

You export the sales report from 1C, open the CSV from the warehouse system next to it, and the totals differ by 4%. You spend the evening matching rows by hand, find that one file has the counterparty name written with a different legal form, and swear to automate it. This guide is the full build of that automation: one Python project that pulls CSV/XLSX exports and data from your ERP API, matches the reference dictionaries to a single key, computes the metrics, and publishes a page with charts that your manager opens in a browser — nothing to install on their machine.

By the end you will know exactly which steps the AI agent does and which checks stay with you, which keys and rights you need before the first line of code, where this kind of project actually breaks, and how to prove with a control sum that the dashboard tells the truth.

What appears at the end, and how you know it works

Picture a page at dash.yourcompany.com or on an internal server. On top: revenue by month, a bar chart by channel, a table of top counterparties. Below: the date and time of the last refresh and a small line — the control sum.

The control sum is the whole trick. It is the total from the source system, taken independently, versus the total the dashboard computed. If they match to the cent, the page is trustworthy. If they differ, the page shows the gap instead of hiding it. That single number turns the dashboard from a pretty picture into a tool a finance director will actually sign off on. More on the topic: “BI Analytics and Dashboards: What to Know Before You Start — Requirements, Pitfalls, and Real Practice”.

What the reader gets in human terms:

  • One page instead of three files. CSV from the warehouse, XLSX from the sales team, API from 1C/ERP — all in one model.
  • A refresh on a schedule, not a manual re-export at month-end.
  • A visible health signal — last refresh time and the control-sum check.
  • No installation for the viewer. A browser and a link. That is the whole requirement on their side.

What the viewer does not get: drill-down to a single invoice, role-based row filtering, or ad-hoc queries. Those are BI territory, and we will come back to that line.

First decide the scope: one script, an integration, or a product

Before the agent writes anything, answer one question honestly: who else will use this besides you?

If your case is… What fits What does not fit The deciding signal
You and two colleagues, monthly review One Streamlit script on a server A BI platform, a data warehouse The page is read, not queried
A department of 10–30 people, daily numbers Streamlit plus a scheduled refresh and a small database Manual re-runs Someone asks "why is it stale?"
Different people must see different rows A BI tool with row-level security A shared public link The word "confidential" appears in the request
Finance needs audit trails and versioned metrics A BI platform with a governed semantic layer A single Python file An auditor asks how a number was computed

The honest default for the first version is a single Streamlit app. Streamlit is a Python library that turns a script into a web page; you run streamlit run app.py and it serves a browser page. The model lives in the script, and the script is the documentation.

Build the control sum before the charts Write the reconciliation check first, on raw data, before any chart exists. If you build the visuals first, you will keep trusting a page whose numbers you have never proven.

Access and data you need before step one

This is where projects stall for a week. Collect these before asking the agent to code.

Files. The CSV and XLSX exports themselves, plus a note on how they are produced — a manual export from a menu, a scheduled job, an email attachment. Ask which encoding the export uses; 1C exports frequently come out in a Windows codepage rather than UTF-8, and that is a real failure point we will handle later.

API access. For 1C, the standard route is the HTTP service or OData published on the web server; the exact endpoints and authentication depend on your configuration and publication settings, so check the documentation for your version rather than guessing endpoint names. For other ERPs, ask for read-only credentials and the API base URL.

Rights. Read-only is enough for everything in this guide. Never ask for write access to the accounting system — a dashboard that can post documents is a liability.

Limits. Ask the admin: request rate limits, page size caps, and whether the API allows filtering by date. This determines whether you pull incrementally or in full.

Where access is impossible. If the ERP has no API and no one will publish one, you are left with scheduled file exports — a folder the system drops CSV into every night. That is a perfectly workable architecture; it just means the refresh is file-driven, not API-driven. If even scheduled exports are refused, the project stops here, and no amount of AI coding changes that.

The build, step by step, with an owner for each

Step 1. The data schema — AI drafts, you confirm the keys

The agent proposes a schema: one table of facts (transactions, amounts, dates, counterparty keys) and reference tables (counterparties, products, channels). You confirm the one thing it cannot know: which field is the stable key. The counterparty name is not a key. The tax ID or the internal code is.

Your check: open two source files and find the same entity in both. If the only shared field is a name spelled slightly differently, the schema is wrong.

Step 2. Normalization of the reference dictionaries — AI writes the matcher, you approve the unmatched list

The agent writes a normalization function and a manual mapping table. The normalizer does the mechanical part — trim, unify case, strip legal-form suffixes and quotes, keep the tax ID as the join key:

import re

LEGAL_FORMS = r"\b(llc|ltd|inc|gmbh|ooo|oao|zao|pjsc|jsc)\b"

def norm_name(s: str) -> str:
    s = s.lower().replace("ё", "е")
    s = re.sub(r"[«»\"'`]", "", s)
    s = re.sub(LEGAL_FORMS, "", s)
    s = re.sub(r"[^\w\s]", " ", s)
    return re.sub(r"\s+", " ", s).strip()

The manual mapping table is a plain CSV you edit by hand — one row per decision, with the reason recorded so the next person understands it:

source_system raw_name canonical_id tax_id decided_by note
warehouse ACME Trading LLC C-1042 7701234567 analyst legal form stripped
erp Acme Trading C-1042 7701234567 analyst matched by tax ID
warehouse ACME Trade C-2087 7709876543 analyst different entity, not a typo

A typical situation: the warehouse CSV says ACME Trading LLC, the ERP says Acme Trading. The normalizer handles that. But ACME Trading and ACME Trade may be two genuinely different legal entities — only a human knows, which is why the third row exists. Rule of thumb: automatic matching for exact and near-exact hits, a manual mapping table for the rest, and every unmatched row must be visible, not silently dropped.

Step 3. Loaders — AI writes the code, you watch the first real run

The agent writes functions that read CSV and XLSX, call the API, and land data in a local store. SQLite is enough for the first version; it is a single file, needs no server, and Streamlit reads it fine.

The human part: run it against real files, not samples. Watch what happens with the encoding, with a column that changed name, with an empty export. The first real run is where the agent's assumptions meet your data.

Step 4. Metrics — AI computes, you write the definition on paper

Before code, write one sentence per metric. Then check that the code does exactly that. "Revenue" is the classic trap because two people mean different things by it. A definition that survives review answers four questions explicitly:

  • Returns. Are credit notes subtracted, and on which date — the original sale date or the return date? State it: "revenue = posted sales minus posted returns, each on its own document date."
  • VAT. Inclusive or exclusive? Pick one and put it in the metric name, not in a footnote.
  • Currency. If documents are in more than one currency, name the rate source and the rate date (document date vs. month-end). Do not let the code choose.
  • Date boundaries. Half-open intervals: >= 2024-01-01 and < 2024-02-01. This avoids the classic double-count of a document dated the last day of the month.

The agent will implement whatever you say; if you say it vaguely, it will pick something plausible.

Step 5. Charts and page — AI builds, you check readability

Streamlit gives you charts in a few lines. Ask for the page a manager can read in five seconds: big numbers on top, trends below, the refresh timestamp and control sum in a footer.

Your check: show it to the actual manager. If they ask "what is this axis?", the chart is not done.

Step 6. Deploy — AI writes the config, you own the server and the secrets

The app needs a machine that stays on. A small virtual server with Python, the app running as a service, and a reverse proxy in front. The agent can draft the service unit and proxy config; you provision the server and put the API credentials in environment variables, never in the code.

Every step has a named owner The AI drafts and writes code at every step. The human owns the schema key, the unmatched list, the metric definitions, the readability check, and the server and secrets. A step with no human check is not done — it is just unverified.
Six steps, each ending in a human check before the next begins
1
Schema
AI drafts; you confirm the stable key
2
Dictionaries
AI matches; you approve unmatched rows
3
Loaders
AI codes; you run on real files
4
Metrics
AI computes; you write definitions
5
Charts
AI builds; manager checks readability
6
Deploy
AI drafts config; you own server and secrets

Where this breaks, and what to do about it

Broken encodings. A CSV that opens fine in Excel shows garbled characters in Python. 1C commonly writes Windows-1251, so read it explicitly and fail loudly if the decode is wrong instead of guessing silently: More on the topic: “Excel vs Python for Data Analysis: How to Choose the Right Tool”.

def read_1c_csv(path):
    for enc in ("utf-8-sig", "cp1251"):
        try:
            df = pd.read_csv(path, sep=";", encoding=enc, decimal=",")
            break
        except UnicodeDecodeError:
            continue
    else:
        raise ValueError(f"{path}: neither utf-8 nor cp1251 decoded cleanly")
    # verify a known value survived the decode
    assert df["Контрагент"].str.contains("ООО", na=False).any(), "decode looks wrong"
    return df

Note the separator and decimal comma too — 1C's export defaults differ from what read_csv assumes. If you do not know the encoding, detect it and log what you assumed.

Changed columns. Someone in the sales team renames Amount to Sum in the export template, and the loader silently loads an empty column. Defend with a schema check: the loader asserts the expected columns exist and fails loudly with a clear message if not. A loud failure at 3 a.m. is far better than a quiet wrong number at 9 a.m.

API timeouts and limits. Pulling a year of documents in one request will hit a timeout. Pull in date windows, retry with backoff, and cache what you already have. If the API caps page size, paginate; the exact parameter names are in your ERP's documentation — check them, do not assume.

Two more that bite quietly: duplicates when an incremental pull re-reads an overlapping window (deduplicate on document ID) and time zones when the API returns UTC and the export returns local time (pick one zone for the whole model and convert at the edge).

Full or incremental load, and when SQLite stops being enough

A full reload is simple and self-healing: every run rebuilds the fact table from scratch, so a missed run or a corrected document fixes itself next time. It costs time proportional to history — fine for a few hundred thousand rows, painful for millions. An incremental load pulls only documents changed since the last watermark, which is fast but adds two obligations: deduplicate on document ID, and re-read a small overlap window (a day or two) because documents get edited after posting.

Start full. Move to incremental when the full run no longer finishes inside your refresh window, and keep a monthly full rebuild as a safety net.

SQLite handles this scale comfortably up to a few million rows in a single-file database read by one Streamlit process. It stops being the right tool when several writers need to write at once, when the refresh takes longer than the schedule allows, or when someone else's tool must query the data over the network. At that point move to PostgreSQL — the SQL is close enough that the loaders mostly survive, and the migration is a day, not a rewrite.

Scheduling the refresh and detecting staleness

The simplest schedule is cron on the same server: a shell line that runs the loader, then the checks, and writes the result to a status table the page reads.

# /etc/cron.d/dashboard — nightly at 03:15
15 3 * * * dash /opt/dash/venv/bin/python /opt/dash/refresh.py >> /var/log/dash.log 2>&1

If you already run Airflow or another orchestrator, put the same script in a DAG task with a retry — you gain alerting on failure for free. Either way, the refresh must write a row into a refresh_log table (started_at, finished_at, status, rows_loaded, control_sum_delta). The page reads the latest row and shows a warning banner when the last successful run is older than your expected interval — that is staleness detection, and it is one query, not a monitoring stack.

How to verify with a control sum

The success sign is not "the chart looks right." It is a set of checks you run by hand once and then automate.

  1. Totals match. Get the source total independently — do not sum the same file the loader read. In 1C, open the sales report for the month with the same filters (posted only, same date range) and read its total; or run a report in the ERP's own interface. Compare with the dashboard. Success sign: identical to the cent, or within a tolerance you have written down. For money in a single currency, demand exact equality — a difference means a bug, not rounding. Allow a small tolerance (a few cents) only where currency conversion or per-line rounding is involved, and state the rule: round each document to two decimals, sum the rounded values, never round the sum.
  2. Row counts match. Count documents in the source for the same period. Success sign: the dashboard's count equals it; a gap points at filtering or duplicates.
  3. A known entity resolves. Pick one counterparty you know exists in both sources. Success sign: it appears once, with combined data, not twice.
  4. Unmatched rows are visible. Success sign: the unmatched list has a count, and you can name each entry.
  5. A fresh refresh is honest. Change one value in a test export, refresh, and see the control-sum check flag the difference. Success sign: it catches the change instead of hiding it.
Keep a frozen test month Save one month of source files and the expected totals. Every time the code changes, re-run against that frozen month. It is your regression test and it takes minutes to set up.

The honest cost in time and money

For one source file plus one API, a working first version is a few days of focused work — most of it not coding, but the schema, the unmatched list, and the metric definitions. Each additional source and each new metric adds hours, not days. The agent compresses the coding; it does not compress the reconciliation thinking.

On money: a small virtual server and the database file cost little per month, and the main variable is your own time. If you would rather not own the server, secrets and refresh schedule, asibiont.com takes builds like this on turnkey — the developer names the price, the client tops up the balance, and you get a working page. Details are on the subscription tiers page.

When one Streamlit script is enough, and when it is not

A single Streamlit script on a server is the right answer when the audience is small, the metrics are stable, and the page is read rather than queried. It is cheap, transparent, and you can read the whole model in one file.

It stops being enough the moment someone needs row-level access control, an audit trail of who saw what, or self-service slicing. At that point you are not fixing the script — you are buying a BI platform, and the honest move is to say so instead of bolting permissions onto a page that was never built for them.

The line is not about size. It is about whether the number must be governed — reproducible, permissioned, and auditable — or simply seen. Build for seeing first. Prove it with a control sum. Move to BI when governance, not volume, is what someone asks for. And if you want the whole thing built and handed over, asibiont.com takes such projects turnkey: the developer quotes, you top up the balance, you get the page.

AssetMaterials for this article

A document from this article — download and apply it.

  • XLSXDashboard Control-Sum Reconciliation Workbook.xlsxXLSX · 8.8 KBDownload
← All posts

Ask AI about this article

Ask a question about this article — ASI Biont will answer based on its text and the attached files.