def test_get_amount_str(self): self.assertEqual("0.00", util.get_amount_str(-0.00000000000001)) self.assertEqual("0.00", util.get_amount_str(0.000000000000001)) self.assertEqual("0.01", util.get_amount_str(0.006)) self.assertEqual("3.56", util.get_amount_str(3.56)) self.assertEqual("3.56", util.get_amount_str(3.561111111111111)) self.assertEqual("5.00", util.get_amount_str(5))
def finish_balancing(self): if self.ending_balance is None: print('*** Ending balance must be set in order to finish') return if util.get_amount_str(self.get_zero_candidate()) != '0.00': print('"To zero" must be zero in order to finish') return for thing in self.open_transactions: if thing.is_pending(): thing.set_cleared() self.ending_balance = None self.ending_date = date.today() self.ledgerfile.write_file() self.save_statement_info_to_cache() self.populate_open_transactions()
def set_statement_info(self): if self.ending_balance is not None: print( "(Enter 'cancel' to remove ending balance and set " "ending date to today.)" ) old_ending_date = self.ending_date while True: date_str = util.get_date_string(self.ending_date) new_date = self.get_response( prompt='Ending Date (YYYY/MM/DD)', old_value=date_str ) if self.cancel_statement(new_date): return try: self.ending_date = util.get_date(new_date) break except ValueError: print('*** Invalid date') new_ending_balance = None if self.ending_balance is None: old_ending_balance = None else: old_ending_balance = util.get_amount_str( self.ending_balance ) while True: new_ending_balance = self.get_response( prompt='Ending Balance', old_value=old_ending_balance ) if new_ending_balance is None: break if self.cancel_statement(new_ending_balance): return try: self.ending_balance = float( new_ending_balance.replace('$', '') ) break except ValueError: print('*** Invalid number') if new_ending_balance is not None: new_ending_balance = util.get_amount_str( self.ending_balance ) # only list and save to cache if values have changed... if old_ending_date != self.ending_date \ or old_ending_balance != new_ending_balance: self.save_statement_info_to_cache() self.list_transactions()