-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsaft_export.py
More file actions
62 lines (51 loc) · 1.9 KB
/
saft_export.py
File metadata and controls
62 lines (51 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""VynFi SAF-T export — Standard Audit File for Tax (Scale+).
Emits one XML document at ``saft/saft_<jurisdiction>.xml`` covering the
generated journal entries. Supported jurisdictions (DS 4.3.1+): ``pt``,
``pl``, ``ro``, ``no``, ``lu``.
The XML is structurally valid — validate against the jurisdiction's
official XSD before using it for a regulatory filing. A 0.25× credit
multiplier applies when ``exportFormat ∈ {sap, saft}``.
"""
from __future__ import annotations
import os
from pathlib import Path
import vynfi
from vynfi import SaftExportConfig
client = vynfi.VynFi(api_key=os.environ["VYNFI_API_KEY"], timeout=180.0)
saft = SaftExportConfig(
jurisdiction="pt", # Portugal — most mature variant
company_tax_id="500000000",
company_name="ACME Retail SA",
)
print("Submitting SAF-T export job …")
job = client.jobs.generate_config(
config={
"sector": "retail",
"country": "PT",
"accountingFramework": "ifrs",
"rows": 300,
"companies": 1,
"periods": 1,
"exportFormat": "saft",
"output": {"saft": saft.to_dict()},
},
)
done = client.jobs.wait(job.id, timeout=420)
print(f" job {done.id} → {done.status}")
if done.status != "completed":
raise SystemExit(done.error_detail or "Generation did not complete.")
archive = client.jobs.download_archive(done.id)
xml_bytes = archive.saft_file("pt")
print(f"\nSAF-T (PT) payload: {len(xml_bytes):,} bytes")
print(f"XML head:\n {xml_bytes[:180].decode('utf-8', errors='replace')}")
# Persist for downstream validation.
out = Path("/tmp/saft_pt.xml")
out.write_bytes(xml_bytes)
print(f"\nSaved to {out}")
print(
"\nNext steps:\n"
" - Validate against the PT SAF-T XSD (schemaLocation in the XML header).\n"
" - For other jurisdictions: set `jurisdiction=' + pl|ro|no|lu + '` and\n"
" call `archive.saft_file(<same code>)` to read the emitted file."
)
archive.close()