Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions ejemplos/wsa122r/wsa122r.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
Attribute VB_Name = "Module1"
' Ejemplo de Uso de Interface COM para
' Iniciar una declaracion jurada, dar de alta comprobantes de retetencion,
' consultar dj y cmp
' 2025 (C) Mariano Reingart <reingart@gmail.com>
' Licencia: GPLv3

Sub Main()
Dim a122r As Object, ok As Variant
Dim idp As Object
' Crear la interfaz COM
Set a122r = CreateObject("WSA122r")
' Crear objeto interface Web Service Autenticaci�n y Autorizaci�n
Set idp = CreateObject("WSIDP")

Debug.Print a122r.Version
Debug.Print a122r.InstallDir

Debug.Print idp.Version
Debug.Print idp.InstallDir

' Solicitar datos a ARBA
cuit_agente = ""
cit = ""
client_id = ""
secret = ""

' Consigo token para autenticarme
token = idp.ObtenerToken(cuit_agente, cit, client_id, secret) ' Url por defecto homologacion

Debug.Print ">> Token: ", token

' Seteo el token
a122r.SetToken (token)

' Conecto al servidor de ARBA
ok = a122r.Conectar() ' Url por defecto homologacion

' Inicio una DJ
actividad_id = 6
anio = 2026
mes = 2
quincena = 1
' ok = a122r.IniciarDj(cuit_agente, actividad_id, anio, mes, quincena)
' Debug.Print ">> ID de DJ iniciada: ", a122r.IdDj

' si no quiero iniciar una nueva dj consulto el Id por per�odo
consulta_dj = ""
consulta_dj = a122r.ConsultarDj(cuit_agente, 0, actividad_id, anio, mes, quincena)

Debug.Print ">> ID de DJ consultada: ", a122r.IdDj
Debug.Print ">> Datos de la DJ consultda: ", consulta_dj

' Creo un Comprobante Interno
cuit_contribuyente = "" ' Ingresar un cuit
sucursal = "00002"
alicuota = 1.75
base_imponible = 90000
importe_retencion = 1575
razon_social_contribuyente = "" ' Relacionado al cuit
fecha_operacion = "2026-02-03T00:00:00" ' Si no entra dentro del per�odo de la DJ va a fallar
n_transaccion_agente = 5

ok = a122r.CrearComprobanteInterno(cuit_contribuyente, cuit_agente, sucursal, _
alicuota, base_imponible, importe_retencion, razon_social_contribuyente, _
fecha_operacion, n_transaccion_agente)

' Agrego la direccion (datos relacionados al cuit)
calle = ""
numero = ""
piso = ""
depto = ""
codigo_postal = ""
localidad = ""
provincia = ""

ok = a122r.AgregarDireccion(calle, numero, piso, depto, codigo_postal, _
localidad, provincia)

' Doy de alta el comprobante
' ok = a122r.AltaComprobante(a122r.IdDj, cuit_agente)
' Debug.Print ">> Id Comprobante: ", a122r.IdComprobante

' Si no quiero dar de alta un nuevo comprobante consulto el Id por per�odo
' y cuit del contribuyente
estado = "TODOS"
consulta_cmp = ""
consulta_cmp = a122r.ConsultarComprobante(cuit_agente, 0, anio, mes, _
quincena, cuit_contribuyente, estado)

Debug.Print ">> Id Comprobante Consultado: ", a122r.IdComprobante

' Imprimo el comprobante en PDF
ruta = a122r.InstallDir + "\cache\comp.pdf"
id_comp = a122r.IdComprobante
ok = a122r.ConsultarComprobantePdf(id_comp, ruta)

If ok Then
Debug.Print ">> PDF Generado En: ", ruta
End If

Debug.Print "------------ WSIDP DEBUG ------------"
Debug.Print ">> Request IDP: ", idp.Request
Debug.Print ">> Response IDP: "; idp.Response
Debug.Print ">> Treaceback IDP: "; idp.Traceback
Debug.Print ">> Excepcion IDP: "; idp.Excepcion
Debug.Print "------------ WSA122R DEBUG ------------"
Debug.Print ">> Request WSA122r: ", a122r.Request
' Debug.Print ">> Response WSA122r: "; a122r.Response
Debug.Print ">> Traceback WSA122r: ", a122r.Traceback
Debug.Print ">> Excepcion WSA122r: ", a122r.Excepcion
End Sub
30 changes: 30 additions & 0 deletions ejemplos/wsa122r/wsa122r.vbp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Type=Exe
Module=Module1; wsa122r.bas
Startup="Sub Main"
Command32=""
Name="wsa122r"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="."
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
ThreadPerObject=0
MaxNumberOfThreads=1

[MS Transaction Server]
AutoRefresh=1
1 change: 1 addition & 0 deletions ejemplos/wsa122r/wsa122r.vbw
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Module1 = 22, 29, 537, 446, Z
32 changes: 30 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,25 @@ def capturar_errores_wrapper(self, *args, **kwargs):
return False
return capturar_errores_wrapper


def inicializar_y_capturar_excepciones_basico(func):
"Decorador para inicializar y capturar errores (versión básica indep.)"
@functools.wraps(func)
def capturar_errores_wrapper(self, *args, **kwargs):
self.inicializar()
try:
return func(self, *args, **kwargs)
except:
ex = exception_info()
self.Excepcion = ex['name']
self.Traceback = ex['msg']
if self.client:
self.Response = self.client.response
self.Request = self.client.request
if self.LanzarExcepciones:
raise
else:
return False
return capturar_errores_wrapper
class BaseWS:
"Infraestructura basica para interfaces webservices de AFIP"

Expand Down Expand Up @@ -465,6 +483,9 @@ def __init__(self, location, enctype="multipart/form-data", trace=False,
self.cookies = None
self.method = "POST"
self.referer = None
self.extra_headers = {}
self.request = ""
self.response = ""

def multipart_encode(self, vars):
"Enconde form data (vars dict)"
Expand Down Expand Up @@ -509,11 +530,17 @@ def __call__(self, *args, **vars):
elif self.enctype == "application/x-www-form-urlencoded":
body = urlencode(vars)
content_type = self.enctype
elif self.enctype == "application/json":
body = vars.get('json_body') or ""
content_type = self.enctype
else:
body = None

# add headers according method, cookies, etc.:
headers={}
headers = self.extra_headers.copy()
# allow passing custom HTTP headers (e.g. Authorization) without affecting existing behavior
if isinstance(headers, dict):
headers.update(headers)
if self.method == "POST":
headers.update({
'Content-type': content_type,
Expand All @@ -535,6 +562,7 @@ def __call__(self, *args, **vars):
location, self.method, body=body, headers=headers )
self.response = response
self.content = content
self.request = "%s %s" % (self.method, location) + '\n'.join(["%s: %s" % (k,v) for k,v in headers.items()]) + "\n%s" % body

if self.trace:
print
Expand Down
Loading