def main(): """ allows to append User's payments and clear them :return: nothing """ read = serialize_type()[0] write = serialize_type()[1] main_user = read() if main_user is None: main_user = User(0.00) while True: key = get_key() if key == '1': account = View.input_accounting() main_user.add_payment(account) elif key == '2': main_user.clear_payments() main_user.set_money(0.00) elif key == '3': View.print_payments(main_user) elif key == '4': write(main_user) return None else: print("You've entered incorrect value")
def encode_dict(dict): """ decodes user from dictionary :param dict: decoded user :return: new user """ # create new user ret_user = User() # set his money ret_user.set_money(decimal.Decimal(dict['money'])) for account in dict['payment list']: # set new accounting tmp_account = Accounting() date = account['datetime'] # set datetime tmp_account.set_datetime(datetime.datetime(date['year'], date['month'], date['day'])) # set sum tmp_account.set_sum(decimal.Decimal(account['sum'])) # set description tmp_account.set_description(account['description']) # add account ret_user.add_payment(tmp_account) ret_user.add_money(-tmp_account.get_sum()) return ret_user
def parse_xml(tree): """ try to parse XML from tree :param tree: XML :return: user """ # get root root = tree.getroot() # creates new user ret_user = User() # set his money ret_user.set_money(decimal.Decimal(root.attrib['money'])) for account in root[0]: # create new account new_account = Accounting() # set its description new_account.set_description(account.attrib['description']) # set new sum new_account.set_sum(decimal.Decimal(account.attrib['price'])) # get datetime dtime = account[0] # set datetime new_account.set_datetime(datetime.datetime(int(dtime.attrib['year']), int(dtime.attrib['month']), int(dtime.attrib['day']))) # set this payment to user ret_user.add_payment(new_account) # add money ret_user.add_money(-new_account.get_sum()) return ret_user
def test_clear_payments(self): """ tests clear_payments method :return: nothing """ user = User(3.00) payment = Accounting() user.add_payment(payment) user.clear_payments() self.assertEqual(len(user.get_payment_list()), 0)
def create_user(self): """ :return: User object """ acc = Accounting() acc.set_datetime(datetime.datetime(2016, 3, 27, 0, 0)) acc.set_description('desc') acc.set_sum(17.00) usr = User() usr.add_payment(acc) return usr
def create_user(self): """ creates instance of User class with two payments :return: user """ user = User() user.set_money(3.00) payment = Accounting() payment.set_sum(2.00) another_payment = payment another_payment.set_description('another') user.add_payment(payment) user.add_payment(another_payment) return user
def main(): """ allows to append User's payments and clear them :return: nothing """ read = cfgparse()[0] write = cfgparse()[1] main_user = read() if main_user is None: main_user = User(0.00) while True: key = get_key() if key == '1': account = View.input_accounting() main_user.add_payment(account) elif key == '2': main_user.clear_payments() main_user.set_money(0.00) elif key == '3': write(main_user) return None else: print("You've entered incorrect value")