Subversion Repositories SmartDukaan

Rev

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

Rev 2091 Rev 2432
Line 37... Line 37...
37
    17: "COMPLETED",
37
    17: "COMPLETED",
38
    18: "CANCELED",
38
    18: "CANCELED",
39
    19: "FAILED",
39
    19: "FAILED",
40
  }
40
  }
41
 
41
 
42
def mark_order_as_picked_up(order_id):
42
def mark_order_as_picked_up(order):
43
    '''
43
    '''
44
    Mark order as picked up
44
    Mark order as picked up
45
    '''
45
    '''
46
    order = get_order(order_id)
-
 
47
    if order.status != OrderStatus.SHIPPED_FROM_WH:
46
    if order.status != OrderStatus.SHIPPED_FROM_WH:
48
        print "Has this order been picked up?"
47
        print "Has this order been picked up?"
49
        print
48
        print
50
        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."
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."
51
        return
50
        return
Line 61... Line 60...
61
    order.status = OrderStatus.SHIPPED_TO_LOGST
60
    order.status = OrderStatus.SHIPPED_TO_LOGST
62
    order.statusDescription = "Order picked up by Courier Company"
61
    order.statusDescription = "Order picked up by Courier Company"
63
    order.pickup_timestamp = pickup_timestamp 
62
    order.pickup_timestamp = pickup_timestamp 
64
    session.commit()
63
    session.commit()
65
 
64
 
66
def mark_order_as_delivered(order_id):
65
def mark_order_as_delivered(order):
67
    '''
66
    '''
68
    Mark order as delivered
67
    Mark order as delivered
69
    '''
68
    '''
70
    order = get_order(order_id)
-
 
71
    if order.status != OrderStatus.SHIPPED_TO_LOGST:
69
    if order.status != OrderStatus.SHIPPED_TO_LOGST:
72
        print "Has this order been picked up?"
70
        print "Has this order been picked up?"
73
        print
71
        print
74
        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."
72
        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."
75
        return
73
        return
Line 91... Line 89...
91
    order.delivery_timestamp = delivery_timestamp
89
    order.delivery_timestamp = delivery_timestamp
92
    order.receiver = receiver
90
    order.receiver = receiver
93
    session.commit()
91
    session.commit()
94
 
92
 
95
 
93
 
96
def mark_order_as_failed(order_id):
94
def mark_order_as_failed(order):
97
    '''
95
    '''
98
    Mark order as failed
96
    Mark order as failed
99
    '''
97
    '''
100
    order = get_order(order_id)
-
 
101
    if order.status != OrderStatus.SHIPPED_TO_LOGST:
98
    if order.status != OrderStatus.SHIPPED_TO_LOGST:
102
        print "Has this order been picked up?"
99
        print "Has this order been picked up?"
103
        print
100
        print
104
        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."
101
        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."
105
        return
102
        return
Line 119... Line 116...
119
    order.status = OrderStatus.FAILED
116
    order.status = OrderStatus.FAILED
120
    order.delivery_timestamp = delivery_timestamp 
117
    order.delivery_timestamp = delivery_timestamp 
121
    order.statusDescription = "Order Returned to Origin:" + reason
118
    order.statusDescription = "Order Returned to Origin:" + reason
122
    session.commit()
119
    session.commit()
123
 
120
 
124
def change_product(order_id):
121
def change_product(order):
125
    '''
122
    '''
126
    Ship a product of a different color to the customer.
123
    Ship a product of a different color to the customer.
127
    '''
124
    '''
128
    order = get_order(order_id)
-
 
129
    if order.status != OrderStatus.SUBMITTED_FOR_PROCESSING:
125
    if order.status != OrderStatus.SUBMITTED_FOR_PROCESSING:
130
        print "This order has already been processed. Please seek help from engineering."
126
        print "This order has already been processed. Please seek help from engineering."
131
        return
127
        return
132
    
128
    
133
    raw_item_id = raw_input("Enter the ID of the item that you want to ship: ")
129
    raw_item_id = raw_input("Enter the ID of the item that you want to ship: ")
Line 140... Line 136...
140
    color = raw_input("Enter the color of the new item: ")
136
    color = raw_input("Enter the color of the new item: ")
141
    if color is None or color == "":
137
    if color is None or color == "":
142
        print("Color information is mandatory.")
138
        print("Color information is mandatory.")
143
        return
139
        return
144
    
140
    
145
    #warehouse_id = raw_input("Enter the warehouse id which will fulfill this order. Leave empty to keep it unchanged: ")
141
    #warehouse_id = raw_input("Enter the warehouse id which will fulfil this order. Leave empty to keep it unchanged: ")
146
    #if warehouse_id is None or warehouse_id == "":
142
    #if warehouse_id is None or warehouse_id == "":
147
    #    warehouse_id = order.warehouse_id
143
    #    warehouse_id = order.warehouse_id
148
    
144
    
149
    lineitem = order.lineitems[0]
145
    lineitem = order.lineitems[0]
