Browse Source

First time book order selection works

Jovian (Netbook) 6 years ago
parent
commit
77afa7dc38
6 changed files with 55 additions and 0 deletions
  1. 7 0
      app_customer.py
  2. 8 0
      basic_display.py
  3. 21 0
      cli/book_asker.py
  4. 11 0
      consumer/connect.py
  5. 4 0
      model/ord.py
  6. 4 0
      model/ori.py

+ 7 - 0
app_customer.py

@@ -4,6 +4,7 @@ from basic_display import BasicDisplay
 from cli.name_asker import NameAsker
 from cli.pass_asker import PassAsker
 from cli.customer_action_asker import CustomerActionAsker
+from cli.book_asker import BookAsker
 
 print('|Customer application|')
 
@@ -13,6 +14,7 @@ consumer = DataConsumer(credentials)
 nameAsker = NameAsker()
 passAsker = PassAsker()
 actionAsker = CustomerActionAsker()
+bookAsker = BookAsker()
 
 display = BasicDisplay()
 
@@ -37,6 +39,11 @@ while running:
     
     if action == 'quit':
         running = False
+    elif action == 'list orders':
+        bookList = consumer.getOrdersOfCompany(login)
+        print('book list :', bookList)
+        bookId = bookAsker.select(bookList)
+        print('book selected :', bookId)
     else:
         print('Action', action, 'not implemented yet.')
 

+ 8 - 0
basic_display.py

@@ -1,4 +1,5 @@
 from model.product import Product
+from model.ord import Ord
 
 class BasicDisplay():
     def product(self, p):
@@ -9,3 +10,10 @@ class BasicDisplay():
             p = Product(pRaw)
             self.product(p)
 
+    def bookOrder(self, b):
+        print(b.id, ':', b.date)
+
+    def bookOrderList(self, bList):
+        for bRaw in bList:
+            b = Ord(bRaw)
+            self.bookOrder(b)

+ 21 - 0
cli/book_asker.py

@@ -0,0 +1,21 @@
+from PyInquirer import prompt 
+
+# Select a bookorder
+
+class BookAsker:
+    def __init__(self):
+        self.widget = [
+            {
+                'type':'list',
+                'name':'id',
+                'message':'Which book order do you want to examine ?',
+                'choices':[]
+            }
+        ]
+
+    def select(self, bookList):
+        for rb in bookList:
+            dic = {'key': rb[0], 'value': rb[0], 'name': rb[1].isoformat()}
+            self.widget[0]['choices'].append(dic)
+        return prompt(self.widget)['id']
+

+ 11 - 0
consumer/connect.py

@@ -39,6 +39,17 @@ class DataConsumer():
 
         return ans
 
+    def getOrdersOfCompany(self, company):
+        cursor = self.conn.cursor()
+
+        cursor.execute("SELECT ord_id, ord_date FROM bookorder NATURAL JOIN company WHERE com_name = %s", (company,))
+
+        rows = cursor.fetchall()
+
+        cursor.close()
+
+        return rows
+
     def commit(self):
         """Make the changes to the database persistent"""
         self.conn.commit()

+ 4 - 0
model/ord.py

@@ -0,0 +1,4 @@
+class Ord():
+    """Bean for a book order"""
+    def __init__(self, raw):
+        (self.id, self.date, self.com_id) = raw

+ 4 - 0
model/ori.py

@@ -0,0 +1,4 @@
+class Ori():
+    """Bean for an ordered item"""
+    def __init__(self, raw):
+        (self.id, self.quantity, self.deliveryDueDate, self.pro_id, self.ord_id, self.war_id) = raw