Exemplo n.º 1
0
 def convert_amount(self, amount, target_currency, date):
     """Convert an amount to a specific currency."""
     # TODO(blais): Save the amount here too.
     return convert.convert_amount(amount,
                                   target_currency,
                                   self.price_map,
                                   date=date)
Exemplo n.º 2
0
 def _convert_cost(self, node, date) -> amount.Amount:
     account_cost_node = node.balance.reduce(convert.get_cost)
     cur, num = list(account_cost_node.items())[0]
     amt = amount.Amount(num, cur)
     account_cost_amt = convert.convert_amount(
         amt, self.operating_currency, g.ledger.price_map, date
     )
     return account_cost_amt
Exemplo n.º 3
0
 def test_convert_amount_with_date(self, entries, _, __):
     """
     2013-01-01 price  USD  1.20 CAD
     2014-01-01 price  USD  1.25 CAD
     2015-01-01 price  USD  1.30 CAD
     """
     price_map = prices.build_price_map(entries)
     for date, exp_amount in [
         (None, A('130 CAD')),
         (datetime.date(2015, 1, 1), A('130 CAD')),
         (datetime.date(2014, 12, 31), A('125 CAD')),
         (datetime.date(2014, 1, 1), A('125 CAD')),
         (datetime.date(2013, 12, 31), A('120 CAD')),
         (datetime.date(2013, 1, 1), A('120 CAD')),
         (datetime.date(2012, 12, 31), A('100 USD')),
     ]:
         self.assertEqual(
             exp_amount,
             convert.convert_amount(A('100 USD'), 'CAD', price_map, date))
Exemplo n.º 4
0
def convert_amount(context, amount_, currency, date=None):
    """Coerce an amount to a particular currency."""
    return convert.convert_amount(amount_, currency, context.price_map, date)
Exemplo n.º 5
0
 def convert_amount(self, amount, target_currency, date):
     # TODO(blais): Save the amount here too.
     return convert.convert_amount(amount,
                                   target_currency,
                                   self.price_map,
                                   date=date)
Exemplo n.º 6
0
 def test_convert_amount__noop(self):
     amt = A("127.00 USD")
     self.assertEqual(
         amt, convert.convert_amount(amt, "USD", self.PRICE_MAP_EMPTY))
     self.assertEqual(
         amt, convert.convert_amount(amt, "USD", self.PRICE_MAP_HIT))
Exemplo n.º 7
0
 def test_convert_amount__success(self):
     amt = A("127.00 USD")
     self.assertEqual(
         A("152.40 CAD"),
         convert.convert_amount(amt, "CAD", self.PRICE_MAP_HIT))
Exemplo n.º 8
0
 def test_convert_amount__fail(self):
     amt = A("127.00 USD")
     self.assertEqual(
         amt, convert.convert_amount(amt, "CAD", self.PRICE_MAP_EMPTY))
Exemplo n.º 9
0
 def __call__(self, context):
     args = self.eval_args(context)
     amount_, currency, date = args
     return convert.convert_amount(amount_, currency, context.price_map, date)