File: a38tool.md

package info (click to toggle)
python-a38 0.1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 440 kB
  • sloc: python: 4,065; xml: 174; makefile: 80; sh: 14
file content (208 lines) | stat: -rw-r--r-- 6,133 bytes parent folder | download
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# `a38tool`

General command line help:

```text
$ a38tool --help
usage: a38tool [-h] [--verbose] [--debug]
               {json,xml,python,diff,validate,html,pdf,update_capath} ...

Handle fattura elettronica files

positional arguments:
  {json,xml,python,diff,validate,html,pdf,update_capath}
                        actions
    json                output a fattura in JSON
    xml                 output a fattura in XML
    python              output a fattura as Python code
    diff                show the difference between two fatture
    validate            validate the contents of a fattura
    html                render a Fattura as HTML using a .xslt stylesheet
    pdf                 render a Fattura as PDF using a .xslt stylesheet
    update_capath       create/update an openssl CApath with CA certificates
                        that can be used to validate digital signatures

optional arguments:
  -h, --help            show this help message and exit
  --verbose, -v         verbose output
  --debug               debug output
```

### Difference between two fatture

```text
$ a38tool diff --help
usage: a38tool diff [-h] first second

positional arguments:
  first       first input file (.xml or .xml.p7m)
  second      second input file (.xml or .xml.p7m)

optional arguments:
  -h, --help  show this help message and exit
```

Example:

```text
$ a38tool diff doc/IT01234567890_FPR01.xml doc/IT01234567890_FPR02.xml
fattura_elettronica_header.dati_trasmissione.codice_destinatario: first: ABC1234, second: 0000000
fattura_elettronica_header.dati_trasmissione.pec_destinatario: first is not set
fattura_elettronica_header.cedente_prestatore.dati_anagrafici.regime_fiscale: first: RF19, second: RF01
fattura_elettronica_header.cessionario_committente.dati_anagrafici.anagrafica.denominazione: first: DITTA BETA, second: …
fattura_elettronica_body.0.dati_generali.dati_contratto: second is not set
fattura_elettronica_body.0.dati_beni_servizi.dettaglio_linee.0.descrizione: first: DESCRIZIONE DELLA FORNITURA, second: …
$ echo $?
1
```

### Validate a fattura

```text
$ a38tool validate --help
usage: a38tool validate [-h] file

positional arguments:
  file        input file (.xml or .xml.p7m)

optional arguments:
  -h, --help  show this help message and exit
```

Example:

```text
$ a38tool validate doc/IT01234567890_FPR01.xml
fattura_elettronica_body.0.dati_beni_servizi.unita_misura: field must be present when quantita is set
$ echo $?
1
```

### Convert a fattura to JSON

```text
$ a38tool json --help
usage: a38tool json [-h] [-o OUTPUT] [--indent INDENT] files [files ...]

positional arguments:
  files                 input files (.xml or .xml.p7m)

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                        output file (default: standard output)
  --indent INDENT       indentation space (default: 1, use 'no' for all in one
                        line)
```

Example:

```text
$ a38tool json doc/IT01234567890_FPR02.xml
{
 "fattura_elettronica_header": {
  "dati_trasmissione": {
   "id_trasmittente": {
    "id_paese": "IT",
    "id_codice": "01234567890"
```

Use `--indent=no` to output a json per line, making it easy to separate reparse
a group of JSON fatture:

```text
$ a38tool json --indent=no doc/*.xml
{"fattura_elettronica_header": {"dati_tr…
{"fattura_elettronica_header": {"dati_tr…
{"fattura_elettronica_header": {"dati_tr…
```

### Extract XML from a `.p7m` signed fattura

```text
$ a38tool xml --help
usage: a38tool xml [-h] [-o OUTPUT] files [files ...]

positional arguments:
  files                 input files (.xml or .xml.p7m)

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                        output file (default: standard output)
```

### Generate Python code

You can convert a fattura to Python code: this is a quick way to start writing
a software that generates fatture similar to an existing one.

```text
$ a38tool python --help
usage: a38tool python [-h] [-o OUTPUT] [--namespace NAMESPACE] [--unformatted]
                      files [files ...]

positional arguments:
  files                 input files (.xml or .xml.p7m)

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                        output file (default: standard output)
  --namespace NAMESPACE
                        namespace to use for the model classes (default: the
                        module fully qualified name)
  --unformatted         disable code formatting, outputting a single-line
                        statement
```

Example:

```text
$ a38tool python doc/IT01234567890_FPR02.xml
a38.fattura.FatturaPrivati12(
    fattura_elettronica_header=a38.fattura.FatturaElettronicaHeader(
        dati_trasmissione=a38.fattura.DatiTrasmissione(
            id_trasmittente=a38.fattura.IdTrasmittente(
                id_paese='IT', id_codice='01234567890'),
            progressivo_invio='00001',
```


### Render to HTML or PDF

You can use a .xslt file to render a fattura to HTML or PDF.

```text
$ a38tool html --help
usage: a38tool html [-h] [-f] [-o OUTPUT] stylesheet files [files ...]

positional arguments:
  stylesheet            .xsl/.xslt stylesheet file to use for rendering
  files                 input files (.xml or .xml.p7m)

optional arguments:
  -h, --help            show this help message and exit
  -f, --force           overwrite existing output files
  -o OUTPUT, --output OUTPUT
                        output file; use {dirname} for the source file path,
                        {basename} for the source file name (default:
                        '{dirname}/{basename}{ext}.html'
```

Example:

```text
$ a38tool -v html -f doc/fatturaordinaria_v1.2.1.xsl doc/IT01234567890_FPR02.xml
INFO doc/IT01234567890_FPR02.xml: writing doc/IT01234567890_FPR02.xml.html
```

```text
$ a38tool -v pdf -f doc/fatturaordinaria_v1.2.1.xsl doc/IT01234567890_FPR02.xml
INFO doc/IT01234567890_FPR02.xml: writing doc/IT01234567890_FPR02.xml.pdf
```