def calculate_total_price(self, dollar_quote): total = 0 for purchase in self.purchases: if purchase.price.currency == self.local_currency: total += purchase.price.amount else: total += purchase.price.amount * dollar_quote.amount return Money(total)
def call_print(self): report = self.bill.print(dollar_quote=Money(4)) return report
def test_report_with_one_international_purchase(self): self.bill.add_purchase(Purchase(name='ROSS', price=Money(amount=100, currency='USD'))) report = self.call_print() self.assertEqual('COMPRA|VALOR\nROSS|100 USD\n_\nCOTACAO USD|4 BRL\n_\nVALOR TOTAL|400 BRL', report)
def test_report_with_more_than_one_local_purchase(self): self.bill.add_purchase(Purchase(name='LOJAS AMERICANAS', price=Money(amount=250))) self.bill.add_purchase(Purchase(name='LOJAS RENNER', price=Money(amount=100))) report = self.call_print() self.assertEqual('COMPRA|VALOR\nLOJAS AMERICANAS|250 BRL\nLOJAS RENNER|100 BRL\n_\nVALOR TOTAL|350 BRL', report)
def test_add_purchases(self): self.bill.add_purchase(Purchase(name='LOJAS AMERICANAS', price=Money(amount=250))) self.bill.add_purchase(Purchase(name='A', price=Money(amount=250))) self.assertEqual(2, len(self.bill.purchases))
def test_print_money(self): money = Money(amount=25) self.assertEqual(money.print(), '25 BRL')
def test_default_currency_on_money(self): money = Money(amount=25) self.assertEqual(money.currency, 'BRL')