浏览代码

Quantity to type for each product in the new order

Jovian (Netbook) 5 年之前
父节点
当前提交
e3bd76ea25
共有 2 个文件被更改,包括 25 次插入1 次删除
  1. 3 1
      app_customer.py
  2. 22 0
      cli/quantity_asker.py

+ 3 - 1
app_customer.py

@@ -8,6 +8,7 @@ from cli.book_asker import BookAsker
 from cli.product_select import ProductSelecter
 from cli.house_asker import HouseAsker
 from cli.confirm import Confirmer
+from cli.quantity_asker import QuantityAsker
 from datetime import date, timedelta
 
 display = BasicDisplay()
@@ -23,6 +24,7 @@ bookAsker = BookAsker()
 productAsker = ProductSelecter()
 houseAsker = HouseAsker()
 confirmAsker = Confirmer()
+quantityAsker = QuantityAsker()
 
 # Login phase
 compList = consumer.getCompanyNames()
@@ -69,7 +71,7 @@ while running:
         targetHouseId = houseAsker.select(houseList)
         proList = consumer.getProductSet()
         proSelectNameList = productAsker.selectInto(proList)
-        productQuantityList = [100] * len(proSelectNameList)
+        productQuantityList = quantityAsker.askForEachOf(proSelectNameList)
         dueDate = date.today() + timedelta(15)
         if (confirmAsker.confirm()):
             consumer.addOrder(login, targetHouseId, proSelectNameList, productQuantityList, dueDate)

+ 22 - 0
cli/quantity_asker.py

@@ -0,0 +1,22 @@
+from PyInquirer import prompt 
+
+# Ask for a quantity
+
+class QuantityAsker:
+    def __init__(self):
+        self.widget = [
+            {
+                'type':'input',
+                'name':'number',
+                'message':'Enter a quantity'
+            }
+        ]
+
+    def askForOne(self, name):
+        return int(prompt(self.widget)['number'])
+
+    def askForEachOf(self, nameList):
+        ans = []
+        for name in nameList:
+            ans.append(self.askForOne(name))
+        return ans