Giter Site home page Giter Site logo

facturama-python-sdk's People

Contributors

diegordzr avatar joseromeronet avatar oscarmorado avatar rafa-dx avatar zeuzmac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

facturama-python-sdk's Issues

Return PDF shouldn't assume that type is issuedLite by default

facturama.version = '2.0.3'
Metodo = facturama.Cfdi

Los siguientes metodos: saveAsPdf, saveAsXml y saveAsHtml no cumplen con lo necesitado ya que asumen en el código que sea issuedLite la petición del cfdi y no siempre es así.

Estaría mejor agregar el tipo como parametro, para esto solo leyendo el código se puede observar que para este fin tienen get_by_file("pdf", "issued", "<ID-CFDI>") y regresa el json que esperamos pero nos toca a mano la conversión. Dejo el código citado

# replicate facturama cfdi docs and create a cfdi object
cfdi = facturama.Cfdi.create(cfdi_object)
# Get the ID
print cfdi.Id
>>> "QilvK5E6QtHPxGmMzcYd8"
# try to get pdf 
file = facturama.Cfdi.saveAsPdf("QilvK5E6QtHPxGmMzcYd8", "filename.pdf")
>>> cfdi.saveAsPdf("QilvK5E6QtHPxGmMzcYd8", "filename.pdf"
... )
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    cfdi.saveAsPdf("QilvK5E6QtHPxGmMzcYd8", "filename.pdf"
  File "/vagrant/prescript/src/facturama/facturama/__init__.py", line 228, in saveAsPdf
    html_file = cls.get_by_file('pdf', 'IssuedLite',oid)
  File "/vagrant/prescript/src/facturama/facturama/__init__.py", line 221, in get_by_file
    return cls.build_http_request('get', '{}/{}/{}/{}'.format(cls.__name__, f, t, oid))
  File "/vagrant/prescript/src/facturama/facturama/__init__.py", line 116, in build_http_request
    raise ResourceNotFoundError(body.json())
  File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 892, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/simplejson/__init__.py", line 518, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python2.7/dist-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/local/lib/python2.7/dist-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Esta forma si se obtiene el payload que se espera, pero sin convertir de base64

# try to get PDF using get_by_file
response = cfdi.get_by_file("pdf", "issued", "QilvK5E6QtHPxGmMzcYd8")
print response
>>> {
    "ContentEncoding": "base64",
    "ContentType": "xml",
    "ContentLength": 4960,
    "Content": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbm==..."}

When create a CFDI the sdk doesn't return the ID (SOLVED)

facturama.version = '2.0.3'
Endpoint = facturama.Cfdi.create
Payload = el mismo de su documentación
Cuando crean la factura esta se emite, pero la respuesta no tienen los datos del CFDi, inclusive el unico necesario es el ID pero no viene con la respuesta. Dejo el debug

import facturama
facturama.sandbox = True
payload = {
   #el mismo que la documentación
}
new_cfdi = facturama.Cfdi.create(payload.copy())

# Empiezo a tratar de ver el ID de la factura generada

print new_cfdi
> facturama.Cfdi

print cfdi.status
> True

print cfdi.__dict__
> {'status': True, '__module__': 'facturama', '_headers': {'content-type': 'application/json', 'Authorization': u'Basic amVzdXNwcmVz...'}, 'send_by_email': <classmethod 
object at 0x7f6ed61f7cc8>, 'create': <classmethod object at 0x7f6ed61f7be8>, 'list': <classmethod object at 0x7f6ed61f7d38>, 'saveAsPdf': <classmethod object at 0x7f6ed61f7c58>, 'get_by_fi
le': <classmethod object at 0x7f6ed61f7c20>, 'delete': <classmethod object at 0x7f6ed61f7d00>, '__doc__': '\n    Opr with Cfdi of Facturama API\n    ', 'saveAsHtml': <classmethod object at
 0x7f6ed61f7c90>}

Todos esos objetos son los mismos que tiene facturama.Cfdi
No tiene los atributos del cfdi, y por ende no localize el Id de la factura. Podrian ayudarme a saber como conseguirla, en su documentación no esta claro esto

The unauthenticated git protocol on port 9418 is no longer supported. (SOLVED)

facturama version: 3.0.2

PROBLEM:
Downloading the package as the readme recommend us gets the following github problem
pip install -e git://github.com/Facturama/facturama-python-sdk.git@master#egg=facturama

pip install -e git://github.com/Facturama/facturama-python-sdk.git@master#egg=facturama                                                             1 ↵
Obtaining facturama from git+git://github.com/Facturama/facturama-python-sdk.git@master#egg=facturama
 Cloning git://github.com/Facturama/facturama-python-sdk.git (to revision master) to ./.venv/src/facturama
 Running command git clone --filter=blob:none --quiet git://github.com/Facturama/facturama-python-sdk.git ./temp/.venv/src/facturama
 fatal: remote error:
   The unauthenticated git protocol on port 9418 is no longer supported.
 Please see https://github.blog/2021-09-01-improving-git-protocol-security-github/ for more information.
 error: subprocess-exited-with-error

SOLUTION
Although is a github update, the solution is updating the installation command line to:
pip install -e git+https://github.com/Facturama/facturama-python-sdk.git@master#egg=facturama

JSONDecodeError on ResourceNotFoundException

When using send_by_email and the CFDI does not exist a not found exception should be returned, but, we receive a JSONDecodeError. Here is an image with the log trace:

image

It's related to this other issue #6

No error throw if not credential are provided. SDK validation previous to send request.

We got an error in our pipeline , the error throw is "simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)" , this error is raised here:

#src/facturama/facturama/__init__.py

 elif body.status_code == 401:
            raise AuthenticationError(body.json()) //here fails to parse the json

As the body response is not a json then a JSONDecodeError is thrown.

It would be really usefull if you add a validation than inspect credentials are not NONE (or falsy), the most common case is when environment or settings are not correctly set up (for instance in a new deployment), or even in a integration phase.

The place were the validation could be implemented is:

    @classmethod
    def aut_api(cls):
        _username, _password = _credentials # here check that both username and password are not false or explicity to None and ''
       if not _username or not _password:
            raise FacturamaError('username or password are not set') #the custom error and message that you consider useful
        cls._headers = {
            'Authorization': 'Basic %s' % (base64.b64encode(
                ('{}:{}'.format(_username, _password)).encode('utf-8'))).decode('ascii'),
            'content-type': 'application/json'
        } 

delete api-lite

when delete cfdi return 404, changing version to 2 solves problem

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.