getafix 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- getafix-0.1.0/LICENSE +202 -0
- getafix-0.1.0/PKG-INFO +284 -0
- getafix-0.1.0/README.md +262 -0
- getafix-0.1.0/pyproject.toml +118 -0
- getafix-0.1.0/src/getafix/__init__.py +0 -0
- getafix-0.1.0/src/getafix/cli.py +146 -0
- getafix-0.1.0/src/getafix/errors.py +31 -0
- getafix-0.1.0/src/getafix/pdf.py +119 -0
- getafix-0.1.0/src/getafix/py.typed +0 -0
- getafix-0.1.0/src/getafix/report/__init__.py +104 -0
- getafix-0.1.0/src/getafix/report/_types.py +80 -0
- getafix-0.1.0/src/getafix/report/accounting.py +171 -0
- getafix-0.1.0/src/getafix/report/agreement.py +82 -0
- getafix-0.1.0/src/getafix/report/delivery.py +72 -0
- getafix-0.1.0/src/getafix/report/document.py +85 -0
- getafix-0.1.0/src/getafix/report/element.py +39 -0
- getafix-0.1.0/src/getafix/report/line.py +141 -0
- getafix-0.1.0/src/getafix/report/party.py +173 -0
- getafix-0.1.0/src/getafix/report/references.py +50 -0
- getafix-0.1.0/src/getafix/report/settlement.py +215 -0
- getafix-0.1.0/src/getafix/report/trade.py +111 -0
- getafix-0.1.0/src/getafix/report/types.py +99 -0
- getafix-0.1.0/src/getafix/rules/__init__.py +13 -0
- getafix-0.1.0/src/getafix/rules/_types.py +102 -0
- getafix-0.1.0/src/getafix/rules/accounting.py +269 -0
- getafix-0.1.0/src/getafix/rules/extended.py +647 -0
- getafix-0.1.0/src/getafix/rules/line.py +75 -0
- getafix-0.1.0/src/getafix/rules/party.py +147 -0
- getafix-0.1.0/src/getafix/rules/settlement.py +328 -0
- getafix-0.1.0/src/getafix/rules/trade.py +1204 -0
- getafix-0.1.0/src/getafix/schema/__init__.py +5 -0
- getafix-0.1.0/src/getafix/schema/_numeric.py +32 -0
- getafix-0.1.0/src/getafix/schema/accounting.py +535 -0
- getafix-0.1.0/src/getafix/schema/agreement.py +139 -0
- getafix-0.1.0/src/getafix/schema/delivery.py +111 -0
- getafix-0.1.0/src/getafix/schema/document.py +290 -0
- getafix-0.1.0/src/getafix/schema/element.py +483 -0
- getafix-0.1.0/src/getafix/schema/line.py +950 -0
- getafix-0.1.0/src/getafix/schema/party.py +999 -0
- getafix-0.1.0/src/getafix/schema/references.py +386 -0
- getafix-0.1.0/src/getafix/schema/settlement.py +805 -0
- getafix-0.1.0/src/getafix/schema/trade.py +224 -0
- getafix-0.1.0/src/getafix/schema/types.py +1871 -0
getafix-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
getafix-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: getafix
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Parse and create ZUGFerD files.
|
|
5
|
+
Author-email: Tammo Ippen <tammo.ippen@posteo.de>
|
|
6
|
+
Requires-Python: >=3.12
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: tagic>=1.5.0
|
|
11
|
+
Requires-Dist: lxml>=6.0.2 ; extra == "cli"
|
|
12
|
+
Requires-Dist: rich>=13.0 ; extra == "cli"
|
|
13
|
+
Requires-Dist: pypdf>=6.12.0 ; extra == "cli"
|
|
14
|
+
Requires-Dist: lxml>=6.0.2 ; extra == "lxml"
|
|
15
|
+
Requires-Dist: pypdf>=6.12.0 ; extra == "pdf"
|
|
16
|
+
Requires-Dist: rich>=13.0 ; extra == "rich"
|
|
17
|
+
Provides-Extra: cli
|
|
18
|
+
Provides-Extra: lxml
|
|
19
|
+
Provides-Extra: pdf
|
|
20
|
+
Provides-Extra: rich
|
|
21
|
+
|
|
22
|
+
# getafix
|
|
23
|
+
|
|
24
|
+
[](https://github.com/tammoippen/getafix/actions/workflows/CI.yml)
|
|
25
|
+
[](https://pypi.python.org/pypi/getafix)
|
|
26
|
+
[](https://pepy.tech/project/getafix)
|
|
27
|
+
[](https://pypi.python.org/pypi/getafix)
|
|
28
|
+
[](https://github.com/astral-sh/ruff)
|
|
29
|
+
[](https://github.com/astral-sh/uv)
|
|
30
|
+
|
|
31
|
+
Build, parse and validate
|
|
32
|
+
[**ZUGFeRD 2.x / Factur-X**](https://www.ferd-net.de/standards/zugferd)
|
|
33
|
+
Cross-Industry-Invoice (CII) XML in Python. `getafix` provides a fully typed dataclass model for creating and parsed invoices - every field traceable to the EN 16931 business terms (`BT-…`) and groups (`BG-…`). Validation follows a broad, but selective set of business rules (`BR-…`). An accompanied cli tool `getafix` renders and validaes invoices in the terminal.
|
|
34
|
+
|
|
35
|
+
[](/imgs/minimum.png)
|
|
36
|
+
|
|
37
|
+
## Why "getafix"?
|
|
38
|
+
|
|
39
|
+
> "get a fix" — _get a Factur-X_
|
|
40
|
+
|
|
41
|
+
The project's working title was `carthorse` - in the spirit of [drafthorse](https://github.com/pretix/python-drafthorse), [pycheval](https://github.com/zfutura/pycheval/tree/main), [mustang](https://github.com/ZUGFeRD/mustangproject), ... - but when I learned, that is already [taken](https://pypi.org/project/carthorse/), I wanted to break free from the horse naming.
|
|
42
|
+
|
|
43
|
+
Getafix is the village druid in _Asterix_ — the one that brews the magic potion. I only knew the german name `Miraculix` and was hooked. The Gaulish `-ix` ending echoes the `-X` in Factur-**X**, and Factur-X is the French half of the standard: so the French druid it is!
|
|
44
|
+
|
|
45
|
+
> **Status: pre-1.0.** Solid for the fields that are modelled across
|
|
46
|
+
> MINIMUM / BASIC_WL / BASIC / COMFORT (EN 16931); broad EXTENDED
|
|
47
|
+
> coverage. PDF/A-3 conformance for the host PDF is **out of scope** —
|
|
48
|
+
> `getafix` attaches the embedded `factur-x.xml` but does not
|
|
49
|
+
> upgrade the surrounding PDF to PDF/A-3.
|
|
50
|
+
|
|
51
|
+
## License and attribution
|
|
52
|
+
|
|
53
|
+
`getafix` is distributed under the **Apache License 2.0** — see [`LICENSE`](LICENSE).
|
|
54
|
+
|
|
55
|
+
This project is an application of the **ZUGFeRD / Factur-X** publication issued by the _Forum elektronische Rechnung Deutschland_ (FeRD) at AWV e.V. The format incorporates **EN 16931**, reproduced by FeRD with the permission of **CEN** and **DIN**. _ZUGFeRD_ and _Factur-X_ are trademarks of FeRD / AWV e.V., used here only to identify the standard this library implements.
|
|
56
|
+
|
|
57
|
+
The vendored test fixtures under [`tests/schemas/`](tests/schemas/) and [`tests/samples/`](tests/samples/) come from third parties and are redistributed under the Apache License 2.0:
|
|
58
|
+
|
|
59
|
+
- **FeRD / AWV e.V.** — XML schemas, Schematron, and the `*_zf24_*`
|
|
60
|
+
example invoices from the official ZUGFeRD 2.4 / Factur-X 1.08
|
|
61
|
+
distribution.
|
|
62
|
+
- **[ZUGFeRD/mustangproject](https://github.com/ZUGFeRD/mustangproject)**
|
|
63
|
+
— additional reference CII invoices from the Java implementation's
|
|
64
|
+
test resources.
|
|
65
|
+
- **[ZUGFeRD/corpus](https://github.com/ZUGFeRD/corpus)** —
|
|
66
|
+
community-curated `XML-Rechnung/CII/` reference invoices.
|
|
67
|
+
|
|
68
|
+
Original copyright remains with the respective upstream holders; per-file provenance is tracked in [`tests/samples/SOURCES.md`](tests/samples/SOURCES.md).
|
|
69
|
+
|
|
70
|
+
> **Important:** It is the user's responsibility to ensure that
|
|
71
|
+
> invoices generated or parsed with `getafix` meet all legal and
|
|
72
|
+
> regulatory requirements applicable in their jurisdiction.
|
|
73
|
+
> `getafix` does not guarantee compliance with any specific
|
|
74
|
+
> national or sector-specific e-invoicing mandate.
|
|
75
|
+
|
|
76
|
+
## Installation
|
|
77
|
+
|
|
78
|
+
Requires **Python 3.12+**. We recommend [`uv`](https://docs.astral.sh/uv/) for dependency management.
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
pip install getafix
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The base install lets you build / serialise / validate documents with the Python stdlib XML parser. The optional extras unlock more:
|
|
85
|
+
|
|
86
|
+
| Extra | Pulls in | Enables |
|
|
87
|
+
| --------------- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
88
|
+
| `getafix[lxml]` | `lxml` | Round-tripping XML produced by other tools (the stdlib parser is fine for most documents; `lxml` is faster and more tolerant of large / namespaced inputs). |
|
|
89
|
+
| `getafix[pdf]` | `pypdf` | Embedding / extracting `factur-x.xml` in a PDF (`getafix.pdf.attach_xml` and `extract_xml`). |
|
|
90
|
+
| `getafix[rich]` | `rich` | Pretty-print an invoice using the rich library. |
|
|
91
|
+
| `getafix[cli]` | `lxml`, `rich`, `pypdf` | The `getafix` console script — pretty-print an invoice and run the BR-\* validators against it. |
|
|
92
|
+
|
|
93
|
+
Install several at once:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
pip install 'getafix[lxml,pdf]'
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Quickstart — build an invoice
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from datetime import date
|
|
103
|
+
from decimal import Decimal
|
|
104
|
+
|
|
105
|
+
from getafix.schema.document import (
|
|
106
|
+
Context, Document, GuidelineDocument, Header
|
|
107
|
+
)
|
|
108
|
+
from getafix.schema.accounting import MonetarySummation, TaxTotal
|
|
109
|
+
from getafix.schema.agreement import TradeAgreement
|
|
110
|
+
from getafix.schema.delivery import TradeDelivery
|
|
111
|
+
from getafix.schema.party import (
|
|
112
|
+
BuyerTradeParty, PostalTradeAddressExtended, SellerTradeParty,
|
|
113
|
+
SpecifiedTaxRegistration, TaxSchemeId,
|
|
114
|
+
)
|
|
115
|
+
from getafix.schema.settlement import TradeSettlement
|
|
116
|
+
from getafix.schema.trade import Trade
|
|
117
|
+
from getafix.schema.types import Country, Currency, Profile, TypeCode
|
|
118
|
+
|
|
119
|
+
doc = Document(
|
|
120
|
+
context=Context(guideline=GuidelineDocument(id=Profile.MINIMUM)),
|
|
121
|
+
header=Header(
|
|
122
|
+
id="INV-2025-0001",
|
|
123
|
+
type_code=TypeCode.T_CommercialInvoice, # 380
|
|
124
|
+
issue_date=date(2025, 11, 16),
|
|
125
|
+
),
|
|
126
|
+
trade=Trade(
|
|
127
|
+
agreement=TradeAgreement(
|
|
128
|
+
seller=SellerTradeParty(
|
|
129
|
+
name="Acme GmbH",
|
|
130
|
+
address=PostalTradeAddressExtended(country_id=Country.DE),
|
|
131
|
+
tax_registrations=[
|
|
132
|
+
SpecifiedTaxRegistration(
|
|
133
|
+
id=TaxSchemeId(id="DE123456789", scheme_id="VA"),
|
|
134
|
+
),
|
|
135
|
+
],
|
|
136
|
+
),
|
|
137
|
+
buyer=BuyerTradeParty(
|
|
138
|
+
name="Beta AG",
|
|
139
|
+
address=PostalTradeAddressExtended(country_id=Country.DE),
|
|
140
|
+
),
|
|
141
|
+
),
|
|
142
|
+
delivery=TradeDelivery(),
|
|
143
|
+
settlement=TradeSettlement(
|
|
144
|
+
currency_code=Currency.EUR,
|
|
145
|
+
monetary_summation=MonetarySummation(
|
|
146
|
+
tax_basis_total=Decimal("100.00"),
|
|
147
|
+
tax_total=[TaxTotal(amount=Decimal("19.00"), currency_id=Currency.EUR)],
|
|
148
|
+
grand_total=Decimal("119.00"),
|
|
149
|
+
due_amount=Decimal("119.00"),
|
|
150
|
+
),
|
|
151
|
+
),
|
|
152
|
+
),
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
xml = doc.to_xml().render(indent=True) # str — ready to write to factur-x.xml
|
|
156
|
+
doc.validate() # raises ValidationErrors on BR-* failures
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
`doc.to_xml()` picks the right profile from `Context.guideline.id`. Setting a field that requires a higher profile than the document raises `ProfileMismatch` at render time.
|
|
160
|
+
|
|
161
|
+
## Quickstart — parse an invoice
|
|
162
|
+
|
|
163
|
+
From XML bytes or a file:
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
import xml.etree.ElementTree as ET
|
|
167
|
+
from getafix.schema.document import Document
|
|
168
|
+
|
|
169
|
+
tree = ET.parse("factur-x.xml")
|
|
170
|
+
doc = Document.from_xml(tree.getroot())
|
|
171
|
+
|
|
172
|
+
print(doc.header.id, doc.header.type_code, doc.header.issue_date)
|
|
173
|
+
print(doc.trade.settlement.monetary_summation.grand_total)
|
|
174
|
+
|
|
175
|
+
doc.validate() # raises ValidationErrors with every violation
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
`lxml.etree` works the same way — pass the root element to `Document.from_xml`.
|
|
179
|
+
|
|
180
|
+
From a Factur-X / ZUGFeRD PDF (`getafix[pdf]` extra):
|
|
181
|
+
|
|
182
|
+
```python
|
|
183
|
+
import xml.etree.ElementTree as ET
|
|
184
|
+
from getafix.pdf import extract_xml
|
|
185
|
+
from getafix.schema.document import Document
|
|
186
|
+
|
|
187
|
+
payload = extract_xml(Path("invoice.pdf")) # bytes or None
|
|
188
|
+
if payload is None:
|
|
189
|
+
raise SystemExit("No factur-x.xml found in the PDF")
|
|
190
|
+
doc = Document.from_xml(ET.fromstring(payload))
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
To embed an XML into an existing PDF:
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
from pathlib import Path
|
|
197
|
+
from getafix.pdf import attach_xml
|
|
198
|
+
|
|
199
|
+
attach_xml(Path("invoice.pdf"), Path("factur-x.xml")) # in-place
|
|
200
|
+
attach_xml(Path("invoice.pdf"), Path("factur-x.xml"),
|
|
201
|
+
pdf_out=Path("invoice-with-xml.pdf"))
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
`attach_xml` produces a valid PDF with a generic embedded file; it does **not** upgrade the host PDF to PDF/A-3, which is the formal Factur-X compliance requirement. Pair with a dedicated PDF/A-3 converter for full conformance.
|
|
205
|
+
|
|
206
|
+
## Validation
|
|
207
|
+
|
|
208
|
+
```python
|
|
209
|
+
from getafix.schema.element import ValidationErrors
|
|
210
|
+
|
|
211
|
+
try:
|
|
212
|
+
doc.validate()
|
|
213
|
+
except ValidationErrors as exc:
|
|
214
|
+
for err in exc.errors:
|
|
215
|
+
print(f"{err.code}: {err.message}")
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
`Document.validate()` walks the document tree once and collects every business-rule violation, raising a single `ValidationErrors` aggregate. Each `ValidationError` carries the rule's code (e.g. `BR-CO-15`) and a human-readable message.
|
|
219
|
+
|
|
220
|
+
Every rule getafix enforces lives in `getafix.rules` — one module per schema topic (`accounting`, `line`, `party`, `settlement`, `trade`, `extended`), each wired onto the relevant element's `_validators`.
|
|
221
|
+
|
|
222
|
+
## Command-line tool
|
|
223
|
+
|
|
224
|
+
The `getafix[cli]` extra ships a console script that pretty-prints an invoice and runs the validators:
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
> getafix path/to/factur-x.xml
|
|
228
|
+
> getafix path/to/invoice.pdf # reads the embedded XML
|
|
229
|
+
> getafix --no-validate path/to/file.xml # skip BR-* checks
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Exit codes:
|
|
233
|
+
|
|
234
|
+
- `0` — parsed cleanly and passed every validator.
|
|
235
|
+
- `1` — parsed but at least one validation rule fired (or the document could not be parsed as a CII invoice, or no Factur-X XML was found in the supplied PDF).
|
|
236
|
+
- `2` — usage / IO / missing dependency error.
|
|
237
|
+
|
|
238
|
+
[](/imgs/comfort.png)
|
|
239
|
+
|
|
240
|
+
## Profiles
|
|
241
|
+
|
|
242
|
+
ZUGFeRD / Factur-X defines five conformance profiles, ordered by
|
|
243
|
+
completeness:
|
|
244
|
+
|
|
245
|
+
| Profile | URN | Carries line items |
|
|
246
|
+
| ---------- | ----------------------------------------------------------------- | ------------------------ |
|
|
247
|
+
| `MINIMUM` | `urn:factur-x.eu:1p0:minimum` | ✗ (header totals only). |
|
|
248
|
+
| `BASIC_WL` | `urn:factur-x.eu:1p0:basicwl` | ✗ (basic, without lines) |
|
|
249
|
+
| `BASIC` | `urn:cen.eu:en16931:2017#compliant#urn:factur-x.eu:1p0:basic` | ✓ |
|
|
250
|
+
| `COMFORT` | `urn:cen.eu:en16931:2017` _(a.k.a. EN 16931)_ | ✓ |
|
|
251
|
+
| `EXTENDED` | `urn:cen.eu:en16931:2017#conformant#urn:factur-x.eu:1p0:extended` | ✓ + sub-lines |
|
|
252
|
+
|
|
253
|
+
The profile is set on the document via `Context(guideline=GuidelineDocument(id=Profile.X))`. Getafix enforces it at render time: setting a field that only exists at a higher profile raises `ProfileMismatch`.
|
|
254
|
+
|
|
255
|
+
## Status and known gaps
|
|
256
|
+
|
|
257
|
+
Getafix models every field that the MINIMUM, BASIC_WL, BASIC and EN 16931 (COMFORT) profiles permit. EXTENDED coverage is broad — sub-line hierarchy (`BT-X-7` / `BT-X-8` / `BT-X-304`), bundle composition (`BG-X-1` `IncludedReferencedProduct`), per-instance batch / serial details (`BG-X-84`), logistics service charges (`BG-X-42`), advance payments (`BG-X-45` with `BG-X-46` / `BG-X-85`), the EXTENDED-only deviating parties (sales agent, buyer agent, buyer / item-level seller / tax representative, invoicer, invoicee, payer, product end-user), the penalty / discount payment-term schedules (`BG-X-43` / `BG-X-44`), tax-currency exchange (`BG-X-41`), delivery terms (`BG-X-22`), quotation / ultimate-customer-order references, and the `PEPPOL`-flavoured rule overlay (`BR-FXEXT-*`) are all modelled.
|
|
258
|
+
|
|
259
|
+
Every shipped sample re-renders **1:1** with its source XML (`tests/test_roundtrip_fidelity.py`) — getafix never silently drops a field it claims to model.
|
|
260
|
+
|
|
261
|
+
The remaining EXTENDED gaps are optional leaf attributes and line-level twins the shipped samples don't exercise. Each one should be easy to add: declare the `field()` gated at `Profile.EXTENDED`, ensure XSD-sequence order - test will fail otherwise; getafix will accept a PR, or pick one up when there is a need for it:
|
|
262
|
+
|
|
263
|
+
- **Party extras** — `RoleCode` (`BT-X-483`…`BT-X-575`) on every trade party; additional legal info (`Description`) on the Buyer (`BT-X-334`) and the line-level item seller (`BT-X-571`); contact `TypeCode` (`BT-X-315`…`BT-X-575`) on every `DefinedTradeContact` (BG-6 / BG-9).
|
|
264
|
+
- **Line-level twins of header references** — on `LineTradeAgreement`: delivery terms (`BG-X-87`), contract (`BG-X-2`), seller order (`BG-X-81`), ultimate-customer order (`BG-X-5`); on `LineTradeDelivery`: the actual delivery event / date (`BT-X-85-000`), despatch (`BG-X-13`) and receiving (`BG-X-82`) advice; on `LineTradeSettlement`: the preceding-invoice reference (`BG-X-48`); line-note codes (`BT-X-9` / `BT-X-10`). _(The line-level delivery-note `BG-X-83` and additional-document `BG-X-3` twins **are** modelled.)_
|
|
265
|
+
- **Line monetary totals** — `AllowanceTotalAmount` / `ChargeTotalAmount` / `TaxTotalAmount` / `GrandTotalAmount` (`BT-X-327`…`BT-X-330`); the line total and total-allowance-charge are modelled.
|
|
266
|
+
- **Referenced-document leaves** — `FormattedIssueDateTime` on the header additional / contract references (`BT-X-33-00` / `BT-X-148-00` / `BT-X-149-00`); preceding-invoice `TypeCode` (`BT-X-555`); accounting reference `TypeCode` (`BT-X-99` / `BT-X-290`).
|
|
267
|
+
- **Other shared leaves** — item characteristic `TypeCode` / `ValueMeasure` (`BT-X-11` / `BT-X-12`), invoicing-period `Description` (`BT-X-264`), allowance/charge `SequenceNumeric` / `BasisQuantity` (`BT-X-265` / `BT-X-266`), per-line product local `ID` (`BT-X-305`), net-price `IncludedTradeTax` (`BG-X-4`, B2C VAT in the unit price).
|
|
268
|
+
|
|
269
|
+
PDF/A-3 packaging is out of scope; use [factur-x](https://github.com/akretion/factur-x), [Mustangproject](https://github.com/ZUGFeRD/mustangproject) or a dedicated converter for full Factur-X PDF conformance.
|
|
270
|
+
|
|
271
|
+
## Contributing
|
|
272
|
+
|
|
273
|
+
See [`CONTRIBUTING.md`](CONTRIBUTING.md) for the developer guide — module layout, how the dataclass model works, how to add a new BT field or BR validator, and the test / lint workflow.
|
|
274
|
+
|
|
275
|
+
## References
|
|
276
|
+
|
|
277
|
+
Specification and validators:
|
|
278
|
+
|
|
279
|
+
- [FeRD net — ZUGFeRD standard](https://www.ferd-net.de/standards/zugferd)
|
|
280
|
+
- [Rechnung Fans — XRechnung / EN 16931 portal](https://portal3.gefeg.com/invoice/tthome/index/617afdc4-623f-44e0-a05b-5b878840e508)
|
|
281
|
+
- [Service BW e-Rechnung Validator](https://erechnungsvalidator.service-bw.de/)
|
|
282
|
+
- [Rechnung.fans validator](https://portal3.gefeg.com/invoice/validation)
|
|
283
|
+
- [Invoice Portal validator](https://validator.invoice-portal.de/index.php)
|
|
284
|
+
|