| Line 188... |
Line 188... |
| 188 |
catalog_client = InventoryClient().get_client()
|
188 |
catalog_client = InventoryClient().get_client()
|
| 189 |
catalog_client.reserveItemInWarehouse(item_id, logistics_info.warehouseId, order.lineitems[0].quantity)
|
189 |
catalog_client.reserveItemInWarehouse(item_id, logistics_info.warehouseId, order.lineitems[0].quantity)
|
| 190 |
|
190 |
|
| 191 |
item_pricing = catalog_client.getItemPricing(item_id, order.warehouse_id)
|
191 |
item_pricing = catalog_client.getItemPricing(item_id, order.warehouse_id)
|
| 192 |
order.lineitems[0].transfer_price = item_pricing.transferPrice
|
192 |
order.lineitems[0].transfer_price = item_pricing.transferPrice
|
| - |
|
193 |
elif new_status == TransactionStatus.COD_IN_PROCESS:
|
| - |
|
194 |
for order in transaction.orders:
|
| - |
|
195 |
order.status = OrderStatus.INIT
|
| - |
|
196 |
order.statusDescription = "Verification Pending"
|
| - |
|
197 |
order.cod = True
|
| - |
|
198 |
#After we got payment success, we will set logistics info also
|
| - |
|
199 |
logistics_client = LogisticsClient().get_client()
|
| - |
|
200 |
#FIXME line item is only one now. If multiple will come, need to fix.
|
| - |
|
201 |
item_id = order.lineitems[0].item_id
|
| - |
|
202 |
logistics_info = logistics_client.getLogisticsInfo(order.customer_pincode, item_id, DeliveryType.COD)
|
| - |
|
203 |
|
| - |
|
204 |
current_time = datetime.datetime.now()
|
| - |
|
205 |
logistics_info.deliveryTime = adjust_delivery_time(current_time, logistics_info.deliveryTime)
|
| - |
|
206 |
|
| - |
|
207 |
order.warehouse_id = logistics_info.warehouseId
|
| - |
|
208 |
order.logistics_provider_id = logistics_info.providerId
|
| - |
|
209 |
order.airwaybill_no = logistics_info.airway_billno
|
| - |
|
210 |
order.tracking_id = order.airwaybill_no
|
| - |
|
211 |
order.expected_delivery_time = current_time + datetime.timedelta(days=logistics_info.deliveryTime)
|
| - |
|
212 |
|
| - |
|
213 |
catalog_client = InventoryClient().get_client()
|
| - |
|
214 |
catalog_client.reserveItemInWarehouse(item_id, logistics_info.warehouseId, order.lineitems[0].quantity)
|
| - |
|
215 |
|
| - |
|
216 |
item_pricing = catalog_client.getItemPricing(item_id, order.warehouse_id)
|
| - |
|
217 |
order.lineitems[0].transfer_price = item_pricing.transferPrice
|
| 193 |
|
218 |
|
| 194 |
session.commit()
|
219 |
session.commit()
|
| 195 |
return True
|
220 |
return True
|
| 196 |
|
221 |
|
| 197 |
def adjust_delivery_time(order_time, delivery_days):
|
222 |
def adjust_delivery_time(order_time, delivery_days):
|
| Line 418... |
Line 443... |
| 418 |
order = get_order(orderId)
|
443 |
order = get_order(orderId)
|
| 419 |
order.status = status
|
444 |
order.status = status
|
| 420 |
order.statusDescription = description
|
445 |
order.statusDescription = description
|
| 421 |
session.commit()
|
446 |
session.commit()
|
| 422 |
return True
|
447 |
return True
|
| - |
|
448 |
|
| - |
|
449 |
def verify_order(self, orderId):
|
| - |
|
450 |
logging.info("Verifying order no: " + str(orderId))
|
| - |
|
451 |
order = get_order(orderId)
|
| - |
|
452 |
if order.status == OrderStatus.INIT:
|
| - |
|
453 |
order.status = OrderStatus.SUBMITTED_FOR_PROCESSING
|
| - |
|
454 |
order.statusDescription = "Submitted for processing"
|
| - |
|
455 |
order.verification_timestamp = datetime.datetime.now()
|
| - |
|
456 |
session.commit()
|
| - |
|
457 |
logging.info("Successfully verified order no: " + str(orderId))
|
| - |
|
458 |
return True
|
| - |
|
459 |
else:
|
| - |
|
460 |
logging.warning("Verify called for order no." + str(orderId) +" which is not in verification pending state");
|
| - |
|
461 |
return False
|
| 423 |
|
462 |
|
| 424 |
def accept_order(self, orderId):
|
463 |
def accept_order(self, orderId):
|
| - |
|
464 |
logging.info("Accepting order no: " + str(orderId))
|
| 425 |
order = get_order(orderId)
|
465 |
order = get_order(orderId)
|
| 426 |
if order.status in [OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW]:
|
466 |
if order.status in [OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW]:
|
| 427 |
logging.info("Accepting order with id " + str(orderId))
|
467 |
if not order.cod:
|
| 428 |
if order.transaction.status == TransactionStatus.AUTHORIZED:
|
468 |
if order.transaction.status == TransactionStatus.AUTHORIZED:
|
| 429 |
__capture_txn(order.transaction.id)
|
469 |
__capture_txn(order.transaction.id)
|
| 430 |
order.status = OrderStatus.ACCEPTED
|
470 |
order.status = OrderStatus.ACCEPTED
|
| 431 |
order.statusDescription = "Order Accepted"
|
471 |
order.statusDescription = "Order Accepted"
|
| 432 |
order.accepted_timestamp = datetime.datetime.now()
|
472 |
order.accepted_timestamp = datetime.datetime.now()
|
| 433 |
session.commit()
|
473 |
session.commit()
|
| - |
|
474 |
logging.info("Successfully accepted the order no.:" + str(orderId))
|
| 434 |
return True
|
475 |
return True
|
| 435 |
else:
|
476 |
else:
|
| 436 |
logging.warning("Accept called for an unacceptable order")
|
477 |
logging.warning("Accept called for the unacceptable order: " + str(orderId))
|
| 437 |
return False
|
478 |
return False
|
| 438 |
|
479 |
|
| 439 |
def __capture_txn(txnId):
|
480 |
def __capture_txn(txnId):
|
| 440 |
logging.info("Capturing payment for merchant txn:" + str(txnId))
|
481 |
logging.info("Capturing payment for merchant txn:" + str(txnId))
|
| 441 |
payment_client = PaymentClient().get_client()
|
482 |
payment_client = PaymentClient().get_client()
|
| 442 |
capture_result = payment_client.capturePayment(txnId)
|
483 |
capture_result = payment_client.capturePayment(txnId)
|
| 443 |
if capture_result:
|
484 |
if capture_result:
|
| - |
|
485 |
logging.info("Successfully captured payment for merchant txn:" + str(txnId))
|
| 444 |
change_transaction_status(txnId, TransactionStatus.IN_PROCESS, "Payment received");
|
486 |
change_transaction_status(txnId, TransactionStatus.IN_PROCESS, "Payment received")
|
| 445 |
else:
|
487 |
else:
|
| 446 |
raise TransactionServiceException(115, "Payment capture failed.")
|
488 |
raise TransactionServiceException(115, "Payment capture failed.")
|
| 447 |
|
489 |
|
| 448 |
def bill_order(self, orderId):
|
490 |
def bill_order(self, orderId):
|
| 449 |
order = get_order(orderId)
|
491 |
order = get_order(orderId)
|
| Line 523... |
Line 565... |
| 523 |
order.statusDescription = "Low Inventory"
|
565 |
order.statusDescription = "Low Inventory"
|
| 524 |
order.outofstock_timestamp = datetime.datetime.now()
|
566 |
order.outofstock_timestamp = datetime.datetime.now()
|
| 525 |
session.commit()
|
567 |
session.commit()
|
| 526 |
return True
|
568 |
return True
|
| 527 |
|
569 |
|
| 528 |
def mark_orders_as_manifested(warehouse_id, provider_id):
|
570 |
def mark_orders_as_manifested(warehouse_id, provider_id, cod):
|
| 529 |
try:
|
571 |
try:
|
| 530 |
current_timestamp = datetime.datetime.now()
|
572 |
current_timestamp = datetime.datetime.now()
|
| 531 |
orders = Order.query.filter_by(warehouse_id = warehouse_id, logistics_provider_id = provider_id, status = OrderStatus.BILLED).all()
|
573 |
orders = Order.query.filter_by(warehouse_id = warehouse_id, logistics_provider_id = provider_id, status = OrderStatus.BILLED, cod = cod).all()
|
| 532 |
for order in orders:
|
574 |
for order in orders:
|
| 533 |
order.status = OrderStatus.SHIPPED_FROM_WH
|
575 |
order.status = OrderStatus.SHIPPED_FROM_WH
|
| 534 |
order.statusDescription = "Order shipped from warehouse"
|
576 |
order.statusDescription = "Order shipped from warehouse"
|
| 535 |
order.shipping_timestamp = current_timestamp
|
577 |
order.shipping_timestamp = current_timestamp
|
| 536 |
session.commit()
|
578 |
session.commit()
|