-
Notifications
You must be signed in to change notification settings - Fork 3
/
wdigdepfiel.py
184 lines (156 loc) · 6.49 KB
/
wdigdepfiel.py
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
#!/usr/bin/python
# -*- coding: latin-1 -*-
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
"""Módulo para interfaz Depositario Fiel web service wDigDepFiel de AFIP
"""
__author__ = "Mariano Reingart <[email protected]>"
__copyright__ = "Copyright (C) 2010 Mariano Reingart"
__license__ = "LGPL 3.0"
__version__ = "1.01"
LICENCIA = """
wdigdepfiel.py: Interfaz para Digitalizacion Depositario Fiel AFIP
Copyright (C) 2010 Mariano Reingart [email protected]
Este progarma es software libre, se entrega ABSOLUTAMENTE SIN GARANTIA
y es bienvenido a redistribuirlo bajo la licencia GPLv3.
Para información adicional sobre garantía, soporte técnico comercial
e incorporación/distribución en programas propietarios ver PyAfipWs:
http://www.sistemasagiles.com.ar/trac/wiki/PyAfipWs
"""
import os, sys, time
from php import date, SimpleXMLElement, SoapClient, SoapFault
WSDDFURL = "https://testdia.afip.gov.ar/Dia/Ws/wDigDepFiel/wDigDepFiel.asmx"
SOAP_ACTION = 'ar.gov.afip.dia.serviciosWeb.wDigDepFiel/'
SOAP_NS = 'ar.gov.afip.dia.serviciosWeb.wDigDepFiel'
DEBUG = True
XML = False
HOMO = True
def dummy(client):
"Metodo dummy para verificacion de funcionamiento"
response = client.Dummy()
result = response.DummyResult
appserver = dbserver = authserver = None
try:
appserver = str(result.appserver)
dbserver = str(result.dbserver)
authserver = str(result.authserver)
except (RuntimeError, IndexError, AttributeError), e:
pass
return {'appserver': appserver,
'dbserver': dbserver,
'authserver': authserver}
def aviso_recep_acept(client, token, sign, cuit, tipo_agente, rol,
nro_legajo, cuit_declarante, cuit_psad, cuit_ie,
codigo, fecha_hora_acept, ticket):
"Aviso de recepcion y aceptacion."
response = client.AvisoRecepAcept(
autentica=dict(Cuit=cuit, Token=token, Sign=sign, TipoAgente=tipo_agente, Rol=rol),
nroLegajo=nro_legajo,
cuitDeclarante=cuit_declarante,
cuitPSAD=cuit_psad,
cuitIE=cuit_ie,
codigo=codigo,
fechaHoraAcept=fecha_hora_acept,
ticket=ticket,
)
result = response.AvisoRecepAceptResult
return str(result.codError), str(result.descError)
def aviso_digit(client, token, sign, cuit, tipo_agente, rol,
nro_legajo, cuit_declarante, cuit_psad, cuit_ie, cuit_ata,
codigo, url, familias, ticket, hashing, cantidad_total):
"Aviso de digitalizacion."
response = client.AvisoDigit(
autentica=dict(Cuit=cuit, Token=token, Sign=sign, TipoAgente=tipo_agente, Rol=rol),
nroLegajo=nro_legajo,
cuitDeclarante=cuit_declarante,
cuitPSAD=cuit_psad,
cuitIE=cuit_ie,
cuitATA=cuit_ata,
codigo=codigo,
url=url,
familias=familias,
ticket=ticket,
hashing=hashing,
cantidadTotal=cantidad_total,
)
result = response.AvisoDigitResult
return str(result.codError), str(result.descError)
if __name__ == '__main__':
if '--ayuda' in sys.argv:
print LICENCIA
print AYUDA
sys.exit(0)
import csv
import traceback
import datetime
import wsaa
try:
if "--version" in sys.argv:
print "Versión: ", __version__
CERT='reingart.crt'
PRIVATEKEY='reingart.key'
# obteniendo el TA
TA = "wsddf-ta.xml"
if not os.path.exists(TA) or os.path.getmtime(TA)+(60*60*5)<time.time():
tra = wsaa.create_tra(service="wDigDepFiel")
cms = wsaa.sign_tra(tra,CERT,PRIVATEKEY)
ta_string = wsaa.call_wsaa(cms)
open(TA,"w").write(ta_string)
ta_string=open(TA).read()
ta = SimpleXMLElement(ta_string)
token = str(ta.credentials.token)
sign = str(ta.credentials.sign)
# fin TA
# cliente soap del web service
client = SoapClient(WSDDFURL,
action = SOAP_ACTION,
namespace = SOAP_NS, exceptions = True,
trace = True, ns = 'ar', soap_ns='soap')
if '--dummy' in sys.argv:
ret = dummy(client)
print '\n'.join(["%s: %s" % it for it in ret.items()])
# ejemplos aviso recep acept (prueba):
cuit = 20267565393
tipo_agente = 'DESP' # 'DESP'
rol = 'EXTE'
nro_legajo = '0'*16 # '1234567890123456'
cuit_declarante = cuit_psad = cuit_ie = cuit
codigo = '000' # carpeta completa, '0001' carpeta adicional
fecha_hora_acept = datetime.datetime.now().isoformat()
ticket = '1234'
r = aviso_recep_acept(client, token, sign, cuit, tipo_agente, rol,
nro_legajo, cuit_declarante, cuit_psad, cuit_ie,
codigo, fecha_hora_acept, ticket)
print r
# ejemplos aviso digit (prueba):
cuit = 20267565393
tipo_agente = 'DESP' # 'DESP'
rol = 'EXTE'
nro_legajo = '0'*16 # '1234567890123456'
cuit_declarante = cuit_psad = cuit_ie = cuit_ata = cuit
codigo = '000' # carpeta completa, '0001' carpeta adicional
ticket = '1234'
url = 'http://www.example.com'
hashing = 'db1491eda47d78532cdfca19c62875aade941dc2'
familias = [ {'Familia': {'codigo': '02', 'cantidad': 1}}, {'Familia': {'codigo': '03', 'cantidad': 3}}, ]
cantidad_total = 4
r = aviso_digit(client, token, sign, cuit, tipo_agente, rol,
nro_legajo, cuit_declarante, cuit_psad, cuit_ie, cuit_ata,
codigo, url, familias, ticket, hashing, cantidad_total)
print r
print "hecho."
except SoapFault,e:
print "Falla SOAP:", e.faultcode, e.faultstring.encode("ascii","ignore")
sys.exit(3)
except Exception, e:
print unicode(e).encode("ascii","ignore")
if DEBUG:
raise
sys.exit(5)