Giter Club home page Giter Club logo

prices's Introduction

Prices: Python price handling for humans

Build Status codecov.io


Money:

from prices import Money
a = Money(10, 'USD')
a += Money(20, 'USD')
a.value
# Decimal('30')
a = a.quantize()
a.value
# Decimal('30.00')
a = Money('5.00', 'JPY')
a.quantize()
a.value
# Decimal('5')

Taxed money:

from prices import Money, TaxedMoney
p = TaxedMoney(net=Money(20, 'EUR'), gross=Money(30, 'EUR'))
p.net
# Money('20', 'EUR')
p.gross
# Money('30', 'EUR')
p.tax
# Money('10', 'EUR')
p = p.quantize()
p.net
# Money('20.00', 'EUR')

Taxed ranges:

from prices import Money, TaxedMoney, TaxedMoneyRange
price1 = TaxedMoney(Money(1, 'USD'), Money(1, 'USD'))
price2 = TaxedMoney(Money(10, 'USD'), Money(10, 'USD'))
pr = TaxedMoneyRange(price1, price2)
pr.min_price
# TaxedMoney(net=Money('1', 'USD'), gross=Money('1', 'USD'))
pr.max_price
# TaxedMoney(net=Money('10', 'USD'), gross=Money('10', 'USD'))
price3 = TaxedMoney(net=Money(5, 'USD'), gross=Money(5, 'USD'))
price3 in pr
# True
pr = pr.quantize()
pr.min_price.net
# Money('1.00', 'USD')

Taxes:

from decimal import Decimal
from prices import Money, TaxedMoney, TaxedMoneyRange, flat_tax
p = TaxedMoney(Money('1.99', 'GBP'), Money('1.99', 'GBP'))
p = flat_tax(p, Decimal('0.23'))
p = p.quantize()
p.gross
# Money('2.45', 'GBP')

While protecting you from all sorts of mistakes:

from prices import Money
Money(10, 'USD') < Money(15, 'GBP')
# ValueError: Cannot compare amounts in 'USD' and 'GBP'
from prices import Money, TaxedMoney
price1 = TaxedMoney(Money(5, 'BTC'), Money(5, 'BTC'))
price2 = TaxedMoney(Money(7, 'INR'), Money(7, 'INR'))
price1 + price2
# ValueError: Cannot add amount in 'BTC' to 'INR'

prices's People

Contributors

patrys avatar artursmet avatar maarcingebala avatar bogdal avatar koradon avatar pcompassion avatar si14 avatar rafalp avatar dependabot-preview[bot] avatar

Watchers

 avatar  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.