本文整理汇总了Python中model.user.User.add_payment方法的典型用法代码示例。如果您正苦于以下问题:Python User.add_payment方法的具体用法?Python User.add_payment怎么用?Python User.add_payment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.user.User
的用法示例。
在下文中一共展示了User.add_payment方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: encode_dict
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import add_payment [as 别名]
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
示例2: main
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import add_payment [as 别名]
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")
示例3: parse_xml
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import add_payment [as 别名]
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
示例4: test_clear_payments
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import add_payment [as 别名]
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)
示例5: create_user
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import add_payment [as 别名]
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
示例6: create_user
# 需要导入模块: from model.user import User [as 别名]
# 或者: from model.user.User import add_payment [as 别名]
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