コード例 #1
0
ファイル: varahaldur.py プロジェクト: nostneji/PDAM
 def buy(self, vara_id, tkpv, vkpv, kogus, summa, valuuta): # ost
     v = Vara.objects.get(id=vara_id)
     ts = Varatehing.objects.all().filter(vara=v, tyyp='O', vaartuspaev=vkpv, valuuta=valuuta)
     chk = 0
     for t in ts:
         if kogus == float(t.kogus) and summa==float(t.summa):
             chk += 1
     if chk == 0:
         vts = Varatehing.objects.all().filter(vara=v, vaartuspaev__lte=vkpv).order_by('vaartuspaev','-tyyp','-kogus')
         l_vt = ''
         for vt in vts:
             l_vt = vt
         e_sum = summa
         if valuuta != 'EUR':
             c = Currency()
             e_sum = c.convert(vkpv, valuuta, 'EUR', summa)
         yk = Decimal(kogus)
         sh = Decimal(e_sum)
         th = Decimal(e_sum)
         rs = Decimal(0)
         if l_vt != '':
             yk = yk + l_vt.yldkogus
             sh = sh + l_vt.soetushind
             if e_sum != 0:
                 th = Decimal(e_sum) * yk / Decimal(kogus)
             else:
                 th = sh
             rs = th - sh
         Varatehing.objects.create(vara=v, tyyp='O', tehingupaev=tkpv, vaartuspaev=vkpv, 
                                   kogus=kogus, summa=summa, valuuta=valuuta,
                                   eur_summa=e_sum, yldkogus=yk, soetushind=sh, 
                                   turuhind=th, reserv=rs)
     return 0
コード例 #2
0
ファイル: tests.py プロジェクト: nostneji/PDAM
 def test_remote_service(self):
     """
     Invoke web page with currency rates and calculate value
     """
     c = Currency()
     v = round(c.convert(date(2012,4,10), 'EUR', 'USD', 2.0),2)
     self.assertEqual(v, 2.62)
コード例 #3
0
ファイル: varahaldur.py プロジェクト: nostneji/PDAM
 def reprize(self, vara_id, vkpv, kogus, summa, valuuta): # ümbrhindlus
     dr = 0
     v = Vara.objects.get(id=vara_id)
     ts = Varatehing.objects.all().filter(vara=v, tyyp='H', vaartuspaev=vkpv, valuuta=valuuta)
     chk = 0
     for t in ts:
         if kogus == float(t.kogus) and summa==float(t.summa):
             chk += 1
     if chk == 0:
         vts = Varatehing.objects.all().filter(vara=v, vaartuspaev__lte=vkpv).order_by('vaartuspaev','-tyyp','-kogus')
         l_vt = ''
         for vt in vts:
             l_vt = vt
         e_sum = summa
         if valuuta != 'EUR':
             c = Currency()
             e_sum = c.convert(vkpv, valuuta, 'EUR', summa)
         if l_vt != '':
             if kogus != float(l_vt.yldkogus):
                 print '>>> Error: Not the same amount!', v
                 return 0
             yk = l_vt.yldkogus
             sh = l_vt.soetushind
             th = Decimal(e_sum)
             rs = th - sh 
             dr = rs - l_vt.reserv
         else:
             print '>>> Error: Nothing to reprize!', v
             return 0
         Varatehing.objects.create(vara=v, tyyp='H', tehingupaev=vkpv, vaartuspaev=vkpv, 
                                   kogus=kogus, summa=summa, valuuta=valuuta,
                                   eur_summa=e_sum, yldkogus=yk, soetushind=sh, 
                                   turuhind=th, reserv=rs)
     return dr
コード例 #4
0
    def test_get_money_with_currency_format(self):
        currency = Currency('USD')

        self.assertEqual(currency.get_money_with_currency_format(13.99),
                         '$13.99 USD')
        self.assertEqual(currency.get_money_with_currency_format('13,2313,33'),
                         '$13,2313,33 USD')
コード例 #5
0
    def test_get_money_with_currency_format(self):
        currency = Currency('USD')

        self.assertEqual(currency.get_money_with_currency_format(13.99), '$13.99 USD')
        self.assertEqual(
            currency.get_money_with_currency_format('13,2313,33'),
            '$13,2313,33 USD'
        )
コード例 #6
0
    def test_set_money_currency(self):
        currency = Currency('USD')

        self.assertEqual(currency.get_money_currency(), 'USD')
        self.assertEqual(currency.get_money_format(13), '$13')

        currency.set_money_currency('AED')

        self.assertEqual(currency.get_money_currency(), 'AED')
        self.assertEqual(currency.get_money_format(13), 'Dhs. 13')
