分析并生成意大利发票
a38的Python项目详细描述
PythonA38
从python生成意大利语fattura elettronica的库。
这个库实现了一个类似于django模型的声明性数据模型 旨在描述、验证、序列化和解析意大利fattura 电子数据。
只实现了规范的一部分,并根据需要添加了更多 起来。欢迎您实施您需要的缺失部分,并发送一个拉 要求:这个想法是要有一个好的,免费的图书馆 在意大利用python结账对每个人来说都更容易。
库可以生成各种通过验证的fatture,并且可以 分析由 fatturapa.gov.it
依赖关系
必需:dateutil、pytz、asn1crypto和python3标准库。
可选:
- 用于格式化输出的yapf
- lxml用于呈现为html
- 用于呈现为pdf的wkhtmltopfd命令
- 下载CA证书进行签名验证的请求
a38tool
脚本
库函数的一个简单命令行包装器可用作a38tool
:
$ 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
有关详细信息,请参见a38tool.md。
示例代码
importa38.fatturaasa38froma38.validationimportValidationimportdatetimeimportsyscedente_prestatore=a38.CedentePrestatore(a38.DatiAnagraficiCedentePrestatore(a38.IdFiscaleIVA("IT","01234567890"),codice_fiscale="NTNBLN22C23A123U",anagrafica=a38.Anagrafica(denominazione="Test User"),regime_fiscale="RF01",),a38.Sede(indirizzo="via Monferrato",numero_civico="1",cap="50100",comune="Firenze",provincia="FI",nazione="IT"),iscrizione_rea=a38.IscrizioneREA(ufficio="FI",numero_rea="123456",stato_liquidazione="LN",),contatti=a38.Contatti(email="local_part@pec_domain.it"),)cessionario_committente=a38.CessionarioCommittente(a38.DatiAnagraficiCessionarioCommittente(a38.IdFiscaleIVA("IT","76543210987"),anagrafica=a38.Anagrafica(denominazione="A Company SRL"),),a38.Sede(indirizzo="via Langhe",numero_civico="1",cap="50142",comune="Firenze",provincia="FI",nazione="IT"),)bill_number=1f=a38.FatturaPrivati12()f.fattura_elettronica_header.dati_trasmissione.id_trasmittente=a38.IdTrasmittente("IT","10293847561")f.fattura_elettronica_header.dati_trasmissione.codice_destinatario="FUFUFUF"f.fattura_elettronica_header.cedente_prestatore=cedente_prestatoref.fattura_elettronica_header.cessionario_committente=cessionario_committentebody=f.fattura_elettronica_body[0]body.dati_generali.dati_generali_documento=a38.DatiGeneraliDocumento(tipo_documento="TD01",divisa="EUR",data=datetime.date.today(),numero=bill_number,causale=["Test billing"],)body.dati_beni_servizi.add_dettaglio_linee(descrizione="Test item",quantita=2,unita_misura="kg",prezzo_unitario="25.50",aliquota_iva="22.00")body.dati_beni_servizi.add_dettaglio_linee(descrizione="Other item",quantita=1,unita_misura="kg",prezzo_unitario="15.50",aliquota_iva="22.00")body.dati_beni_servizi.build_dati_riepilogo()body.build_importo_totale_documento()res=Validation()f.validate(res)ifres.warnings:forwinres.warnings:print(str(w),file=sys.stderr)ifres.errors:foreinres.errors:print(str(e),file=sys.stderr)filename="{}{}_{:05d}.xml".format(f.fattura_elettronica_header.cedente_prestatore.dati_anagrafici.id_fiscale_iva.id_paese,f.fattura_elettronica_header.cedente_prestatore.dati_anagrafici.id_fiscale_iva.id_codice,bill_number)tree=f.build_etree()withopen(filename,"wb")asout:tree.write(out)
数字签名
firma elettronica上的数字签名是 CAdES签名。
openssl cal验证签名,但尚未生成它们。要签名的补丁 带着凯德has been recently merged 但截至2019年2月26日尚未发布。
下载CA证书
用于验证数字证书的ca证书是 distributed by the EU in XML format。 另请参见the AGID page about it。
有一个Trusted List Browser但是 显然没有办法得到一个简单的证书包 openssl。
a38tool
具有下载和解析ca证书信息的基本功能,
并维护一个ca证书目录:
a38tool update_capath certdir/ --remove-old
除了验证下载的证书之外,没有特别的努力 由requests library执行的标准https检查。
正在验证签名的.p7m
文件
一旦有了ca证书目录,验证已签名的p7m文件就相当于 简单明了:
openssl cms -verify -in tests/data/test.txt.p7m -inform der -CApath certs/
有用的链接
用于显示fatture的xslt样式表:
- 来自fatturapa.gov.it privati 和 PA
- 来自AssoSoftware
版权所有
版权所有2019 Truelite S.r.l.
此软件是在apache许可证2.0下发布的