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):
|
def _execute(self):
|
||||||
while 1:
|
name = self.input_str('Product name> ')
|
||||||
print "Main Menu: \nWhat do you want to do? \n"
|
bar_code = self.input_int('Bar code> ')
|
||||||
for i in range(len(self.menu_list)):
|
price = self.input_int('Price> ')
|
||||||
print i+1," ) ",self.menu_list[i].name
|
product = Product(bar_code,name,price)
|
||||||
result = raw_input('\nEnter a number corresponding to your action, or "exit" to exit \n')
|
session = Session()
|
||||||
if result in ["1","2","3","4"]:
|
session.add(product)
|
||||||
self.menu_list[int(result)-1].execute()
|
session.commit()
|
||||||
elif result in ["quit", "exit", "abort"]:
|
session.close()
|
||||||
print "OK, quitting"
|
print 'Added product %s, price %d, bar code %d' (name,price,bar_code)
|
||||||
break
|
self.pause()
|
||||||
else:
|
|
||||||
print "This does not make sense"
|
|
||||||
|
#class MainMenu():
|
||||||
|
# def __init__(self):
|
||||||
|
# self.menu_list = [Menu("Buy"),ChargeMenu(), Menu("Add User"), Menu("Add Product")]
|
||||||
|
|
||||||
|
# def execute(self):
|
||||||
|
# while 1:
|
||||||
|
# print "Main Menu: \nWhat do you want to do? \n"
|
||||||
|
# for i in range(len(self.menu_list)):
|
||||||
|
# print i+1," ) ",self.menu_list[i].name
|
||||||
|
# result = raw_input('\nEnter a number corresponding to your action, or "exit" to exit \n')
|
||||||
|
# if result in ["1","2","3","4"]:
|
||||||
|
# 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