150
    
146
    
151
    catalog_client = InventoryClient().get_client()
147
    catalog_client = InventoryClient().get_client()
152
    catalog_client.reserveItemInWarehouse(item_id, order.warehouse_id, lineitem.quantity)
148
    catalog_client.reserveItemInWarehouse(item_id, order.warehouse_id, lineitem.quantity)
153
    catalog_client.reduceReservationCount(lineitem.item_id, order.warehouse_id, lineitem.quantity)
149
    catalog_client.reduceReservationCount(lineitem.item_id, order.warehouse_id, lineitem.quantity)
154
    #TODO: Check that the item has the same price
150
    #TODO: Check that this new item has the same price
155
        
151
        
156
    lineitem.item_id = item_id
152
    lineitem.item_id = item_id
157
    lineitem.color = color
153
    lineitem.color = color
158
    
154
    
159
    session.commit()
155
    session.commit()
160
 
156
 
-
 
157
def change_warehouse(order):
-
 
158
    '''
-
 
159
    Update the warehouse which will be used to fulfil this order.
-
 
160
    '''
-
 
161
    if order.status != OrderStatus.SUBMITTED_FOR_PROCESSING and order.status != OrderStatus.INVENTORY_LOW:
-
 
162
        print "This order has already been processed. Please seek help from engineering."
-
 
163
        return
-
 
164
    
-
 
165
    print("Current Warehouse: " + str(order.warehouse_id))
-
 
166
    
-
 
167
    raw_warehouse_id = raw_input("Enter the ID of the warehouse from where you want to ship: ")
-
 
168
    try:
-
 
169
        warehouse_id = int(raw_warehouse_id)
-
 
170
    except ValueError:
-
 
171
        print("Invalid warehouse id")
-
 
172
        return
-
 
173
      
-
 
174
    if warehouse_id == order.warehouse_id:
-
 
175
        print("You have selected the current warehouse again. Nothing to do")
-
 
176
        return
-
 
177
 
-
 
178
    lineitem = order.lineitems[0]
-
 
179
    catalog_client = InventoryClient().get_client()
-
 
180
    catalog_client.reserveItemInWarehouse(lineitem.item_id, warehouse_id, lineitem.quantity)
-
 
181
    catalog_client.reduceReservationCount(lineitem.item_id, order.warehouse_id, lineitem.quantity)
-
 
182
    
-
 
183
    order.warehouse_id = warehouse_id
-
 
184
    session.commit()
-
 
185
 
-
 
186
def update_weight(order):
-
 
187
    '''
-
 
188
    Update the weight of order
-
 
189
    '''
-
 
190
    raw_weight = raw_input("Enter the final weight to be set: ")
-
 
191
    try:
-
 
192
        weight = float(raw_weight)
-
 
193
    except ValueError:
-
 
194
        print("Invalid weight")
-
 
195
        return
-
 
196
    
-
 
197
    order.total_weight = weight
-
 
198
    lineitem = order.lineitems[0]
-
 
199
    lineitem.total_weight = weight
-
 
200
    lineitem.unit_weight = weight
-
 
201
    #TODO: Update the weight of item. Problem is that even then, this update will only go to Production and not to Staging. Next content update will wipe out this data.
-
 
202
    session.commit()
-
 
203
 
161
def cancel(order_id):
204
def cancel(order_id):
162
    '''
205
    '''
163
    Cancel
206
    Cancel
164
    '''
207
    '''
165
    print("Your session has been closed")
208
    print("Your session has been closed")
166
    pass
209
    pass
167
 
210
 
-
 
211
ACTIONS = {0: cancel,
168
ACTIONS = {0: order_outofstock,
212
           1: order_outofstock,
169
           1: mark_order_as_picked_up,
213
           2: mark_order_as_picked_up,
170
           2: mark_order_as_delivered,
214
           3: mark_order_as_delivered,
171
           3: mark_order_as_failed,
215
           4: mark_order_as_failed,
172
           4: change_product,
216
           5: change_product,
-
 
217
           6: change_warehouse,
173
           5: cancel
218
           7: update_weight
174
           }
219
           }
175
 
220
 
176
def get_py_datetime(time_string):
221
def get_py_datetime(time_string):
177
    time_format = "%Y-%m-%d %H%M"
222
    time_format = "%Y-%m-%d %H%M"
178
    mytime = time.strptime(time_string, time_format)
223
    mytime = time.strptime(time_string, time_format)
Line 223... Line 268...
223
            print("Invalid input.")
268
            print("Invalid input.")
224
            return
269
            return
225
        if action > 4:
270
        if action > 4:
226
            print("Invalid input.")
271
            print("Invalid input.")
227
            return
272
            return
228
        ACTIONS[action](order_id)
273
        ACTIONS[action](order)
229
    except TransactionServiceException as tsex:
274
    except TransactionServiceException as tsex:
230
        print tsex.message
275
        print tsex.message
231
    finally:
276
    finally:
232
        close_session()
277
        close_session()
233
    
278