def autorizar(client, token, sign, cuit, entrada, salida): # recupero el último número de transacción ##id = wsfex.ultnro(client, token, sign, cuit) detalles = [] permisos = [] cbtasocs = [] encabezado = {} for linea in entrada: if str(linea[0]) == '0': encabezado = leer(linea, ENCABEZADO) elif str(linea[0]) == '1': detalle = leer(linea, DETALLE) detalles.append(detalle) elif str(linea[0]) == '2': permiso = leer(linea, PERMISO) permisos.append(permiso) elif str(linea[0]) == '3': cbtasoc = leer(linea, CMP_ASOC) cbtasocs.append(cbtasoc) else: print "Tipo de registro incorrecto:", linea[0] if not encabezado['id'].strip() or int(encabezado['id']) == 0: # TODO: habria que leer y/o grabar el id en el archivo ##id += 1 # incremento el nº de transacción # Por el momento, el id se calcula con el tipo, pv y nº de comprobant i = long(encabezado['cbte_nro']) i += (int(encabezado['cbte_nro']) * 10**4 + int(encabezado['punto_vta'])) * 10**8 encabezado['id'] = wsfex.get_last_id(client, token, sign, cuit)[0] + 1 factura = wsfex.FacturaEX(**encabezado) for detalle in detalles: it = wsfex.ItemFEX(**detalle) factura.add_item(it, calcular=False) for permiso in permisos: p = wsfex.PermisoFEX(**permiso) factura.add_permiso(p) for cbtasoc in cbtasocs: c = wsfex.CmpAsocFEX(**cbtasoc) factura.add_cmp_asoc(c) if DEBUG: #print f.to_dict() print '\n'.join( ["%s='%s'" % (k, str(v)) for k, v in factura.to_dict().items()]) print 'id:', encabezado['id'] if not DEBUG or raw_input("Facturar?") == "S": dic = factura.to_dict() auth, events = wsfex.authorize(client, token, sign, cuit, id=encabezado['id'], factura=dic) dic.update(auth) escribir_factura(dic, salida) print "ID:", dic['id'], "CAE:", dic['cae'], "Obs:", dic[ 'obs'], "Reproceso:", dic['reproceso']
def autorizar(client, token, sign, cuit, entrada, salida): # recupero el último número de transacción ##id = wsfex.ultnro(client, token, sign, cuit) detalles = [] permisos = [] cbtasocs = [] encabezado = {} for linea in entrada: if str(linea[0])=='0': encabezado = leer(linea, ENCABEZADO) elif str(linea[0])=='1': detalle = leer(linea, DETALLE) detalles.append(detalle) elif str(linea[0])=='2': permiso = leer(linea, PERMISO) permisos.append(permiso) elif str(linea[0])=='3': cbtasoc = leer(linea, CMP_ASOC) cbtasocs.append(cbtasoc) else: print "Tipo de registro incorrecto:", linea[0] if not encabezado['id'].strip() or int(encabezado['id'])==0: # TODO: habria que leer y/o grabar el id en el archivo ##id += 1 # incremento el nº de transacción # Por el momento, el id se calcula con el tipo, pv y nº de comprobant i = long(encabezado['cbte_nro']) i += (int(encabezado['cbte_nro'])*10**4 + int(encabezado['punto_vta']))*10**8 encabezado['id'] = wsfex.get_last_id(client, token, sign, cuit)[0] + 1 factura = wsfex.FacturaEX(**encabezado) for detalle in detalles: it = wsfex.ItemFEX(**detalle) factura.add_item(it, calcular=False) for permiso in permisos: p = wsfex.PermisoFEX(**permiso) factura.add_permiso(p) for cbtasoc in cbtasocs: c = wsfex.CmpAsocFEX(**cbtasoc) factura.add_cmp_asoc(c) if DEBUG: #print f.to_dict() print '\n'.join(["%s='%s'" % (k,str(v)) for k,v in factura.to_dict().items()]) print 'id:', encabezado['id'] if not DEBUG or raw_input("Facturar?")=="S": dic = factura.to_dict() auth, events = wsfex.authorize(client, token, sign, cuit, id=encabezado['id'], factura=dic) dic.update(auth) escribir_factura(dic, salida) print "ID:", dic['id'], "CAE:",dic['cae'],"Obs:",dic['obs'],"Reproceso:",dic['reproceso']
def GetLastID(self): "Recuperar último número de transacción (ID)" try: # limpio errores self.Exception = self.Traceback = "" self.ErrCode = self.ErrMsg = "" # llamo al web service id, events = wsfex.get_last_id(self.client, self.Token, self.Sign, self.Cuit) return id except wsfex.FEXError, e: self.ErrCode = unicode(e.code) self.ErrMsg = unicode(e.msg) if self.LanzarExcepciones: raise COMException(scode = vbObjectError + int(e.code), desc=unicode(e.msg), source="WebService")
def GetLastID(self): "Recuperar último número de transacción (ID)" try: # limpio errores self.Exception = self.Traceback = "" self.ErrCode = self.ErrMsg = "" # llamo al web service id, events = wsfex.get_last_id(self.client, self.Token, self.Sign, self.Cuit) return id except wsfex.FEXError, e: self.ErrCode = unicode(e.code) self.ErrMsg = unicode(e.msg) if self.LanzarExcepciones: raise COMException(scode=vbObjectError + int(e.code), desc=unicode(e.msg), source="WebService")
print " * Campo: %-20s Posición: %3d Longitud: %4d Tipo: %s Decimales: %s" % ( clave, comienzo, longitud, tipo, dec) comienzo += longitud sys.exit(0) # TODO: esto habría que guardarlo en un archivo y no tener que autenticar cada vez token, sign = autenticar(cert, privatekey, wsaa_url) if '/prueba' in sys.argv: # generar el archivo de prueba para la próxima factura fecha = date('Ymd') tipo_cbte = 19 punto_vta = 3 ult_cbte, fecha, events = wsfex.get_last_cmp(client, token, sign, cuit, tipo_cbte, punto_vta) ult_id, events = wsfex.get_last_id(client, token, sign, cuit) f_entrada = open(entrada,"w") f = wsfex.FacturaEX() f.punto_vta = punto_vta f.cbte_nro = ult_cbte+1 f.imp_moneda_id = 'PES' f.fecha_cbte = date('Ymd') f.tipo_expo = 1 f.permiso_existente = 'S' f.dst_cmp = 203 f.cliente = 'Joao Da Silva' f.cuit_pais_cliente = 50000000016 f.domicilio_cliente = 'Rua 76 km 34.5 Alagoas' f.id_impositivo = 'PJ54482221-l'
clave, comienzo, longitud, tipo, dec) comienzo += longitud sys.exit(0) # TODO: esto habría que guardarlo en un archivo y no tener que autenticar cada vez token, sign = autenticar(cert, privatekey, wsaa_url) if '/prueba' in sys.argv: # generar el archivo de prueba para la próxima factura fecha = date('Ymd') tipo_cbte = 19 punto_vta = 3 ult_cbte, fecha, events = wsfex.get_last_cmp( client, token, sign, cuit, tipo_cbte, punto_vta) ult_id, events = wsfex.get_last_id(client, token, sign, cuit) f_entrada = open(entrada, "w") f = wsfex.FacturaEX() f.punto_vta = punto_vta f.cbte_nro = ult_cbte + 1 f.imp_moneda_id = 'PES' f.fecha_cbte = date('Ymd') f.tipo_expo = 1 f.permiso_existente = 'S' f.dst_cmp = 203 f.cliente = 'Joao Da Silva' f.cuit_pais_cliente = 50000000016 f.domicilio_cliente = 'Rua 76 km 34.5 Alagoas' f.id_impositivo = 'PJ54482221-l'