Join the last 2 entries in a purchase if they are the same thing.

This commit is contained in:
Christoffer Viken 2017-02-26 11:26:41 +00:00
parent a71274ed78
commit a0ec131c49
2 changed files with 13 additions and 9 deletions

View File

@ -64,10 +64,10 @@ When finished, write an empty line to confirm the purchase.\n'''
def add_thing_to_purchase(self, thing, amount=1): def add_thing_to_purchase(self, thing, amount=1):
if isinstance(thing, User): if isinstance(thing, User):
if thing.is_anonymous(): if thing.is_anonymous():
print '--------------------------------------------' print '---------------------------------------------'
print'You are now purchasing as the user anonym.' print '| You are now purchasing as the user anonym.|'
print'You have to put money in the anonym-jar.' print '| You have to put money in the anonym-jar. |'
print '--------------------------------------------' print '---------------------------------------------'
if not self.credit_check(thing): if not self.credit_check(thing):
if self.low_credit_warning(user=thing, timeout=self.superfast_mode): if self.low_credit_warning(user=thing, timeout=self.superfast_mode):
@ -77,6 +77,9 @@ When finished, write an empty line to confirm the purchase.\n'''
else: else:
Transaction(thing, purchase=self.purchase) Transaction(thing, purchase=self.purchase)
elif isinstance(thing, Product): elif isinstance(thing, Product):
if len(self.purchase.entries) and self.purchase.entries[-1].product == thing:
self.purchase.entries[-1].amount += amount
else:
PurchaseEntry(self.purchase, thing, amount) PurchaseEntry(self.purchase, thing, amount)
return True return True
@ -123,8 +126,7 @@ When finished, write an empty line to confirm the purchase.\n'''
# Possibly exit from the menu: # Possibly exit from the menu:
if thing is None: if thing is None:
if not self.complete_input(): if not self.complete_input():
if self.confirm('Not enough information entered. Abort purchase?', if self.confirm('Not enough information entered. Abort purchase?', default=True):
default=True):
return False return False
continue continue
break break

View File

@ -378,7 +378,8 @@ class Menu(object):
return_index=False) return_index=False)
return selector.execute() return selector.execute()
def confirm(self, prompt, default=None, timeout=None): @staticmethod
def confirm(prompt, default=None, timeout=None):
return ConfirmMenu(prompt, default, timeout).execute() return ConfirmMenu(prompt, default, timeout).execute()
def print_header(self): def print_header(self):
@ -388,7 +389,8 @@ class Menu(object):
def pause(self): def pause(self):
self.input_str('.') self.input_str('.')
def general_help(self): @staticmethod
def general_help():
print ''' print '''
DIBBLER HELP DIBBLER HELP