-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathInventory.py
More file actions
66 lines (55 loc) · 2.58 KB
/
Inventory.py
File metadata and controls
66 lines (55 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# manages printing to file, getting from file, etc.
import numpy as np
import pandas as pd
class Inventory:
def __init__(self):
self.filename1 = 'inventory.csv'
self.filename2 = 'book.csv'
# read file
self.inventoryList = pd.read_csv(self.filename1)
self.bookList = pd.read_csv(self.filename2)
# default adds 1, checks to see if input is int, if not returns error message
def getQuantity(self, quantity):
num = self.bookList.loc[self.bookList.Quantity == quantity, "Quantity"]
return num
def removeInventory(self, isbn, quantity):
num = int(self.inventoryList.loc[self.inventoryList.ISBN == isbn, "Quantity"])
num = num - quantity
self.inventoryList.loc[self.inventoryList.ISBN == isbn, "Quantity"] = num
def addback(self, isbn, quantity):
num = int(self.inventoryList.loc[self.inventoryList.ISBN == isbn, "Quantity"])
num = num + quantity
self.inventoryList.loc[self.inventoryList.ISBN == isbn, "Quantity"] = num
def addQuantity(self, isbn, num=1):
self.inventoryList.loc[self.inventoryList.ISBN==isbn, 'Quantity']+=num
self.save2file()
# num defaults 1, checks to see if input is int, if not returns error message
def removeQuantity(self, isbn, num=1):
self.inventoryList.loc[self.inventoryList.ISBN == isbn, 'Quantity'] -= num
self.save2file()
# check the Quantity of isbn
# input:ISBN, number
# output: 1: success
# 0: Quantity is not enough
# -1: there are no ISBN number in Inventory
def checkQuantity(self, isbn, num):
if len(self.inventoryList.loc[self.inventoryList.ISBN == isbn, 'Quantity'])==0:
return -1
elif np.array(self.inventoryList.loc[self.inventoryList.ISBN == isbn, 'Quantity'])[0] >= int(num):
return 1
else:
return 0
def getPrice(self, isbn):
# self.bookList.loc[self.bookList.ISBN == isbn]
if len(self.bookList.loc[self.bookList.ISBN == isbn, 'Price']) == 0:
return -1 ##better failsafe??
else:
return np.array(self.bookList.loc[self.bookList.ISBN == isbn, 'Price'])[0]
# print detail
def print(self):
inventory_Book_List = self.bookList.merge(self.inventoryList, on='ISBN')
print("########### Welcome to Inventory List###################")
print(inventory_Book_List)
print("########################################################")
def save2file(self):
self.inventoryList.to_csv(self.filename1, encoding='utf-8', index=False)