Skip to main content

AFIP integration for django

Project description

django-afip is a django application for interacting with AFIP’s web-services (and models all related data). For the moment only WSFE and WSAA are implemented.

build status version on pypi licence

Instalation

First install the actual package:

pip install django-afip

And then configure your project to use it by adding it to settings.py:

INSTALLED_APPS = (
    ...
    'django_afip',
    ...
)

If you want to use AFIP’s testing servers, then you’ll need to configure the app to do so:

AFIP_DEBUG = True

Getting started

First of all, you’ll need to create a taxpayer, and upload the related ssl key and certificate (for authorization). django-afip includes admin views for every model included, and it’s the recomended way to create one.

Once you have created a taxpayer, you’ll need its points of sales. This, again, should be done via the admin by selecting “fetch points of sales’. You may also do this programatically via TaxPayer.fetch_points_of_sales.

Finally, you’ll need to pre-populate certain models with AFIP-defined metadata.

Rather than include fixtures which require updating over time, a special view has been included for importing them from the WS with live data. Only a superuser can activate this population. This view is idempotent, and running it more than once will not create any duplicate data.

To access this view, add something like this to your views.py:

urlpatterns = [
    ...
    url(r'^__afip__/', include('django_afip.urls')),
    ...
]

Then visit http://example.com/__afip__/populate_models. This will retrieve Receipt Types, Document Types, and a few other data types from AFIP’s WS. Again, only a user with superuser priviledges may trigger this download.

This metadata can also be downloaded programatically, via models.populate_all().

You are now ready to start creating and validating receipts. While you may do this via the admin as well, you probably want to do this programatically or via some custom view.

PDF Receipts

Version 1.2.0 introduces PDF-generation for validated receipts. These may be exposed both as pdf or html with an existing view, for example, using:

url(
    r'^invoices/pdf/(?P<pk>\d+)?$',
    views.ReceiptPDFView.as_view(),
    name='receipt_view',
),
url(
    r'^invoices/html/(?P<pk>\d+)?$',
    views.ReceiptHTMLView.as_view(),
    name='receipt_view',
),

You’ll generally want to subclass this view, and add some authorization checks to it. If you want some other, more complex generation (like sending via email), these views should serve as a reference to the PDF API.

The template used for the HTML and PDF receipts is found in templates/django_afip/invoice.html. If you want to override the default (you probably do), simply place a template with the same path/name inside your own app, and make sure it’s listed before django_afip in INSTALLED_APPS.

Contributing

Unit tests are run via tox. Any code contributions must pass all tests. New features must include corresponding unit tests. Any bugfixes must include tests that fail without it, and pass with it.

Note that tests use AFIP’s testing servers and a specific key that’s know to contain at least one point of sale.

Licence

This software is distributed under the ISC licence. See LICENCE for details.

Copyright (c) 2015 Hugo Osvaldo Barrera <hugo@barrera.io>

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

django_afip-1.2.0-py3-none-any.whl (37.1 kB view details)

Uploaded Python 3

File details

Details for the file django_afip-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_afip-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0b87ec5a57ec22c2d86d1a12cfccba56bd673d8fcf45baf8d5f14db5e6388fbd
MD5 e2b05b43d3014d480d883d7724d97f44
BLAKE2b-256 98df40fe727c1ff5a5ccc7081f4f84cbd1ae56651bd9f17c3c1a49e70429c580

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page