Giter Club home page Giter Club logo

django-prices-openexchangerates's Introduction

openexchangerates.org support for django-prices

from prices import Price
from django_prices_openexchangerates import exchange_currency

converted_price = exchange_currency(Price(10, currency='USD'), 'EUR')
print(converted_price)
# Price('8.84040', currency='EUR')
print(converted_price.history)
# (Price('10', currency='USD') | CurrencyConversion('USD', 'EUR', rate=Decimal('0.88404')))

It will also create additional steps if it cannot convert directly:

from prices import Price
from django_prices_openexchangerates import exchange_currency

converted_price = exchange_currency(Price(10, currency='GBP'), 'EUR')
print(converted_price)
# Price('13.31313588062401085236264978', currency='EUR')
print(converted_price.history)
# ((Price('10', currency='GBP') | CurrencyConversion('GBP', 'USD', rate=Decimal('1.507272590247946341095787173'))) | CurrencyConversion('USD', 'EUR', rate=Decimal('0.88326')))

Templatetags can be used to convert currency and round amounts:

{% load prices_multicurrency %}

<p>Price: {% gross_in_currency foo.price 'USD' %} ({% net_in_currency foo.price 'USD' %} + {% tax_in_currency foo.price 'USD' %} tax)</p>

When you install babel-django library, you can use i18n templatetags and display proper currency symbols

{% load prices_multicurrency_i18n %}

<p>Price: {% gross_in_currency foo.price 'USD' %} ({% net_in_currency foo.price 'USD' %} + {% tax_in_currency foo.price 'USD' %} tax)</p>

Installation

First install the package:

pip install django-prices-openexchangerates

Then add 'django_prices_openexchangerates' to your INSTALLED_APPS.

Set following settings in your project's settings:

  • OPENEXCHANGERATES_API_KEY

  • OPENEXCHANGERATES_BASE_CURRENCY (defaults to 'USD', only premium accounts support other bases)

Use your admin console to create ConversionRate objects for each currency that you want to support.

Updating exchange rates

Fetch current rates from API with ./manage.py update_exchange_rates

Schedule this task in cron job or in celery, to be always up to date with exchange rates

django-prices-openexchangerates's People

Contributors

artursmet avatar bogdal avatar mociepka avatar patrys avatar

Watchers

 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.