Subversion Repositories SmartDukaan

Rev

Rev 1911 | Rev 2091 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1911 Rev 1939
Line 40... Line 40...
40
 
40
 
41
def mark_order_as_picked_up(order_id):
41
def mark_order_as_picked_up(order_id):
42
    '''
42
    '''
43
    Mark order as picked up
43
    Mark order as picked up
44
    '''
44
    '''
-
 
45
    order = get_order(order_id)
-
 
46
    if order.status != OrderStatus.SHIPPED_FROM_WH:
-
 
47
        print "Has this order been picked up?"
-
 
48
        print
-
 
49
        print "In case it has been and the same was not updated in the database, please first mark this order as picked up and then try again."
-
 
50
        return
-
 
51
 
45
    raw_pickup_timestamp = raw_input("Enter pickup time in YYYY-MM-DD hhmm format: ")
52
    raw_pickup_timestamp = raw_input("Enter pickup time in YYYY-MM-DD hhmm format: ")
46
    try:
53
    try:
47
        pickup_timestamp = get_py_datetime(raw_pickup_timestamp)
54
        pickup_timestamp = get_py_datetime(raw_pickup_timestamp)
48
        print("Pick up timestamp: " + str(pickup_timestamp))
55
        print("Pick up timestamp: " + str(pickup_timestamp))
49
    except ValueError:
56
    except ValueError:
50
        print("Invalid pickup time")
57
        print("Invalid pickup time")
51
        return
58
        return
52
 
-
 
53
    order = get_order(order_id)
-
 
54
    if order.status != OrderStatus.SHIPPED_FROM_WH:
-
 
55
        print "Has this order been picked up?"
-
 
56
        print
-
 
57
        print "In case it has been and the same was not updated in the database, please first mark this order as picked up and then try again."
-
 
58
        return
-
 
59
    
59
   
60
    order.status = OrderStatus.SHIPPED_TO_LOGST
60
    order.status = OrderStatus.SHIPPED_TO_LOGST
61
    order.statusDescription = "Order picked up by Courier Company"
61
    order.statusDescription = "Order picked up by Courier Company"
62
    order.pickup_timestamp = pickup_timestamp 
62
    order.pickup_timestamp = pickup_timestamp 
63
    session.commit()
63
    session.commit()
64
 
64
 
65
def mark_order_as_delivered(order_id):
65
def mark_order_as_delivered(order_id):
66
    '''
66
    '''
67
    Mark order as delivered
67
    Mark order as delivered
68
    '''
68
    '''
-
 
69
    order = get_order(order_id)
-
 
70
    if order.status != OrderStatus.SHIPPED_TO_LOGST:
-
 
71
        print "Has this order been picked up?"
-
 
72
        print
-
 
73
        print "In case it has been and the same was not updated in the database, please first mark this order as picked up and then try again."
-
 
74
        return
-
 
75
 
69
    raw_delivery_timestamp = raw_input("Enter delivery time in YYYY-MM-DD hhmm format: ")
76
    raw_delivery_timestamp = raw_input("Enter delivery time in YYYY-MM-DD hhmm format: ")
70
    try:
77
    try:
71
        delivery_timestamp = get_py_datetime(raw_delivery_timestamp)
78
        delivery_timestamp = get_py_datetime(raw_delivery_timestamp)
72
    except ValueError:
79
    except ValueError:
73
        print("Invalid delivery time stamp")
80
        print("Invalid delivery time stamp")
Line 76... Line 83...
76
    receiver = raw_input("Enter the name of receiver: ")
83
    receiver = raw_input("Enter the name of receiver: ")
77
    if receiver is None or receiver == "":
84
    if receiver is None or receiver == "":
78
        print("Receiver info is mandatory.")
85
        print("Receiver info is mandatory.")
79
        return
86
        return
80
    
87
    
81
    order = get_order(order_id)
-
 
82
    if order.status != OrderStatus.SHIPPED_TO_LOGST:
-
 
83
        print "Has this order been picked up?"
-
 
84
        print
-
 
85
        print "In case it has been and the same was not updated in the database, please first mark this order as picked up and then try again."
-
 
86
        return
-
 
87
    
-
 
88
    order.status = OrderStatus.DELIVERY_SUCCESS
88
    order.status = OrderStatus.DELIVERY_SUCCESS
89
    order.statusDescription = "Order delivered"
89
    order.statusDescription = "Order delivered"
90
    order.delivery_timestamp = delivery_timestamp
90
    order.delivery_timestamp = delivery_timestamp
91
    order.receiver = receiver
91
    order.receiver = receiver
92
    session.commit()
92
    session.commit()
Line 94... Line 94...
94
 
94
 
95
def mark_order_as_failed(order_id):
95
def mark_order_as_failed(order_id):
96
    '''
96
    '''
97
    Mark order as failed
97
    Mark order as failed
98
    '''
98
    '''
-
 
99
    order = get_order(order_id)
-
 
100
    if order.status != OrderStatus.SHIPPED_TO_LOGST:
-
 
101
        print "Has this order been picked up?"
-
 
102
        print
-
 
103
        print "In case it has been and the same was not updated in the database, please first mark this order as picked up and then try again."
-
 
104
        return
-
 
105
 
99
    raw_delivery_timestamp = raw_input("Enter delivery time in YYYY-MM-DD hhmm format: ")
106
    raw_delivery_timestamp = raw_input("Enter delivery time in YYYY-MM-DD hhmm format: ")
100
    try:
107
    try:
101
        delivery_timestamp = get_py_datetime(raw_delivery_timestamp)
