Giter Club home page Giter Club logo

django-prices-vatlayer's Introduction

django-prices-vatlayer: Vatlayer API support for prices

Build Status codecov.io

from prices import Money, TaxedMoney
from django_prices_vatlayer.utils import (
    get_tax_for_rate, get_tax_rates_for_country)

de_tax_rates = get_tax_rates_for_country('DE')
books_tax = get_tax_for_rate(de_tax_rates, 'books')

price_with_vat = books_tax(Money(10, 'EUR'))
print(price_with_vat)
# TaxedMoney(net=Money('10', 'EUR'), gross=Money('11', 'EUR'))

price_with_vat = books_tax(
    TaxedMoney(net=Money(10, 'EUR'), gross=Money(10, 'EUR')))
print(price_with_vat)
# TaxedMoney(net=Money('10', 'EUR'), gross=Money('11', 'EUR'))

Installation

The package can easily be installed via pip:

pip install django-prices-vatlayer

After installation, you'll also need to setup your site to use it. To do that, open your settings.py and do the following:

  1. Add 'django_prices_vatlayer', to your INSTALLED_APPS
  2. Add VATLAYER_ACCESS_KEY = 'YOUR_API_KEY_HERE' line
  3. Replace YOUR_API_KEY_HERE with the API key that you have obtained from vatlayer API

Lastly, run manage.py migrate to create new tables in your database and manage.py get_vat_rates to populate them with initial data.

Forcing secure API connection in production

Because HTTPS is unavailable in the free vatlayer plan, django-prices-vatlayer uses the unsafe HTTP connection by default.

If you are using a paid plan, you can force the secure HTTP on your site by adding following line to your settings.py:

VATLAYER_USE_HTTPS = True

Remember that not using HTTPS may expose you to DNS poisoning and man-in-the-middle attacks; we recommend enabling VATLAYER_USE_HTTPS in production sites.

Updating VAT rates

To get current VAT rates from the API run the get_vat_rates management command.

You may also set cron job for running this task daily to always be up to date with current tax rates.

django-prices-vatlayer's People

Contributors

artursmet avatar maarcingebala avatar maclake avatar mad-anne avatar nyankiyoshi avatar patrys avatar piotrantosz avatar rafalp avatar szewczykmira avatar

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.