Skip to content

Repository files navigation

tax_payer

Tooling for:

  • pulling issued invoices and paid expenses (náklady) from Fakturoid (incl. documents from Krabice na náklady once posted as expenses),
  • parsing them into a VAT‑centric model,
  • generating XML for DPH and kontrolní hlášení (DHK) with output VAT from invoices and input VAT / KH řádky B from eligible expenses.

This is deliberately minimal and focused; you can wire it into cron, CI, or run manually once a month.

Setup

Create and activate a venv however you like, then:

pip install -r requirements.txt

Create a .env in the project root (or export env vars some other way):

FAKTUROID_SLUG=your-fakturoid-subdomain
FAKTUROID_CLIENT_ID=your-client-id
FAKTUROID_CLIENT_SECRET=your-client-secret
FAKTUROID_USER_AGENT=tax-payer-tool (you@example.com)

# Required taxpayer info
TAXPAYER_ICO=12345678
TAXPAYER_DIC=CZ12345678
TAXPAYER_NAME=Your s.r.o.

# Optional taxpayer details (for DHK and DPH XML - if not provided, name will be parsed from TAXPAYER_NAME)
TAXPAYER_TITLE=Ing.
TAXPAYER_FIRST_NAME=John
TAXPAYER_LAST_NAME=Doe
TAXPAYER_STREET=Main Street
TAXPAYER_HOUSE_NUMBER=123
TAXPAYER_HOUSE_NUMBER_POP=1
TAXPAYER_CITY=PRAHA 2
TAXPAYER_ZIP=12000
TAXPAYER_EMAIL=you@example.com
TAXPAYER_PHONE=123456789
TAXPAYER_UFO=451
TAXPAYER_PRACUFO=2002
TAXPAYER_OKEC=631000

TAX_PORTAL_USERNAME=optional
TAX_PORTAL_PASSWORD=optional

BANK_API_URL=optional
BANK_ACCOUNT_NUMBER=optional
BANK_API_KEY=optional

OUTPUT_DIR=./output

# Email settings (for automated monthly reports)
EMAIL_SMTP_HOST=smtp.gmail.com
EMAIL_SMTP_PORT=587
EMAIL_SMTP_USER=your-email@gmail.com
EMAIL_SMTP_PASSWORD=your-app-password
EMAIL_SMTP_USE_TLS=true
EMAIL_RECIPIENT=your-email@gmail.com

Run:

python main.py

Or specify a specific month/year:

python main.py --month 10 --year 2024

To send generated XML files via email:

python main.py --send-email

By default it:

  • takes last calendar month as the period,
  • fetches invoices from Fakturoid for that period (since/until on issued invoices),
  • fetches paid expenses in a widened API window and assigns each to a month by taxable_fulfillment_due (DUZP) only; supplier DIČ falls back from the linked Fakturoid subject when missing on the expense row,
  • includes only expenses suitable for full odpočet: tax_deductible, no přenesená daňová povinnost, proportional_vat_deduction == 100%, status=paid,
  • writes dph_YYYYMM.xml and dhk_YYYYMM.xml into OUTPUT_DIR.

KH: expenses > 10 000 Kč incl. VAT with supplier DIČ → VetaB2; others → aggregated VetaB3. Expenses over 10k without DIČ are logged and omitted from B2/B3 (fix supplier in Fakturoid); they still flow into DPH odpočet totals if VAT lines were parsed.

Validate generated XML against the current MF XSD before filing.

Automated Monthly Reports (Cron)

To automatically generate and email XML files on the 1st of every month:

  1. Edit your crontab:
crontab -e
  1. Add this line (runs on 1st of every month at 2 AM):
0 2 1 * * cd /path/to/project/tax_payer && /path/to/venv/bin/python main.py --send-email >> /var/log/tax_payer.log 2>&1

Replace /path/to/venv/bin/python with your actual Python path (find it with which python from your venv).

For Gmail:

  • Use an App Password
  • Go to: Google Account → Security → 2-Step Verification → App passwords
  • Generate an app password and use it for EMAIL_SMTP_PASSWORD

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages