Example #1
0
def autorizar(client, token, sign, cuit, entrada, salida):
    # recupero el último número de transacción
    ##id = wsbfe.ultnro(client, token, sign, cuit)

    detalles = []
    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)
        else:
            print "Tipo de registro incorrecto:", linea[0]

    if not encabezado['id'].strip():
        # 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'] = i

    if not encabezado['zona'].strip():
        encabezado['zona'] = 0

    if 'testing' in sys.argv:
        ult_cbte, fecha, events = wsbfe.get_last_cmp(client, token, sign, cuit,
                                                     punto_vta, tipo_cbte)
        encabezado['cbte_nro'] = ult_cbte + 1
        ult_id, events = wsbfe.get_last_id(client, token, sign, cuit)
        encabezado['id'] = ult_id + 1

    ##encabezado['imp_moneda_ctz'] = 1.00
    factura = wsbfe.FacturaBF(**encabezado)
    for detalle in detalles:
        it = wsbfe.ItemBF(**detalle)
        factura.add_item(it, calc=False)

    if DEBUG:
        print '\n'.join(
            ["%s='%s'" % (k, v) for k, v in factura.to_dict().items()])
        print 'id:', encabezado['id']
    if not DEBUG or raw_input("Facturar?") == "S":
        auth, events = wsbfe.authorize(client,
                                       token,
                                       sign,
                                       cuit,
                                       id=encabezado['id'],
                                       factura=factura.to_dict())
        dic = factura.to_dict()
        dic.update(auth)
        escribir_factura(dic, salida)
        print "ID:", dic['id'], "CAE:", dic['cae'], "Obs:", dic[
            'obs'], "Reproceso:", dic['reproceso']
Example #2
0
def autorizar(client, token, sign, cuit, entrada, salida):
    # recupero el último número de transacción
    ##id = wsbfe.ultnro(client, token, sign, cuit)

   
    detalles = []
    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)
        else:
            print "Tipo de registro incorrecto:", linea[0]

    if not encabezado['id'].strip():
        # 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'] = i

    if not encabezado['zona'].strip():
        encabezado['zona'] = 0

    if 'testing' in sys.argv:
        ult_cbte, fecha, events = wsbfe.get_last_cmp(client, token, sign, cuit, punto_vta, tipo_cbte)
        encabezado['cbte_nro'] = ult_cbte + 1
        ult_id, events = wsbfe.get_last_id(client, token, sign, cuit)
        encabezado['id'] = ult_id + 1    
   
    ##encabezado['imp_moneda_ctz'] = 1.00
    factura = wsbfe.FacturaBF(**encabezado)
    for detalle in detalles:
        it = wsbfe.ItemBF(**detalle)
        factura.add_item(it,calc=False)
            
    if DEBUG:
        print '\n'.join(["%s='%s'" % (k,v) for k,v in factura.to_dict().items()])
        print 'id:', encabezado['id']
    if not DEBUG or raw_input("Facturar?")=="S":
        auth, events = wsbfe.authorize(client, token, sign, cuit, 
                                       id=encabezado['id'],
                                       factura=factura.to_dict())
        dic = factura.to_dict()
        dic.update(auth)
        escribir_factura(dic, salida)
        print "ID:", dic['id'], "CAE:",dic['cae'],"Obs:",dic['obs'],"Reproceso:",dic['reproceso']
Example #3
0
 def GetLastID(self):
     "Recuperar último número de transacción (ID)"
     try:
         # limpio errores
         self.Exception = self.Traceback = ""
         self.ErrCode = self.ErrMsg = ""
         id, events = wsbfe.get_last_id(self.client, 
                                 self.Token, self.Sign, self.Cuit)
         return id
     except wsbfe.BFEError, 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")
Example #4
0
 def GetLastID(self):
     "Recuperar último número de transacción (ID)"
     try:
         # limpio errores
         self.Exception = self.Traceback = ""
         self.ErrCode = self.ErrMsg = ""
         id, events = wsbfe.get_last_id(self.client, self.Token, self.Sign,
                                        self.Cuit)
         return id
     except wsbfe.BFEError, 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")
Example #5
0
                    print " * Campo: %-20s Posición: %3d Longitud: %4d Tipo: %s" % (
                        clave, comienzo, longitud, tipo)
                    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 or False:
            # generar el archivo de prueba para la próxima factura
            fecha = date('Ymd')
            tipo_cbte = 1
            punto_vta = 2
            ult_cbte, fecha, events = wsbfe.get_last_cmp(
                client, token, sign, cuit, punto_vta, tipo_cbte)
            ult_id, events = wsbfe.get_last_id(client, token, sign, cuit)

            f_entrada = open(entrada, "w")

            f = wsbfe.FacturaBF()
            f.punto_vta = punto_vta
            f.cbte_nro = ult_cbte + 1
            f.imp_moneda_id = 'PES'
            f.fecha_cbte = date('Ymd')
            it = wsbfe.ItemBF(ncm='7308.10.00',
                              sec='',
                              ds='prueba',
                              qty=2.0,
                              precio=100.0,
                              bonif=0.0,
                              iva_id=5)
Example #6
0
                for (clave, longitud, tipo) in formato:
                    print " * Campo: %-20s Posición: %3d Longitud: %4d Tipo: %s" % (
                        clave, comienzo, longitud, tipo)
                    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 or False:
            # generar el archivo de prueba para la próxima factura
            fecha = date('Ymd')
            tipo_cbte = 1
            punto_vta = 2
            ult_cbte, fecha, events = wsbfe.get_last_cmp(client, token, sign, cuit, punto_vta, tipo_cbte)
            ult_id, events = wsbfe.get_last_id(client, token, sign, cuit)

            f_entrada = open(entrada,"w")

            f = wsbfe.FacturaBF()
            f.punto_vta = punto_vta
            f.cbte_nro = ult_cbte+1
            f.imp_moneda_id = 'PES'
            f.fecha_cbte = date('Ymd')
            it = wsbfe.ItemBF(ncm='7308.10.00', sec='', ds='prueba', qty=2.0, precio=100.0, bonif=0.0, iva_id=5)
            f.add_item(it)
            it = wsbfe.ItemBF(ncm='7308.20.00', sec='', ds='prueba 2', qty=4.0, precio=50.0, bonif=10.0, iva_id=5)
            f.add_item(it)
            ##print f.to_dict()

            dic = f.to_dict()