Ejemplo n.º 1
0
 def Authorize(self, id):
     "Autoriza la factura en memoria (interna)"
     try:
         # limpio errores
         self.Exception = self.Traceback = ""
         self.ErrCode = self.ErrMsg = ""
         # llamo al web service
         auth, events = wsbfe.authorize(self.client, 
                                  self.Token, self.Sign, self.Cuit, 
                                  id=id, factura=self.factura.to_dict())
                    
         # Resultado: A: Aceptado, R: Rechazado
         self.Resultado = auth['resultado']
         # Obs:
         self.Obs = auth['obs'].strip(" ")
         self.Reproceso = auth['reproceso']
         self.CAE = auth['cae']
         vto = str(auth['fch_venc_cae'])
         self.Vencimiento = "%s/%s/%s" % (vto[6:8], vto[4:6], vto[0:4])
         self.Eventos = ['%s: %s' % (evt['code'], evt['msg']) for evt in events]
         return self.CAE
     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")
Ejemplo n.º 2
0
    def Authorize(self, id):
        "Autoriza la factura en memoria (interna)"
        try:
            # limpio errores
            self.Exception = self.Traceback = ""
            self.ErrCode = self.ErrMsg = ""
            # llamo al web service
            auth, events = wsbfe.authorize(self.client,
                                           self.Token,
                                           self.Sign,
                                           self.Cuit,
                                           id=id,
                                           factura=self.factura.to_dict())

            # Resultado: A: Aceptado, R: Rechazado
            self.Resultado = auth['resultado']
            # Obs:
            self.Obs = auth['obs'].strip(" ")
            self.Reproceso = auth['reproceso']
            self.CAE = auth['cae']
            vto = str(auth['fch_venc_cae'])
            self.Vencimiento = "%s/%s/%s" % (vto[6:8], vto[4:6], vto[0:4])
            self.Eventos = [
                '%s: %s' % (evt['code'], evt['msg']) for evt in events
            ]
            return self.CAE
        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")
Ejemplo n.º 3
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']
Ejemplo n.º 4
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']