コード例 #7
0
    def test_set_money_currency(self):
        currency = Currency('USD')

        self.assertEqual(currency.get_money_currency(), 'USD')
        self.assertEqual(currency.get_money_format(13), '$13')

        currency.set_money_currency('AED')

        self.assertEqual(currency.get_money_currency(), 'AED')
        self.assertEqual(currency.get_money_format(13), 'Dhs. 13')
コード例 #8
0
ファイル: varahaldur.py プロジェクト: nostneji/PDAM
 def sell(self, vara_id, tkpv, vkpv, kogus, summa, valuuta): # müük
     dr = 0
     v = Vara.objects.get(id=vara_id)
     ts = Varatehing.objects.all().filter(vara=v, tyyp='M', vaartuspaev=vkpv, valuuta=valuuta)
     chk = 0
     for t in ts:
         if abs(kogus) == float(t.kogus) and summa==float(t.summa):
             chk += 1
     if chk == 0:
         vts = Varatehing.objects.all().filter(vara=v, vaartuspaev__lte=vkpv).order_by('vaartuspaev','-tyyp','-kogus')
         l_vt = ''
         for vt in vts:
             l_vt = vt
         e_sum = summa
         if valuuta != 'EUR':
             c = Currency()
             e_sum = c.convert(vkpv, valuuta, 'EUR', summa)
         yk = 0
         sh = 0 
         th = 0
         rs = 0
         if l_vt != '':
             if float(l_vt.yldkogus) - abs(kogus) < 0 and abs(float(l_vt.yldkogus) - abs(kogus)) > 0.000001:
                 print '>>> Error: Trying to sell more than we have!', abs(float(l_vt.yldkogus) - abs(kogus)), v
                 return 0
             yk = l_vt.yldkogus - Decimal(abs(kogus))
             if float(yk) < 0:
                 yk = Decimal(0)
             sh = l_vt.soetushind * Decimal(yk) / l_vt.yldkogus
             th = Decimal(e_sum) * yk / Decimal(abs(kogus))
             rs = th - sh
             dr = rs - l_vt.reserv
         else:
             print '>>> Error: Trying to sell, but we have not any!', v
             return 0
         Varatehing.objects.create(vara=v, tyyp='M', tehingupaev=tkpv, vaartuspaev=vkpv, 
                                   kogus=abs(kogus), summa=summa, valuuta=valuuta,
                                   eur_summa=e_sum, yldkogus=yk, soetushind=sh, 
                                   turuhind=th, reserv=rs)
     return dr
コード例 #9
0
    def test_get_currency_formats(self):
        currency_formats = Currency.get_currency_formats()

        self.assertIsNotNone(currency_formats)
        self.assertIsInstance(currency_formats, list)
        self.assertGreater(len(currency_formats), 0)
コード例 #10
0
ファイル: deals.py プロジェクト: nostneji/PDAM
def nok2eur(amount, when):
    c = Currency()    
    return round(c.convert(when, 'NOK', 'EUR', amount),2)
コード例 #11
0
ファイル: deals.py プロジェクト: nostneji/PDAM
def gbp2eur(amount, when):
    c = Currency()    
    return round(c.convert(when, 'GBP', 'EUR', amount),2) 
コード例 #12
0
ファイル: deals.py プロジェクト: nostneji/PDAM
def eur2usd(amount, when):
    c = Currency()    
    return round(c.convert(when, 'EUR', 'USD', amount),2)
コード例 #13
0
 def to_representation(self, price):
     currency = Currency('BRL')
     return currency.get_money_format(price)
コード例 #14
0
    def test_get_money_currency(self):
        currency = Currency('USD')

        self.assertIsInstance(currency.get_money_currency(), str)
        self.assertEqual(currency.get_money_currency(), 'USD')
コード例 #15
0
    def test_get_money_currency(self):
        currency = Currency('USD')

        self.assertIsInstance(currency.get_money_currency(), str)
        self.assertEqual(currency.get_money_currency(), 'USD')
コード例 #16
0
ファイル: money_test.py プロジェクト: guoyy2017/python_util
#!/usr/bin/env python
# encoding: utf-8
'''
@author:maidou
@contact:QQ4113291000
@time:2018/4/28.上午11:13
'''
'''
显示货币格式以及它的数值
'''
from currencies import Currency

currency = Currency('USD')
print currency.get_money_format(13)
print currency.get_money_format('13,2313,33')
print currency.get_money_format('13,231,333')
print currency.get_money_with_currency_format(13.99)

if __name__ == '__main__':
    pass
コード例 #17
0
    def test_get_currency_formats(self):
        currency_formats = Currency.get_currency_formats()

        self.assertIsNotNone(currency_formats)
        self.assertIsInstance(currency_formats, list)
        self.assertGreater(len(currency_formats), 0)