Superhurtigkjøp (fikser #8).

This commit is contained in:
Øystein Ingmar Skartsæterhagen 2011-03-10 15:03:19 +00:00
parent 6493173339
commit f1ef355fd6
1 changed files with 15 additions and 0 deletions

View File

@ -801,6 +801,7 @@ class BuyMenu(Menu):
Menu.__init__(self, 'Buy', uses_db=True) Menu.__init__(self, 'Buy', uses_db=True)
if session: if session:
self.session = session self.session = session
self.superfast_mode = False
self.help_text = ''' self.help_text = '''
Each purchase may contain one or more products and one or more buyers. Each purchase may contain one or more products and one or more buyers.
@ -827,10 +828,20 @@ When finished, write an empty line to confirm the purchase.
self.print_header() self.print_header()
self.purchase = Purchase() self.purchase = Purchase()
self.exit_confirm_msg=None self.exit_confirm_msg=None
self.superfast_mode = False
for thing in initialContents: for thing in initialContents:
self.add_thing_to_purchase(thing) self.add_thing_to_purchase(thing)
isproduct = lambda t: isinstance(t, Product)
if len(initialContents) > 0 and all(map(isproduct, initialContents)):
self.superfast_mode = True
print '***********************************************'
print '****** Buy menu is in SUPERFASTmode[tm]! ******'
print '*** The purchase will be stored immediately ***'
print '*** when you enter a user. ***'
print '***********************************************'
while True: while True:
self.print_purchase() self.print_purchase()
self.printc({(False,False): 'Enter user or product identification', self.printc({(False,False): 'Enter user or product identification',
@ -861,6 +872,10 @@ When finished, write an empty line to confirm the purchase.
# Add the thing to our purchase object: # Add the thing to our purchase object:
self.add_thing_to_purchase(thing) self.add_thing_to_purchase(thing)
# In superfast mode, we complete the purchase once we get a user:
if self.superfast_mode and isinstance(thing, User):
break
self.purchase.perform_purchase() self.purchase.perform_purchase()
self.session.add(self.purchase) self.session.add(self.purchase)
try: try: