Varebeholdning!!!!!
This commit is contained in:
parent
057dad9ea7
commit
0237f58f59
8
db.py
8
db.py
|
@ -36,18 +36,20 @@ class Product(Base):
|
||||||
bar_code = Column(String(13), primary_key=True)
|
bar_code = Column(String(13), primary_key=True)
|
||||||
name = Column(String(45))
|
name = Column(String(45))
|
||||||
price = Column(Integer)
|
price = Column(Integer)
|
||||||
|
stock = Column(Integer)
|
||||||
|
|
||||||
bar_code_re = r"[0-9]+"
|
bar_code_re = r"[0-9]+"
|
||||||
name_re = r".+"
|
name_re = r".+"
|
||||||
name_length = 45
|
name_length = 45
|
||||||
|
|
||||||
def __init__(self, bar_code, name, price):
|
def __init__(self, bar_code, name, price, stock):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.bar_code = bar_code
|
self.bar_code = bar_code
|
||||||
self.price = price
|
self.price = price
|
||||||
|
self.stock = stock
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<Product('%s', '%s', '%s')>" % (self.name, self.bar_code, self.price)
|
return "<Product('%s', '%s', '%s', '%s')>" % (self.name, self.bar_code, self.price, self.stock)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
@ -66,7 +68,7 @@ class PurchaseEntry(Base):
|
||||||
self.product_bar_code = product.bar_code
|
self.product_bar_code = product.bar_code
|
||||||
self.purchase = purchase
|
self.purchase = purchase
|
||||||
self.amount = amount
|
self.amount = amount
|
||||||
|
self.product.stock -= 1
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<PurchaseEntry('%s', '%s')>" % (self.product.name, self.amount )
|
return "<PurchaseEntry('%s', '%s')>" % (self.product.name, self.amount )
|
||||||
|
|
||||||
|
|
|
@ -165,11 +165,10 @@ class Menu():
|
||||||
result = self.input_str(prompt)
|
result = self.input_str(prompt)
|
||||||
try:
|
try:
|
||||||
choice = int(result)
|
choice = int(result)
|
||||||
if (choice <= 0 or choice > number_of_choices):
|
if (choice > 0 and choice <= number_of_choices):
|
||||||
print 'Not a legal choice'
|
|
||||||
else:
|
|
||||||
return choice
|
return choice
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
pass
|
||||||
self.thing_in_menu_choice(result)
|
self.thing_in_menu_choice(result)
|
||||||
|
|
||||||
|
|
||||||
|
@ -878,6 +877,31 @@ When finished, write an empty line to confirm the purchase.
|
||||||
if info != None:
|
if info != None:
|
||||||
self.set_context(info)
|
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
|
class AdjustCreditMenu(Menu): # reimplements ChargeMenu; these should be combined to one
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -917,11 +941,11 @@ class ProductListMenu(Menu):
|
||||||
self.print_header()
|
self.print_header()
|
||||||
text = ''
|
text = ''
|
||||||
product_list = self.session.query(Product).all()
|
product_list = self.session.query(Product).all()
|
||||||
line_format = '%-15s | %5s | %-'+str(Product.name_length)+'s\n'
|
line_format = '%-15s | %5s | %-'+str(Product.name_length)+'s | %5s \n'
|
||||||
text += line_format % ('bar code', 'price', 'name')
|
text += line_format % ('bar code', 'price', 'name', 'stock')
|
||||||
text += '-----------------------------------------------------------------------\n'
|
text += '-----------------------------------------------------------------------\n'
|
||||||
for p in product_list:
|
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)
|
less(text)
|
||||||
|
|
||||||
|
|
||||||
|
@ -933,7 +957,7 @@ class ProductSearchMenu(Menu):
|
||||||
self.print_header()
|
self.print_header()
|
||||||
self.set_context('Enter (part of) product name or bar code')
|
self.set_context('Enter (part of) product name or bar code')
|
||||||
product = self.input_product()
|
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()
|
self.pause()
|
||||||
|
|
||||||
|
|
||||||
|
@ -1007,7 +1031,8 @@ main = Menu('Dibbler main menu',
|
||||||
items=[AddUserMenu(),
|
items=[AddUserMenu(),
|
||||||
EditUserMenu(),
|
EditUserMenu(),
|
||||||
AddProductMenu(),
|
AddProductMenu(),
|
||||||
EditProductMenu()]),
|
EditProductMenu(),
|
||||||
|
AdjustStockMenu(),]),
|
||||||
ProductSearchMenu(),
|
ProductSearchMenu(),
|
||||||
Menu('Statistics',
|
Menu('Statistics',
|
||||||
items=[ProductPopularityMenu(),
|
items=[ProductPopularityMenu(),
|
||||||
|
|
Loading…
Reference in New Issue