Ikke så mye nytt, kosmetiske endringer gjort på Charge.
This commit is contained in:
parent
b648c27473
commit
09bf703a35
|
@ -145,43 +145,20 @@ class Selector(Menu):
|
||||||
|
|
||||||
class ChargeMenu(Menu):
|
class ChargeMenu(Menu):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.name = "Add Credits to a User Account"
|
self.name = "Add credits to a user account"
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
self.session = Session()
|
self.session = Session()
|
||||||
while 1:
|
amount = self.input_int('Amount to be added> ')
|
||||||
abort = False
|
user = self.input_user('To user>')
|
||||||
while 1:
|
t = Transaction(user, -amount, 'Add '+str(amount)+' to user '+user.name)
|
||||||
user_string = raw_input('\nEnter the user name or card number of the account you wish to add credits to, or type "exit" to exit:\n')
|
t.perform_transaction()
|
||||||
if user_string in ['exit', 'abort', 'quit']:
|
self.session.add(t)
|
||||||
abort = True
|
self.session.commit()
|
||||||
break
|
print 'Added %d kr to user %s\'s account' % (amount, user.name)
|
||||||
else:
|
print 'User %s\'s credit is now %d kr' % (user,user.credit)
|
||||||
user = retrieve_user(user_string,self.session)
|
self.session.close()
|
||||||
if user:
|
self.pause()
|
||||||
break
|
|
||||||
if abort:
|
|
||||||
break
|
|
||||||
while 1:
|
|
||||||
print '\nHow much do you wish to charge?\n'
|
|
||||||
amount_string = raw_input('Enter an amount, or type "exit" to exit:\n')
|
|
||||||
|
|
||||||
if amount_string in ['exit', 'abort', 'quit']:
|
|
||||||
abort = True
|
|
||||||
break
|
|
||||||
try:
|
|
||||||
amount = int(amount_string)
|
|
||||||
break
|
|
||||||
except:
|
|
||||||
print "Please enter an integer"
|
|
||||||
if abort:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
user.credit += amount
|
|
||||||
# self.session.add(user)
|
|
||||||
self.session.commit()
|
|
||||||
self.session.close()
|
|
||||||
break
|
|
||||||
|
|
||||||
class TransferMenu(Menu):
|
class TransferMenu(Menu):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -332,24 +309,40 @@ class ProductListMenu(Menu):
|
||||||
print line_format % (p.name, p.price, p.bar_code)
|
print line_format % (p.name, p.price, p.bar_code)
|
||||||
self.pause()
|
self.pause()
|
||||||
|
|
||||||
|
class AddProductMenu(Menu)
|
||||||
class MainMenu():
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.menu_list = [Menu("Buy"),ChargeMenu(), Menu("Add User"), Menu("Add Product")]
|
Menu.__init__(self, 'Add product')
|
||||||
|
|
||||||
|
def _execute(self):
|
||||||
|
name = self.input_str('Product name> ')
|
||||||
|
bar_code = self.input_int('Bar code> ')
|
||||||
|
price = self.input_int('Price> ')
|
||||||
|
product = Product(bar_code,name,price)
|
||||||
|
session = Session()
|
||||||
|
session.add(product)
|
||||||
|
session.commit()
|
||||||
|
session.close()
|
||||||
|
print 'Added product %s, price %d, bar code %d' (name,price,bar_code)
|
||||||
|
self.pause()
|
||||||
|
|
||||||
def execute(self):
|
|
||||||
while 1:
|
#class MainMenu():
|
||||||
print "Main Menu: \nWhat do you want to do? \n"
|
# def __init__(self):
|
||||||
for i in range(len(self.menu_list)):
|
# self.menu_list = [Menu("Buy"),ChargeMenu(), Menu("Add User"), Menu("Add Product")]
|
||||||
print i+1," ) ",self.menu_list[i].name
|
|
||||||
result = raw_input('\nEnter a number corresponding to your action, or "exit" to exit \n')
|
# def execute(self):
|
||||||
if result in ["1","2","3","4"]:
|
# while 1:
|
||||||
self.menu_list[int(result)-1].execute()
|
# print "Main Menu: \nWhat do you want to do? \n"
|
||||||
elif result in ["quit", "exit", "abort"]:
|
# for i in range(len(self.menu_list)):
|
||||||
print "OK, quitting"
|
# print i+1," ) ",self.menu_list[i].name
|
||||||
break
|
# result = raw_input('\nEnter a number corresponding to your action, or "exit" to exit \n')
|
||||||
else:
|
# if result in ["1","2","3","4"]:
|
||||||
print "This does not make sense"
|
# self.menu_list[int(result)-1].execute()
|
||||||
|
# elif result in ["quit", "exit", "abort"]:
|
||||||
|
# print "OK, quitting"
|
||||||
|
# break
|
||||||
|
# else:
|
||||||
|
# print "This does not make sense"
|
||||||
|
|
||||||
|
|
||||||
def dwim_search(string, session):
|
def dwim_search(string, session):
|
||||||
|
|
Loading…
Reference in New Issue