| Line 11... |
Line 11... |
| 11 |
from reportlab.rl_config import defaultPageSize
|
11 |
from reportlab.rl_config import defaultPageSize
|
| 12 |
from shop2020.clients.CatalogClient import CatalogClient
|
12 |
from shop2020.clients.CatalogClient import CatalogClient
|
| 13 |
from shop2020.clients.HelperClient import HelperClient
|
13 |
from shop2020.clients.HelperClient import HelperClient
|
| 14 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
14 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
| 15 |
from shop2020.clients.PaymentClient import PaymentClient
|
15 |
from shop2020.clients.PaymentClient import PaymentClient
|
| 16 |
from shop2020.clients.PurchaseClient import PurchaseClient
|
- |
|
| 17 |
from shop2020.clients.UserClient import UserClient
|
16 |
from shop2020.clients.UserClient import UserClient
|
| 18 |
from shop2020.clients.WarehouseClient import WarehouseClient
|
17 |
from shop2020.clients.WarehouseClient import WarehouseClient
|
| 19 |
from shop2020.config.client.ConfigClient import ConfigClient
|
- |
|
| 20 |
from shop2020.model.v1 import order
|
18 |
from shop2020.model.v1 import order
|
| 21 |
from shop2020.model.v1.order.impl.DataService import Transaction, LineItem, \
|
19 |
from shop2020.model.v1.order.impl.DataService import Transaction, LineItem, \
|
| 22 |
Order, BatchNoGenerator, InvoiceIDGenerator, TransactionRequiringExtraProcessing, \
|
20 |
Order, BatchNoGenerator, InvoiceIDGenerator, TransactionRequiringExtraProcessing, \
|
| 23 |
OrderInventory, Alert, PaymentSettlement, EBSSettlementSummary
|
21 |
OrderInventory, Alert, PaymentSettlement, EBSSettlementSummary
|
| 24 |
from shop2020.model.v1.order.impl.model.ReturnOrder import ReturnOrder
|
22 |
from shop2020.model.v1.order.impl.model.ReturnOrder import ReturnOrder
|
| 25 |
from shop2020.thriftpy.generic.ttypes import ExceptionType
|
23 |
from shop2020.thriftpy.generic.ttypes import ExceptionType
|
| 26 |
from shop2020.thriftpy.logistics.ttypes import DeliveryType
|
24 |
from shop2020.thriftpy.logistics.ttypes import DeliveryType
|
| 27 |
from shop2020.thriftpy.model.v1.catalog.ttypes import BillingType, \
|
25 |
from shop2020.thriftpy.model.v1.catalog.ttypes import BillingType, \
|
| 28 |
InventoryServiceException
|
26 |
InventoryServiceException, WarehouseType, ItemType, InventoryType
|
| 29 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
27 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
| 30 |
TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
|
28 |
TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
|
| 31 |
HotspotAction, TimeoutSummary, OrderStatusGroups
|
29 |
HotspotAction, TimeoutSummary, OrderStatusGroups
|
| 32 |
from shop2020.thriftpy.payments.ttypes import PaymentException
|
30 |
from shop2020.thriftpy.payments.ttypes import PaymentException
|
| 33 |
from shop2020.thriftpy.purchase.ttypes import PurchaseOrder, LineItem as POLineItem
|
31 |
from shop2020.thriftpy.warehouse.ttypes import ScanType, \
|
| 34 |
from shop2020.thriftpy.warehouse.ttypes import ScanType, WarehouseServiceException
|
32 |
WarehouseServiceException
|
| 35 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
|
33 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
|
| 36 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
34 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
| 37 |
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
|
35 |
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
|
| 38 |
from sqlalchemy.sql import func
|
36 |
from sqlalchemy.sql import func
|
| 39 |
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct
|
37 |
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct
|
| Line 208... |
Line 206... |
| 208 |
logistics_info = logistics_client.getLogisticsInfo(order.customer_pincode, item_id, DeliveryType.PREPAID)
|
206 |
logistics_info = logistics_client.getLogisticsInfo(order.customer_pincode, item_id, DeliveryType.PREPAID)
|
| 209 |
|
207 |
|
| 210 |
current_time = datetime.datetime.now()
|
208 |
current_time = datetime.datetime.now()
|
| 211 |
logistics_info.deliveryTime = adjust_delivery_time(current_time, logistics_info.deliveryTime)
|
209 |
logistics_info.deliveryTime = adjust_delivery_time(current_time, logistics_info.deliveryTime)
|
| 212 |
logistics_info.shippingTime = adjust_delivery_time(current_time, logistics_info.shippingTime)
|
210 |
logistics_info.shippingTime = adjust_delivery_time(current_time, logistics_info.shippingTime)
|
| 213 |
|
211 |
|
| 214 |
order.warehouse_id = logistics_info.warehouseId
|
212 |
order.warehouse_id = logistics_info.warehouseId
|
| - |
|
213 |
order.fulfilmentWarehouseId = logistics_info.fulfilmentWarehouseId
|
| 215 |
order.logistics_provider_id = logistics_info.providerId
|
214 |
order.logistics_provider_id = logistics_info.providerId
|
| 216 |
order.airwaybill_no = logistics_info.airway_billno
|
215 |
order.airwaybill_no = logistics_info.airway_billno
|
| 217 |
order.tracking_id = order.airwaybill_no
|
216 |
order.tracking_id = order.airwaybill_no
|
| 218 |
order.expected_shipping_time = (current_time + datetime.timedelta(days=logistics_info.shippingTime)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
|
217 |
order.expected_shipping_time = (current_time + datetime.timedelta(days=logistics_info.shippingTime)).replace(hour=PREPAID_SHIPPING_CUTOFF_TIME, minute=0, second=0)
|
| 219 |
order.promised_shipping_time = order.expected_shipping_time
|
218 |
order.promised_shipping_time = order.expected_shipping_time
|
| 220 |
order.expected_delivery_time = current_time + datetime.timedelta(days=logistics_info.deliveryTime)
|
219 |
order.expected_delivery_time = current_time + datetime.timedelta(days=logistics_info.deliveryTime)
|
| 221 |
order.promised_delivery_time = order.expected_delivery_time
|
220 |
order.promised_delivery_time = order.expected_delivery_time
|
| 222 |
|
221 |
|
| 223 |
catalog_client = CatalogClient().get_client()
|
222 |
catalog_client = CatalogClient().get_client()
|
| 224 |
catalog_client.reserveItemInWarehouse(item_id, logistics_info.warehouseId, order.lineitems[0].quantity)
|
223 |
catalog_client.reserveItemInWarehouse(item_id, logistics_info.fulfilmentWarehouseId, order.lineitems[0].quantity)
|
| 225 |
|
224 |
|
| 226 |
try:
|
225 |
try:
|
| 227 |
item_pricing = catalog_client.getItemPricing(item_id, -1)
|
226 |
item_pricing = catalog_client.getItemPricing(item_id, -1)
|
| 228 |
order.lineitems[0].transfer_price = item_pricing.transferPrice
|
227 |
order.lineitems[0].transfer_price = item_pricing.transferPrice
|
| 229 |
except:
|
228 |
except:
|
| Line 242... |
Line 241... |
| 242 |
current_time = datetime.datetime.now()
|
241 |
current_time = datetime.datetime.now()
|
| 243 |
logistics_info.deliveryTime = adjust_delivery_time(current_time, logistics_info.deliveryTime)
|
242 |
logistics_info.deliveryTime = adjust_delivery_time(current_time, logistics_info.deliveryTime)
|
| 244 |
logistics_info.shippingTime = adjust_delivery_time(current_time, logistics_info.shippingTime)
|
243 |
logistics_info.shippingTime = adjust_delivery_time(current_time, logistics_info.shippingTime)
|
| 245 |
|
244 |
|
| 246 |
order.warehouse_id = logistics_info.warehouseId
|
245 |
order.warehouse_id = logistics_info.warehouseId
|
| - |
|
246 |
order.fulfilmentWarehouseId = logistics_info.fulfilmentWarehouseId
|
| 247 |
order.logistics_provider_id = logistics_info.providerId
|
247 |
order.logistics_provider_id = logistics_info.providerId
|
| 248 |
order.airwaybill_no = logistics_info.airway_billno
|
248 |
order.airwaybill_no = logistics_info.airway_billno
|
| 249 |
order.tracking_id = order.airwaybill_no
|
249 |
order.tracking_id = order.airwaybill_no
|
| 250 |
order.expected_shipping_time = (current_time + datetime.timedelta(days=logistics_info.shippingTime)).replace(hour=COD_SHIPPING_CUTOFF_TIME, minute=0, second=0)
|
250 |
order.expected_shipping_time = (current_time + datetime.timedelta(days=logistics_info.shippingTime)).replace(hour=COD_SHIPPING_CUTOFF_TIME, minute=0, second=0)
|
| 251 |
order.promised_shipping_time = order.expected_shipping_time
|
251 |
order.promised_shipping_time = order.expected_shipping_time
|
| 252 |
order.expected_delivery_time = current_time + datetime.timedelta(days=logistics_info.deliveryTime)
|
252 |
order.expected_delivery_time = current_time + datetime.timedelta(days=logistics_info.deliveryTime)
|
| 253 |
order.promised_delivery_time = order.expected_delivery_time
|
253 |
order.promised_delivery_time = order.expected_delivery_time
|
| 254 |
|
254 |
|
| 255 |
catalog_client = CatalogClient().get_client()
|
255 |
catalog_client = CatalogClient().get_client()
|
| 256 |
catalog_client.reserveItemInWarehouse(item_id, logistics_info.warehouseId, order.lineitems[0].quantity)
|
256 |
catalog_client.reserveItemInWarehouse(item_id, logistics_info.fulfilmentWarehouseId, order.lineitems[0].quantity)
|
| 257 |
|
257 |
|
| 258 |
try:
|
258 |
try:
|
| 259 |
item_pricing = catalog_client.getItemPricing(item_id, -1)
|
259 |
item_pricing = catalog_client.getItemPricing(item_id, -1)
|
| 260 |
order.lineitems[0].transfer_price = item_pricing.transferPrice
|
260 |
order.lineitems[0].transfer_price = item_pricing.transferPrice
|
| 261 |
except:
|
261 |
except:
|
| Line 574... |
Line 574... |
| 574 |
return False
|
574 |
return False
|
| 575 |
|
575 |
|
| 576 |
def accept_order(orderId):
|
576 |
def accept_order(orderId):
|
| 577 |
logging.info("Accepting order no: " + str(orderId))
|
577 |
logging.info("Accepting order no: " + str(orderId))
|
| 578 |
order = get_order(orderId)
|
578 |
order = get_order(orderId)
|
| 579 |
if order.status in [OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW, OrderStatus.LOW_INV_PO_RAISED, OrderStatus.LOW_INV_REVERSAL_IN_PROCESS, OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT]:
|
579 |
if order.status in [OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW, OrderStatus.LOW_INV_PO_RAISED, OrderStatus.LOW_INV_REVERSAL_IN_PROCESS, OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT, OrderStatus.CAPTURE_IN_PROCESS]:
|
| 580 |
if not order.cod:
|
580 |
if not order.cod:
|
| 581 |
if order.transaction.status == TransactionStatus.AUTHORIZED:
|
581 |
if order.transaction.status == TransactionStatus.AUTHORIZED:
|
| 582 |
__capture_txn(order)
|
582 |
__capture_txn(order)
|
| 583 |
order.status = OrderStatus.ACCEPTED
|
583 |
order.status = OrderStatus.ACCEPTED
|
| 584 |
order.statusDescription = "Order Accepted"
|
584 |
order.statusDescription = "Order Accepted"
|
| Line 607... |
Line 607... |
| 607 |
session.commit()
|
607 |
session.commit()
|
| 608 |
raise TransactionServiceException(122, "Unable to capture payment due to connection issue.")
|
608 |
raise TransactionServiceException(122, "Unable to capture payment due to connection issue.")
|
| 609 |
else:
|
609 |
else:
|
| 610 |
raise TransactionServiceException(115, "Payment capture failed.")
|
610 |
raise TransactionServiceException(115, "Payment capture failed.")
|
| 611 |
|
611 |
|
| 612 |
def add_billing_details(orderId, invoice_number, serialNumber, itemNumber, billedBy, jacketNumber, billingType, vendorId, authorize):
|
612 |
def add_billing_details(orderId, invoice_number, serialNumber, itemNumber, billedBy, jacketNumber, billingType, fulfilmentWarehouseId, authorize):
|
| 613 |
if jacketNumber is None or jacketNumber <= 0:
|
613 |
if jacketNumber is None or jacketNumber <= 0:
|
| 614 |
raise TransactionServiceException(110, "Invalid jacket number")
|
614 |
raise TransactionServiceException(110, "Invalid jacket number")
|
| 615 |
|
615 |
|
| 616 |
if billedBy is None or billedBy.strip() == "":
|
616 |
if billedBy is None or billedBy.strip() == "":
|
| 617 |
raise TransactionServiceException(110, "Invalid Biller")
|
617 |
raise TransactionServiceException(110, "Invalid Biller")
|
| 618 |
|
618 |
|
| 619 |
order = Order.get_by(id=orderId)
|
619 |
order = Order.get_by(id=orderId)
|
| 620 |
if not order:
|
620 |
if not order:
|
| 621 |
raise TransactionServiceException(101, "No order found for the given order id" + str(orderId))
|
621 |
raise TransactionServiceException(101, "No order found for the given order id" + str(orderId))
|
| 622 |
|
622 |
|
| - |
|
623 |
lineitem = order.lineitems[0]
|
| - |
|
624 |
item_id = lineitem.item_id
|
| - |
|
625 |
catalog_client = CatalogClient().get_client()
|
| - |
|
626 |
item = catalog_client.getItem(item_id)
|
| 623 |
if order.status == OrderStatus.ACCEPTED:
|
627 |
if order.status == OrderStatus.ACCEPTED:
|
| 624 |
order.jacket_number = jacketNumber
|
628 |
order.jacket_number = jacketNumber
|
| 625 |
if billingType == BillingType.OURS:
|
629 |
if billingType == BillingType.OURS:
|
| 626 |
if itemNumber is None or itemNumber.strip() == "":
|
630 |
if itemNumber is None or itemNumber.strip() == "":
|
| 627 |
raise TransactionServiceException(110, "Invalid item number")
|
631 |
raise TransactionServiceException(110, "Invalid item number")
|
| 628 |
|
632 |
|
| 629 |
order.invoice_number = get_next_invoice_number()
|
633 |
order.invoice_number = get_next_invoice_number()
|
| 630 |
lineitem = order.lineitems[0]
|
- |
|
| 631 |
if lineitem.productGroup == "Handsets" and not serialNumber:
|
634 |
if ItemType.SERIALIZED == item.type and not serialNumber:
|
| 632 |
raise TransactionServiceException(110, "No Serial Number supplied for a handset.")
|
635 |
raise TransactionServiceException(110, "No Serial Number supplied")
|
| 633 |
lineitem.item_number = itemNumber
|
636 |
lineitem.item_number = itemNumber
|
| 634 |
if serialNumber:
|
637 |
if serialNumber:
|
| 635 |
lineitem.serial_number = serialNumber
|
638 |
lineitem.serial_number = serialNumber
|
| 636 |
else:
|
639 |
else:
|
| 637 |
order.invoice_number = invoice_number
|
640 |
order.invoice_number = invoice_number
|
| Line 646... |
Line 649... |
| 646 |
|
649 |
|
| 647 |
order.status = OrderStatus.BILLED
|
650 |
order.status = OrderStatus.BILLED
|
| 648 |
order.statusDescription = "Order Billed"
|
651 |
order.statusDescription = "Order Billed"
|
| 649 |
order.billing_timestamp = datetime.datetime.now()
|
652 |
order.billing_timestamp = datetime.datetime.now()
|
| 650 |
order.billed_by = billedBy
|
653 |
order.billed_by = billedBy
|
| 651 |
lineitem = order.lineitems[0]
|
- |
|
| 652 |
item_id = lineitem.item_id
|
- |
|
| 653 |
|
654 |
|
| 654 |
# Not letting the billing process fail in cases where we are unable to
|
655 |
# Not letting the billing process fail in cases where we are unable to
|
| 655 |
# fill in transfer price
|
656 |
# fill in transfer price
|
| 656 |
item_pricing = None
|
- |
|
| 657 |
try:
|
657 |
try:
|
| 658 |
catalog_client = CatalogClient().get_client()
|
658 |
catalog_client = CatalogClient().get_client()
|
| - |
|
659 |
warehouse = catalog_client.getWarehouse(fulfilmentWarehouseId)
|
| 659 |
item_pricing = catalog_client.getItemPricing(item_id, vendorId)
|
660 |
item_pricing = catalog_client.getItemPricing(item_id, warehouse.vendor.id)
|
| - |
|
661 |
lineitem.transfer_price = item_pricing.transferPrice
|
| - |
|
662 |
order.vendorId = warehouse.vendor.id
|
| 660 |
except InventoryServiceException as e:
|
663 |
except InventoryServiceException as e:
|
| 661 |
print sys.exc_info()[0]
|
664 |
print sys.exc_info()[0]
|
| 662 |
print e.message
|
665 |
print e.message
|
| - |
|
666 |
raise TransactionServiceException(110, 'Transfer price missing for itemId: ' + str(item_id) + ' and vendor: ' + str(warehouse.vendor.id))
|
| 663 |
|
667 |
|
| 664 |
order.vendorId = vendorId
|
- |
|
| 665 |
lineitems = order.lineitems
|
- |
|
| 666 |
|
- |
|
| 667 |
# Putting NULL as transfer price for cases where its missing
|
- |
|
| 668 |
if item_pricing is not None:
|
- |
|
| 669 |
order.lineitems[0].transfer_price = item_pricing.transferPrice
|
- |
|
| 670 |
|
- |
|
| 671 |
# For Mahipal warehouse, we need to scan out items for every billed order
|
668 |
# For OUR warehouse, we need to scan out items for every billed order
|
| 672 |
if order.warehouse_id == 7:
|
669 |
if billingType == BillingType.OURS:
|
| 673 |
if lineitem.productGroup == "Handsets":
|
670 |
if ItemType.SERIALIZED == item.type:
|
| 674 |
try:
|
671 |
try:
|
| 675 |
warehouse_client = WarehouseClient().get_client()
|
672 |
warehouse_client = WarehouseClient().get_client()
|
| 676 |
inventoryItem = warehouse_client.getInventoryItem(serialNumber)
|
673 |
inventoryItem = warehouse_client.getInventoryItem(serialNumber)
|
| 677 |
if (inventoryItem.itemId != item_id):
|
674 |
if (inventoryItem.itemId != item_id):
|
| - |
|
675 |
catalog_client = CatalogClient().get_client()
|
| 678 |
item = catalog_client.getItem(inventoryItem.itemId)
|
676 |
item = catalog_client.getItem(inventoryItem.itemId)
|
| 679 |
lineitem = order.lineitems[0]
|
- |
|
| 680 |
scanItemString = " ".join([str(item.brand), str(item.modelName), str(item.modelNumber), str(item.color)])
|
677 |
scanItemString = " ".join([str(item.brand), str(item.modelName), str(item.modelNumber), str(item.color)])
|
| 681 |
lineItemString = " ".join([str(lineitem.brand), str(lineitem.model_name), str(lineitem.model_number), str(lineitem.color)])
|
678 |
lineItemString = " ".join([str(lineitem.brand), str(lineitem.model_name), str(lineitem.model_number), str(lineitem.color)])
|
| 682 |
raise TransactionServiceException(110, 'Trying to scan ' + scanItemString + ' instead of ' + lineItemString)
|
679 |
raise TransactionServiceException(110, 'Trying to scan ' + scanItemString + ' instead of ' + lineItemString)
|
| - |
|
680 |
print order.fulfilmentWarehouseId, lineitem.quantity, order.warehouse_id
|
| 683 |
inventoryItem = warehouse_client.scanSerializedItemForOrder(serialNumber, ScanType.SALE, orderId, order.warehouse_id)
|
681 |
inventoryItem = warehouse_client.scanSerializedItemForOrder(serialNumber, ScanType.SALE, orderId, order.fulfilmentWarehouseId, lineitem.quantity, order.warehouse_id)
|
| 684 |
lineitem.transfer_price = inventoryItem.unitPrice
|
682 |
lineitem.transfer_price = inventoryItem.unitPrice
|
| 685 |
order.vendorId = inventoryItem.supplierId
|
683 |
order.vendorId = inventoryItem.supplierId
|
| 686 |
catalog_client = CatalogClient().get_client()
|
684 |
catalog_client = CatalogClient().get_client()
|
| - |
|
685 |
warehouse = catalog_client.getWarehouse(order.fulfilmentWarehouseId)
|
| - |
|
686 |
# Fetching GOOD w/h corresponding to the virtual one here
|
| 687 |
for lineitem in lineitems:
|
687 |
if warehouse.billingWarehouseId is None:
|
| 688 |
catalog_client.addInventory(item_id, order.warehouse_id, -1 * lineitem.quantity)
|
688 |
warehouse = catalog_client.getWarehouses(None, InventoryType.GOOD, warehouse.vendor.id, order.warehouse_id, 0)[0]
|
| - |
|
689 |
order.fulfilmentWarehouseId = warehouse.id
|
| 689 |
except WarehouseServiceException as e:
|
690 |
except WarehouseServiceException as e:
|
| 690 |
print sys.exc_info()[0]
|
691 |
print sys.exc_info()[0]
|
| 691 |
print 'Could not scan out orders due to: ' + e.message
|
692 |
print 'Could not scan out orders due to: ' + e.message
|
| 692 |
if e.exceptionType == ExceptionType.ILLEGAL_ARGUMENTS:
|
- |
|
| 693 |
raise TransactionServiceException(110, e.message)
|
693 |
raise TransactionServiceException(110, e.message)
|
| 694 |
|
- |
|
| 695 |
try:
|
- |
|
| 696 |
catalog_client = CatalogClient().get_client()
|
- |
|
| 697 |
for lineitem in lineitems:
|
- |
|
| 698 |
catalog_client.reduceReservationCount(item_id, order.warehouse_id, lineitem.quantity)
|
- |
|
| 699 |
except Exception as e:
|
- |
|
| 700 |
print sys.exc_info()[0]
|
- |
|
| 701 |
print e.message
|
- |
|
| 702 |
raise TransactionServiceException(110, 'Please contact with Engg. team, inventory could not be updated because of: ' + e.message)
|
- |
|
| 703 |
|
694 |
|
| - |
|
695 |
__update_inventory_reservation(order)
|
| 704 |
session.commit()
|
696 |
session.commit()
|
| 705 |
return True
|
697 |
return True
|
| 706 |
else:
|
698 |
else:
|
| 707 |
return False
|
699 |
return False
|
| 708 |
|
700 |
|
| Line 1213... |
Line 1205... |
| 1213 |
return orders_not_picked_up
|
1205 |
return orders_not_picked_up
|
| 1214 |
|
1206 |
|
| 1215 |
def receive_return(order_id, receiveCondition):
|
1207 |
def receive_return(order_id, receiveCondition):
|
| 1216 |
order = get_order(order_id)
|
1208 |
order = get_order(order_id)
|
| 1217 |
|
1209 |
|
| 1218 |
# FIXME: For Mahipal warehouse, we need to scan in items for every sales return
|
- |
|
| 1219 |
if order.warehouse_id == 7:
|
- |
|
| 1220 |
try:
|
- |
|
| 1221 |
warehouse_client = WarehouseClient().get_client()
|
- |
|
| 1222 |
lineitem = order.lineitems[0]
|
- |
|
| 1223 |
|
- |
|
| 1224 |
# Inventory should not be updated for DOA returns
|
- |
|
| 1225 |
if order.status == OrderStatus.RTO_IN_TRANSIT:
|
- |
|
| 1226 |
warehouse_client.scanSerializedItemForOrder(lineitem.serial_number, ScanType.SALE_RET, order.id, order.warehouse_id)
|
- |
|
| 1227 |
# In case of RTOs increasing availibility only if we receive item in prestine state
|
- |
|
| 1228 |
if not receiveCondition:
|
- |
|
| 1229 |
catalog_client = CatalogClient().get_client()
|
- |
|
| 1230 |
catalog_client.addInventory(lineitem.item_id, order.warehouse_id, lineitem.quantity)
|
- |
|
| 1231 |
elif order.status in [OrderStatus.DOA_PICKUP_CONFIRMED, OrderStatus.DOA_RETURN_IN_TRANSIT]:
|
- |
|
| 1232 |
warehouse_client.scanSerializedItemForOrder(lineitem.serial_number, ScanType.DOA_IN, order.id, order.warehouse_id)
|
- |
|
| 1233 |
except:
|
- |
|
| 1234 |
print sys.exc_info()[0]
|
- |
|
| 1235 |
print 'Could not scan in sales return orders'
|
- |
|
| 1236 |
|
- |
|
| 1237 |
if order.status in [OrderStatus.DOA_PICKUP_CONFIRMED, OrderStatus.DOA_RETURN_IN_TRANSIT]:
|
1210 |
if order.status in [OrderStatus.DOA_PICKUP_CONFIRMED, OrderStatus.DOA_RETURN_IN_TRANSIT]:
|
| 1238 |
if receiveCondition == 0:
|
1211 |
if receiveCondition == 0:
|
| 1239 |
order.status = OrderStatus.DOA_RECEIVED_PRESTINE
|
1212 |
order.status = OrderStatus.DOA_RECEIVED_PRESTINE
|
| 1240 |
order.statusDescription = "DOA package received"
|
1213 |
order.statusDescription = "DOA package received"
|
| 1241 |
elif receiveCondition == 1:
|
1214 |
elif receiveCondition == 1:
|
| Line 1270... |
Line 1243... |
| 1270 |
order.statusDescription = "RTO lost in transit"
|
1243 |
order.statusDescription = "RTO lost in transit"
|
| 1271 |
order.received_return_timestamp = datetime.datetime.now()
|
1244 |
order.received_return_timestamp = datetime.datetime.now()
|
| 1272 |
session.commit()
|
1245 |
session.commit()
|
| 1273 |
else:
|
1246 |
else:
|
| 1274 |
return False
|
1247 |
return False
|
| - |
|
1248 |
|
| - |
|
1249 |
# For OUR warehouses, we need to scan in items for every return
|
| - |
|
1250 |
catalogClient = CatalogClient().get_client()
|
| - |
|
1251 |
warehouse = catalogClient.getWarehouse(order.warehouse_id)
|
| - |
|
1252 |
if warehouse.billingType == BillingType.OURS:
|
| - |
|
1253 |
try:
|
| - |
|
1254 |
scanMap = {
|
| - |
|
1255 |
OrderStatus.RTO_RECEIVED_PRESTINE : ScanType.SALE_RET,
|
| - |
|
1256 |
OrderStatus.RTO_RECEIVED_DAMAGED : ScanType.SALE_RET_UNUSABLE,
|
| - |
|
1257 |
OrderStatus.RTO_LOST_IN_TRANSIT : ScanType.LOST_IN_TRANSIT,
|
| - |
|
1258 |
OrderStatus.DOA_RECEIVED_PRESTINE : ScanType.DOA_IN,
|
| - |
|
1259 |
OrderStatus.DOA_RECEIVED_DAMAGED : ScanType.DOA_IN,
|
| - |
|
1260 |
OrderStatus.DOA_LOST_IN_TRANSIT : ScanType.LOST_IN_TRANSIT
|
| - |
|
1261 |
}
|
| - |
|
1262 |
|
| - |
|
1263 |
scanType = scanMap[order.status]
|
| - |
|
1264 |
if scanType:
|
| - |
|
1265 |
lineitem = order.lineitems[0]
|
| - |
|
1266 |
warehouseClient = WarehouseClient().get_client()
|
| - |
|
1267 |
warehouseClient.scanSerializedItemForOrder(lineitem.serial_number, scanType, order.id, order.fulfilmentWarehouseId, lineitem.quantity, order.warehouse_id)
|
| - |
|
1268 |
except Exception as e:
|
| - |
|
1269 |
print sys.exc_info()[0]
|
| - |
|
1270 |
print 'Could not scan in sales return orders' + str(e)
|
| - |
|
1271 |
|
| 1275 |
return True
|
1272 |
return True
|
| 1276 |
|
1273 |
|
| 1277 |
def validate_doa(order_id, is_valid):
|
1274 |
def validate_doa(order_id, is_valid):
|
| 1278 |
order = get_order(order_id)
|
1275 |
order = get_order(order_id)
|
| 1279 |
if order.status != OrderStatus.DOA_RECEIVED_PRESTINE:
|
1276 |
if order.status != OrderStatus.DOA_RECEIVED_PRESTINE:
|
| Line 1290... |
Line 1287... |
| 1290 |
|
1287 |
|
| 1291 |
def validate_return_product(order_id, is_usable):
|
1288 |
def validate_return_product(order_id, is_usable):
|
| 1292 |
order = get_order(order_id)
|
1289 |
order = get_order(order_id)
|
| 1293 |
if order.status != OrderStatus.RET_RECEIVED_PRESTINE:
|
1290 |
if order.status != OrderStatus.RET_RECEIVED_PRESTINE:
|
| 1294 |
return False
|
1291 |
return False
|
| - |
|
1292 |
|
| - |
|
1293 |
scanType = ScanType.SALE_RET_UNUSABLE
|
| 1295 |
if is_usable:
|
1294 |
if is_usable:
|
| 1296 |
order.status = OrderStatus.RET_PRODUCT_USABLE
|
1295 |
order.status = OrderStatus.RET_PRODUCT_USABLE
|
| 1297 |
order.statusDescription = "Return product usable"
|
1296 |
order.statusDescription = "Return product usable"
|
| 1298 |
lineitem = order.lineitems[0]
|
1297 |
scanType = ScanType.SALE_RET
|
| 1299 |
if order.warehouse_id == 7:
|
- |
|
| 1300 |
catalog_client = CatalogClient().get_client()
|
- |
|
| 1301 |
catalog_client.addInventory(lineitem.item_id, order.warehouse_id, lineitem.quantity)
|
- |
|
| 1302 |
else:
|
1298 |
else:
|
| 1303 |
order.status = OrderStatus.RET_PRODUCT_UNUSABLE
|
1299 |
order.status = OrderStatus.RET_PRODUCT_UNUSABLE
|
| 1304 |
order.statusDescription = "Return product unusable"
|
1300 |
order.statusDescription = "Return product unusable"
|
| 1305 |
update_trust_level(order)
|
1301 |
update_trust_level(order)
|
| 1306 |
session.commit()
|
1302 |
session.commit()
|
| - |
|
1303 |
|
| - |
|
1304 |
# For OUR warehouses, we need to scan in items for every return
|
| - |
|
1305 |
catalogClient = CatalogClient().get_client()
|
| - |
|
1306 |
warehouse = catalogClient.getWarehouse(order.warehouse_id)
|
| - |
|
1307 |
if warehouse.billingType == BillingType.OURS:
|
| - |
|
1308 |
lineitem = order.lineitems[0]
|
| - |
|
1309 |
warehouse_client = WarehouseClient().get_client()
|
| - |
|
1310 |
warehouse_client.scanSerializedItemForOrder(lineitem.serial_number, scanType, order.id, order.fulfilmentWarehouseId, lineitem.quantity, order.warehouse_id)
|
| 1307 |
return True
|
1311 |
return True
|
| 1308 |
|
1312 |
|
| 1309 |
def reship_order(order_id):
|
1313 |
def reship_order(order_id):
|
| 1310 |
"""
|
1314 |
"""
|
| 1311 |
If the order is in RTO_RECEIVED_PRESTINE or DOA_CERT_INVALID state, it does the following:
|
1315 |
If the order is in RTO_RECEIVED_PRESTINE or DOA_CERT_INVALID state, it does the following:
|
| Line 1544... |
Line 1548... |
| 1544 |
__update_inventory_reservation(order)
|
1548 |
__update_inventory_reservation(order)
|
| 1545 |
order.statusDescription = "Order Cancelled due to payment flagged"
|
1549 |
order.statusDescription = "Order Cancelled due to payment flagged"
|
| 1546 |
|
1550 |
|
| 1547 |
# For orders that are cancelled after being billed, we need to scan in the scanned out
|
1551 |
# For orders that are cancelled after being billed, we need to scan in the scanned out
|
| 1548 |
# inventory item and change availability accordingly
|
1552 |
# inventory item and change availability accordingly
|
| - |
|
1553 |
catalogClient = CatalogClient().get_client()
|
| - |
|
1554 |
warehouse = catalogClient.getWarehouse(order.warehouse_id)
|
| 1549 |
if order.warehouse_id == 7:
|
1555 |
if warehouse.billingType == BillingType.OURS:
|
| 1550 |
if order.status in [OrderStatus.BILLED, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_FROM_WH] or (order.status == OrderStatus.CANCEL_REQUEST_CONFIRMED and order.previousStatus in [OrderStatus.BILLED, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_FROM_WH]):
|
1556 |
if order.status in [OrderStatus.BILLED, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_FROM_WH] or (order.status == OrderStatus.CANCEL_REQUEST_CONFIRMED and order.previousStatus in [OrderStatus.BILLED, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_FROM_WH]):
|
| 1551 |
lineitem = order.lineitems[0]
|
1557 |
lineitem = order.lineitems[0]
|
| 1552 |
warehouseClient = WarehouseClient().get_client()
|
1558 |
warehouseClient = WarehouseClient().get_client()
|
| 1553 |
warehouseClient.scanSerializedItemForOrder(lineitem.serial_number, ScanType.SALE_RET, order.id, order.warehouse_id)
|
1559 |
warehouseClient.scanSerializedItemForOrder(lineitem.serial_number, ScanType.SALE_RET, order.id, order.fulfilmentWarehouseId, lineitem.quantity, order.warehouse_id)
|
| 1554 |
# Increasing availability as well here
|
- |
|
| 1555 |
catalogClient = CatalogClient().get_client()
|
- |
|
| 1556 |
catalogClient.addInventory(lineitem.item_id, order.warehouse_id, lineitem.quantity)
|
- |
|
| 1557 |
|
1560 |
|
| 1558 |
order.status = status_transition[order.status]
|
1561 |
order.status = status_transition[order.status]
|
| 1559 |
order.refund_timestamp = datetime.datetime.now()
|
1562 |
order.refund_timestamp = datetime.datetime.now()
|
| 1560 |
order.refunded_by = refunded_by
|
1563 |
order.refunded_by = refunded_by
|
| 1561 |
order.refund_reason = reason
|
1564 |
order.refund_reason = reason
|
| Line 1568... |
Line 1571... |
| 1568 |
Reduce the reservation count for all line items of the given order.
|
1571 |
Reduce the reservation count for all line items of the given order.
|
| 1569 |
'''
|
1572 |
'''
|
| 1570 |
try:
|
1573 |
try:
|
| 1571 |
catalog_client = CatalogClient().get_client()
|
1574 |
catalog_client = CatalogClient().get_client()
|
| 1572 |
for lineitem in order.lineitems:
|
1575 |
for lineitem in order.lineitems:
|
| 1573 |
catalog_client.reduceReservationCount(lineitem.item_id, order.warehouse_id, lineitem.quantity);
|
1576 |
catalog_client.reduceReservationCount(lineitem.item_id, order.fulfilmentWarehouseId, lineitem.quantity);
|
| 1574 |
except:
|
1577 |
except:
|
| 1575 |
print "Unable to reduce reservation count"
|
1578 |
print "Unable to reduce reservation count"
|
| 1576 |
|
1579 |
|
| 1577 |
def __clone_order(order, should_copy_billing_info, is_cod):
|
1580 |
def __clone_order(order, should_copy_billing_info, is_cod):
|
| 1578 |
current_time = datetime.datetime.now()
|
1581 |
current_time = datetime.datetime.now()
|
| Line 1620... |
Line 1623... |
| 1620 |
|
1623 |
|
| 1621 |
logistics_client = LogisticsClient().get_client()
|
1624 |
logistics_client = LogisticsClient().get_client()
|
| 1622 |
item_id = new_order.lineitems[0].item_id
|
1625 |
item_id = new_order.lineitems[0].item_id
|
| 1623 |
logistics_info = logistics_client.getLogisticsInfo(new_order.customer_pincode, item_id, is_cod) #TODO: We should be able to pass another flag to suggest ignoring the inventory situation.
|
1626 |
logistics_info = logistics_client.getLogisticsInfo(new_order.customer_pincode, item_id, is_cod) #TODO: We should be able to pass another flag to suggest ignoring the inventory situation.
|
| 1624 |
logistics_info.deliveryTime = adjust_delivery_time(current_time, logistics_info.deliveryTime)
|
1627 |
logistics_info.deliveryTime = adjust_delivery_time(current_time, logistics_info.deliveryTime)
|
| 1625 |
|
- |
|
| 1626 |
new_order.warehouse_id = logistics_info.warehouseId
|
1628 |
new_order.warehouse_id = logistics_info.warehouseId
|
| - |
|
1629 |
new_order.fulfilmentWarehouseId = logistics_info.fulfilmentWarehouseId
|
| 1627 |
new_order.logistics_provider_id = logistics_info.providerId
|
1630 |
new_order.logistics_provider_id = logistics_info.providerId
|
| 1628 |
new_order.airwaybill_no = logistics_info.airway_billno
|
1631 |
new_order.airwaybill_no = logistics_info.airway_billno
|
| 1629 |
new_order.tracking_id = new_order.airwaybill_no
|
1632 |
new_order.tracking_id = new_order.airwaybill_no
|
| 1630 |
new_order.expected_delivery_time = current_time + datetime.timedelta(days=logistics_info.deliveryTime)
|
1633 |
new_order.expected_delivery_time = current_time + datetime.timedelta(days=logistics_info.deliveryTime)
|
| 1631 |
new_order.promised_delivery_time = new_order.expected_delivery_time
|
1634 |
new_order.promised_delivery_time = new_order.expected_delivery_time
|
| 1632 |
|
1635 |
|
| 1633 |
if should_copy_billing_info:
|
1636 |
if should_copy_billing_info:
|
| 1634 |
new_order.invoice_number = order.invoice_number
|
1637 |
new_order.invoice_number = order.invoice_number
|
| 1635 |
new_order.billed_by = order.billed_by
|
1638 |
new_order.billed_by = order.billed_by
|
| 1636 |
new_order.warehouse_id = order.warehouse_id
|
1639 |
new_order.warehouse_id = order.warehouse_id
|
| - |
|
1640 |
new_order.fulfilmentWarehouseId = order.fulfilmentWarehouseId
|
| 1637 |
new_order.accepted_timestamp = current_time
|
1641 |
new_order.accepted_timestamp = current_time
|
| 1638 |
new_order.billing_timestamp = current_time
|
1642 |
new_order.billing_timestamp = current_time
|
| 1639 |
new_order.status = OrderStatus.BILLED
|
1643 |
new_order.status = OrderStatus.BILLED
|
| 1640 |
new_order.statusDescription = 'Order Billed'
|
1644 |
new_order.statusDescription = 'Order Billed'
|
| 1641 |
else:
|
1645 |
else:
|
| 1642 |
catalog_client = CatalogClient().get_client()
|
1646 |
catalog_client = CatalogClient().get_client()
|
| 1643 |
catalog_client.reserveItemInWarehouse(item_id, logistics_info.warehouseId, new_order.lineitems[0].quantity)
|
1647 |
catalog_client.reserveItemInWarehouse(item_id, logistics_info.fulfilmentWarehouseId, new_order.lineitems[0].quantity)
|
| 1644 |
|
1648 |
|
| 1645 |
return new_order
|
1649 |
return new_order
|
| 1646 |
|
1650 |
|
| 1647 |
def __create_return_order(order):
|
1651 |
def __create_return_order(order):
|
| 1648 |
ret_order = ReturnOrder(order)
|
1652 |
ret_order = ReturnOrder(order)
|
| Line 1769... |
Line 1773... |
| 1769 |
old_item = catalog_client.getItem(lineitem.item_id)
|
1773 |
old_item = catalog_client.getItem(lineitem.item_id)
|
| 1770 |
item = catalog_client.getItem(item_id)
|
1774 |
item = catalog_client.getItem(item_id)
|
| 1771 |
if old_item.catalogItemId != item.catalogItemId:
|
1775 |
if old_item.catalogItemId != item.catalogItemId:
|
| 1772 |
raise TransactionServiceException(121, "You can't ship a different item. You can only ship the same item in a different color.")
|
1776 |
raise TransactionServiceException(121, "You can't ship a different item. You can only ship the same item in a different color.")
|
| 1773 |
|
1777 |
|
| 1774 |
catalog_client.reserveItemInWarehouse(item_id, order.warehouse_id, lineitem.quantity)
|
1778 |
catalog_client.reserveItemInWarehouse(item_id, order.fulfilmentWarehouseId, lineitem.quantity)
|
| 1775 |
catalog_client.reduceReservationCount(lineitem.item_id, order.warehouse_id, lineitem.quantity)
|
1779 |
__update_inventory_reservation(order)
|
| 1776 |
#TODO: Check that this new item has the same price
|
1780 |
#TODO: Check that this new item has the same price
|
| 1777 |
|
1781 |
|
| 1778 |
lineitem.item_id = item_id
|
1782 |
lineitem.item_id = item_id
|
| 1779 |
lineitem.color = item.color
|
1783 |
lineitem.color = item.color
|
| 1780 |
|
1784 |
|
| Line 1798... |
Line 1802... |
| 1798 |
catalog_client = CatalogClient().get_client()
|
1802 |
catalog_client = CatalogClient().get_client()
|
| 1799 |
try:
|
1803 |
try:
|
| 1800 |
warehouse = catalog_client.getWarehouse(warehouse_id)
|
1804 |
warehouse = catalog_client.getWarehouse(warehouse_id)
|
| 1801 |
except:
|
1805 |
except:
|
| 1802 |
raise TransactionServiceException(119, "No warehouse with id" + str(warehouse_id))
|
1806 |
raise TransactionServiceException(119, "No warehouse with id" + str(warehouse_id))
|
| - |
|
1807 |
|
| - |
|
1808 |
if warehouse.billingWarehouseId is None or warehouse.inventoryType != InventoryType.GOOD:
|
| - |
|
1809 |
raise TransactionServiceException(119, "Shifting of warehouse allowed to GOOD inventory type warehouse with billing support")
|
| 1803 |
|
1810 |
|
| 1804 |
catalog_client.reserveItemInWarehouse(lineitem.item_id, warehouse_id, lineitem.quantity)
|
1811 |
catalog_client.reserveItemInWarehouse(lineitem.item_id, warehouse_id, lineitem.quantity)
|
| 1805 |
catalog_client.reduceReservationCount(lineitem.item_id, order.warehouse_id, lineitem.quantity)
|
1812 |
__update_inventory_reservation(order)
|
| 1806 |
|
1813 |
|
| - |
|
1814 |
order.warehouse_id = warehouse.billingWarehouseId
|
| 1807 |
order.warehouse_id = warehouse_id
|
1815 |
order.fulfilmentWarehouseId = warehouse_id
|
| 1808 |
session.commit()
|
1816 |
session.commit()
|
| 1809 |
return order
|
1817 |
return order
|
| 1810 |
|
1818 |
|
| 1811 |
def add_delay_reason(order_id, reason, further_delay, delayReasonText):
|
1819 |
def add_delay_reason(order_id, reason, further_delay, delayReasonText):
|
| 1812 |
'''
|
1820 |
'''
|