From a0ec131c49a77e4e0378bb339caf0349eaf5e945 Mon Sep 17 00:00:00 2001 From: Christoffer Viken Date: Sun, 26 Feb 2017 11:26:41 +0000 Subject: [PATCH] Join the last 2 entries in a purchase if they are the same thing. --- text_interface/buymenu.py | 16 +++++++++------- text_interface/helpermenus.py | 6 ++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/text_interface/buymenu.py b/text_interface/buymenu.py index 3c857b8..49585fc 100644 --- a/text_interface/buymenu.py +++ b/text_interface/buymenu.py @@ -64,10 +64,10 @@ When finished, write an empty line to confirm the purchase.\n''' def add_thing_to_purchase(self, thing, amount=1): if isinstance(thing, User): if thing.is_anonymous(): - print '--------------------------------------------' - print'You are now purchasing as the user anonym.' - print'You have to put money in the anonym-jar.' - print '--------------------------------------------' + print '---------------------------------------------' + print '| You are now purchasing as the user anonym.|' + print '| You have to put money in the anonym-jar. |' + print '---------------------------------------------' if not self.credit_check(thing): if self.low_credit_warning(user=thing, timeout=self.superfast_mode): @@ -77,7 +77,10 @@ When finished, write an empty line to confirm the purchase.\n''' else: Transaction(thing, purchase=self.purchase) elif isinstance(thing, Product): - PurchaseEntry(self.purchase, thing, amount) + if len(self.purchase.entries) and self.purchase.entries[-1].product == thing: + self.purchase.entries[-1].amount += amount + else: + PurchaseEntry(self.purchase, thing, amount) return True def _execute(self, initial_contents=None): @@ -123,8 +126,7 @@ When finished, write an empty line to confirm the purchase.\n''' # Possibly exit from the menu: if thing is None: if not self.complete_input(): - if self.confirm('Not enough information entered. Abort purchase?', - default=True): + if self.confirm('Not enough information entered. Abort purchase?', default=True): return False continue break diff --git a/text_interface/helpermenus.py b/text_interface/helpermenus.py index 432334c..850144d 100644 --- a/text_interface/helpermenus.py +++ b/text_interface/helpermenus.py @@ -378,7 +378,8 @@ class Menu(object): return_index=False) 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() def print_header(self): @@ -388,7 +389,8 @@ class Menu(object): def pause(self): self.input_str('.') - def general_help(self): + @staticmethod + def general_help(): print ''' DIBBLER HELP