From 0237f58f592e8f5eaf2238daf4fbc9706a24d949 Mon Sep 17 00:00:00 2001 From: inebeate Date: Sun, 6 Mar 2011 11:24:58 +0000 Subject: [PATCH] Varebeholdning!!!!! --- data | Bin 9216 -> 9216 bytes db.py | 10 ++++++---- text_based.py | 43 ++++++++++++++++++++++++++++++++++--------- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/data b/data index b142322ada62ca1e1fa7679852147e5caddb4acc..1f40586bde7139d23923db879c2def7ee29e5779 100644 GIT binary patch delta 452 zcmZ{gze@sf7{=f4J>N^|#3RcJ40MS|Q0}L9-4NL1lKl;mH>6iWt%5o zqE10LI5@TiZ7#J2(H~HD5vb7%@9=>S&-?J!bM@R+jIDGxULoO`1PllRy!DrO4|~z` z_hDY7ZN~Opuk4k-D7tc(h*l>%J?lhL`||d>Qxhr5*ukk=SrmK0Pq4>ci1QFf zl`x)!w^8jjJRHV3r!3PHRZS^+O35Tt)zNfE+esU`Whfarjv2vBXquyHj&7$d#WEFJ zjtg^wYB`$W7;0KKZ9`Y&=6HECEFwY}qJn3)Tr=wg3PC delta 137 zcmV;40CxX?NPtL?8vzWl9OVNG000021K0oq=mXfZ5e&=&C<&d7rIeq41OOEQPjY2% z3KNC#!cGJLDFIDoY-?q6YHw?AY++<&53&gV0|EQ83" % (self.name, self.bar_code, self.price) + return "" % (self.name, self.bar_code, self.price, self.stock) def __str__(self): return self.name @@ -60,13 +62,13 @@ class PurchaseEntry(Base): amount = Column(Integer) product = relationship(Product,backref="purchases") - + def __init__(self, purchase, product, amount): self.product = product self.product_bar_code = product.bar_code self.purchase = purchase self.amount = amount - + self.product.stock -= 1 def __repr__(self): return "" % (self.product.name, self.amount ) diff --git a/text_based.py b/text_based.py index eed4576..a984c1b 100755 --- a/text_based.py +++ b/text_based.py @@ -165,12 +165,11 @@ class Menu(): result = self.input_str(prompt) try: choice = int(result) - if (choice <= 0 or choice > number_of_choices): - print 'Not a legal choice' - else: + if (choice > 0 and choice <= number_of_choices): return choice except ValueError: - self.thing_in_menu_choice(result) + pass + self.thing_in_menu_choice(result) def input_int(self, prompt=None, allowed_range=(None,None)): @@ -878,6 +877,31 @@ When finished, write an empty line to confirm the purchase. if info != None: self.set_context(info) +class AdjustStockMenu(Menu): + def __init__(self): + Menu.__init__(self,'Adjust stock', uses_db=True) + + def _execute(self): + self.print_header() + product = self.input_product('Product> ') + + print 'The stock of this product is: %d ' % (product.stock) + #print 'Write the number of products you have added to the stock' + + add_stock = self.input_int('Added stock> ', (-1000, 1000)) + print 'You added %d to the stock of %s' % (add_stock,product) + + product.stock += add_stock + print 'The stock is now %d' % (product.stock) + + try: + self.session.commit() + print 'Stock is now stored' + except sqlalchemy.exc.SQLAlchemyError, e: + print 'Could not store stock: %s' % (e) + self.pause() + return + class AdjustCreditMenu(Menu): # reimplements ChargeMenu; these should be combined to one def __init__(self): @@ -917,11 +941,11 @@ class ProductListMenu(Menu): self.print_header() text = '' product_list = self.session.query(Product).all() - line_format = '%-15s | %5s | %-'+str(Product.name_length)+'s\n' - text += line_format % ('bar code', 'price', 'name') + line_format = '%-15s | %5s | %-'+str(Product.name_length)+'s | %5s \n' + text += line_format % ('bar code', 'price', 'name', 'stock') text += '-----------------------------------------------------------------------\n' for p in product_list: - text += line_format % (p.bar_code, p.price, p.name) + text += line_format % (p.bar_code, p.price, p.name, p.stock) less(text) @@ -933,7 +957,7 @@ class ProductSearchMenu(Menu): self.print_header() self.set_context('Enter (part of) product name or bar code') product = self.input_product() - print 'Result: %s, price: %d kr, bar code: %s' % (product.name, product.price, product.bar_code) + print 'Result: %s, price: %d kr, bar code: %s, stock: %d' % (product.name, product.price, product.bar_code, product.stock) self.pause() @@ -1007,7 +1031,8 @@ main = Menu('Dibbler main menu', items=[AddUserMenu(), EditUserMenu(), AddProductMenu(), - EditProductMenu()]), + EditProductMenu(), + AdjustStockMenu(),]), ProductSearchMenu(), Menu('Statistics', items=[ProductPopularityMenu(),