Skip to content

Allow this site to count your visits with Yandex Metrica? Metrica will store cookies in your browser to do this. How the site uses cookies

VC
Case 11 of 22 · B2B · Finance

Federal Treasury statements into 1C: 5 seconds per statement, down from 2–3 hours

Every week an accountant at a government-contract company converted XML statements from the Federal Treasury's GIS system into the 1C format by hand. I wrote a Python converter that reads both versions of the format, and now a statement is converted in a single run.

Industry
Accounting at a government-contract company
Technology
Python · xml.etree · Win-1251
Timeline
About 3 business days
Outcome
2–3 hours → 5 seconds per statement
01 · Problem

Hours of picking through XML by hand, every month

Every week an accountant at a government-contract company received XML statements from the Federal Treasury's "Electronic Budget" system. Each statement is an XML document with dozens of nested tags: recipient details, the Treasury office (ORFK) and the legal entity, credit and debit amounts, and balance items for each personal account.

To load this data into 1C, it had to be moved into the 1CClientBankExchange format. This is the text format 1C uses to exchange data with bank-client software. It is encoded in Windows-1251, has a strict structure of SectionDocument=... sections and dozens of required fields for every payment.

In practice this meant opening the XML in an editor and copying each field by hand into the Excel mapping table Payment_Treasury_1C_mapping.xlsx. Then came checking the counterparties, checking the amounts against the control figures, converting to the right encoding and saving the file. And the same again for every payment in the statement.

02 · Solution

Python reads both versions of the format, and 1C loads the result directly

The design is simple and the data flows one way, so there is very little to break. A single command-line script reads the XML file, detects the format version, pulls out the fields it needs, maps them through the table and writes a finished 1CClientBankExchange file in the right encoding.

01
XML statement

A file from the Treasury GIS: V3 (TSE_BalanAcc_D13) or V4 (TSE_BalanAcc2_D13)

02
Reading the file

xml.etree.ElementTree; the version is detected automatically from the root element's namespace

03
Field mapping

BasicRequisites, ORFK, LegalEntity, balance_items → 1C fields

04
Writing the file

1CClientBankExchange template, Windows-1251 encoding

05
1C

The file loads through 1C's standard bank-client exchange

Two XML versions, one result

The Treasury GIS uses two statement formats at the same time: V3 (TSE_BalanAcc_D13) and V4 (TSE_BalanAcc2_D13). Their fields and namespaces differ. The script detects the version from the root element and picks the matching way to read it. Either way, the output is the same data structure.

The script pulls out every field that matters

The script extracts the statement header, every payment and the balance items, and checks the control sums along the way:

  • BasicRequisites: document details, period, statement number
  • ORFK: the Federal Treasury office
  • LegalEntity: the legal entity, its INN/KPP tax registration codes, the personal account
  • SDTotalSum / EDTotalSum: debit and credit control sums
  • balance_items: each balance item broken down by KBK, the budget classification code

Windows-1251 encoding without surprises

The 1CClientBankExchange format expects Windows-1251. The converter opens the output file with encoding="cp1251" and handles in advance any characters that this encoding can't represent. So the import into 1C comes out without garbled text.

03 · Technology

Simple technology, chosen on purpose

Python 3.11+

One script, no cloud services needed

xml.etree.ElementTree

Part of the standard library, no extra packages

Windows-1251 / cp1251

The encoding that 1CClientBankExchange requires

1CClientBankExchange

The bank-client exchange standard: 1C loads the file with its built-in tools

Excel mapping table

Payment_Treasury_1C_mapping.xlsx, the field reference

Command line

Runs from the command line or from a .bat file on the accountant's computer

Pythonxml.etreeWindows-12511CClientBankExchangeCLIExcel
04 · Results

Before and after, side by side

Processing time
2–3 hrs 5 sec

per statement

Amounts typed by hand
0

amounts come straight from the XML, and the control sums are checked before the file is written

Format versions
V3 + V4

both versions of the Treasury GIS XML statement

The main result: a whole class of manual-entry errors disappeared. Every field comes straight from the source XML, and nobody retypes amounts from the screen any more.

The accountant double-clicks a .bat file and gets a file ready to load. The checking now happens in 1C, where it belongs.

The same statements can also be converted right in the browser with my free online Treasury-to-1C converter (the page is in Russian).

05 · Where it fits

Where else the same approach works

Behind this case is a common task: "turn a document in one strict format into another, using a fixed mapping table". The same design works anywhere data has to move from one system to another without manual entry:

  • → Bank statements in the 1C bank-client or SUFD format: the same fields, a different namespace
  • → UPD and e-invoicing documents from Kontur.Diadoc or SBIS → import into 1C: Trade Management or 1C: Accounting
  • → "Honest Sign" product marking: XML reports into the accounting system
  • → Tax returns and reports in non-standard Federal Tax Service formats → internal spreadsheets
  • → Tender documents (XML exports from government procurement portals) → a CRM or internal Excel registers
What I reuse in later projects
  • A script template that detects the format version from the root element
  • The field mapping lives in an Excel reference table that the accountant edits without touching the code
  • Control sums are checked before the file is written: if they disagree, the script stops and the error stays out of the books
  • A .bat file on the accountant's computer, so nobody has to deal with Python
Similar challenge?

A document arrives in one strict format and you need it in another? That can be automated

A document converter is predictable automation: the input and the output are known in advance. From the first XML to live use takes 3–7 business days, and the payback is easy to work out on the back of an envelope.

Ready to start?

Start with the 5,000 ₽ audit: a written report and a payback estimate

I'll tell you what to automate first, when it will pay for itself and whether your task needs AI at all. Sometimes it doesn't.

Or just ask a question. During business hours I reply within 2 hours