108
        delivery_timestamp = get_py_datetime(raw_delivery_timestamp)
102
    except ValueError:
109
    except ValueError:
103
        print("Invalid delivery timestamp")
110
        print("Invalid delivery timestamp")
Line 106... Line 113...
106
    reason = raw_input("Enter the reason for failure: ")
113
    reason = raw_input("Enter the reason for failure: ")
107
    if reason is None or reason == "":
114
    if reason is None or reason == "":
108
        print("Reason for failure is mandatory.")
115
        print("Reason for failure is mandatory.")
109
        return
116
        return
110
    
117
    
111
    order = get_order(order_id)
-
 
112
    if order.status != OrderStatus.SHIPPED_TO_LOGST:
-
 
113
        print "Has this order been picked up?"
-
 
114
        print
-
 
115
        print "In case it has been and the same was not updated in the database, please first mark this order as picked up and then try again."
-
 
116
        return
-
 
117
    
-
 
118
    order.status = OrderStatus.FAILED
118
    order.status = OrderStatus.FAILED
119
    order.delivery_timestamp = delivery_timestamp 
119
    order.delivery_timestamp = delivery_timestamp 
120
    order.statusDescription = "Order Returned to Origin:" + reason
120
    order.statusDescription = "Order Returned to Origin:" + reason
121
    session.commit()
121
    session.commit()
122
 
122
 
-
 
123
def change_product(order_id):
-
 
124
    '''
-
 
125
    Ship a product of a different color to the customer.
-
 
126
    '''
-
 
127
    order = get_order(order_id)
-
 
128
    if order.status != OrderStatus.SUBMITTED_FOR_PROCESSING:
-
 
129
        print "This order has already been processed. Please seek help from engineering."
-
 
130
        return
-
 
131
    
-
 
132
    raw_item_id = raw_input("Enter the ID of the item that you want to ship: ")
-
 
133
    try:
-
 
134
        item_id = int(raw_item_id)
-
 
135
    except ValueError:
-
 
136
        print("Invalid product Id")
-
 
137
        return
-
 
138
    
-
 
139
    color = raw_input("Enter the color of the new item: ")
-
 
140
    if color is None or color == "":
-
 
141
        print("Color information is mandatory.")
-
 
142
        return
-
 
143
 
-
 
144
    #TODO: Check that the item has the same price
-
 
145
    lineitem = order.lineitems[0]
-
 
146
    lineitem.item_id = item_id
-
 
147
    lineitem.color = color
-
 
148
    
-
 
149
    session.commit()
-
 
150
 
123
def cancel(order_id):
151
def cancel(order_id):
124
    '''
152
    '''
125
    Cancel
153
    Cancel
126
    '''
154
    '''
-
 
155
    print("Your session has been closed")
127
    pass
156
    pass
128
 
157
 
129
ACTIONS = {0: order_outofstock,
158
ACTIONS = {0: order_outofstock,
130
           1: mark_order_as_picked_up,
159
           1: mark_order_as_picked_up,
131
           2: mark_order_as_delivered,
160
           2: mark_order_as_delivered,
132
           3: mark_order_as_failed,
161
           3: mark_order_as_failed,
-
 
162
           4: change_product,
133
           4: cancel
163
           5: cancel
134
           }
164
           }
135
 
165
 
136
def get_py_datetime(time_string):
166
def get_py_datetime(time_string):
137
    time_format = "%Y-%m-%d %H%M"
167
    time_format = "%Y-%m-%d %H%M"
138
    mytime = time.strptime(time_string, time_format)
168
    mytime = time.strptime(time_string, time_format)
Line 162... Line 192...
162
        print("Created On:\t\t" + str(order.created_timestamp))
192
        print("Created On:\t\t" + str(order.created_timestamp))
163
        #print("Billed On:\t" + str(order.billing_timestamp))
193
        #print("Billed On:\t" + str(order.billing_timestamp))
164
        #print("Shipped On:\t" + str(order.shipping_timestamp))
194
        #print("Shipped On:\t" + str(order.shipping_timestamp))
165
        print("Current Status:\t\t" + VALUES_TO_NAMES[order.status])
195
        print("Current Status:\t\t" + VALUES_TO_NAMES[order.status])
166
        print("Status Description:\t" + order.statusDescription)
196
        print("Status Description:\t" + order.statusDescription)
-
 
197
        print("Ordered Items description:")
-
 
198
        for lineitem in order.lineitems:
-
 
199
            print("Item Id:" + str(lineitem.item_id) + "\tBrand: " + str(lineitem.brand) + "\tModel: " + str(lineitem.model_number) + "\tColor: " + str(lineitem.color))
167
        print
200
        print
168
        print
201
        print
169
        print("You can perform following operations:")
202
        print("You can perform following operations:")
170
        for (key, val) in ACTIONS.iteritems():
203
        for (key, val) in ACTIONS.iteritems():
171
            print("[" + str(key) + "]" + val.__doc__ )
204
            print("[" + str(key) + "]" + val.__doc__ )
172
 
205
 
173
        raw_action = raw_input("What do you want to do? ")
206
        raw_action = raw_input("What do you want to do? ")
174
        if raw_action is None or raw_action == "" or raw_action == "4":
207
        if raw_action is None or raw_action == "":
175
            print("Your session has been closed.")
208
            print("Your session has been closed.")
176
            return
209
            return
177
        try:
210
        try:
178
            action = int(raw_action)
211
            action = int(raw_action)
179
        except ValueError:
212
        except ValueError: