| Line 1988... |
Line 1988... |
| 1988 |
LOGGER.error("Error while processing missing scratch offer invoice orderId", fofoOrder.getId());
|
1988 |
LOGGER.error("Error while processing missing scratch offer invoice orderId", fofoOrder.getId());
|
| 1989 |
}
|
1989 |
}
|
| 1990 |
}
|
1990 |
}
|
| 1991 |
}
|
1991 |
}
|
| 1992 |
}
|
1992 |
}
|
| - |
|
1993 |
|
| - |
|
1994 |
@Override
|
| - |
|
1995 |
public boolean refundOrder(int orderId, String refundedBy, String refundReason) throws ProfitMandiBusinessException {
|
| - |
|
1996 |
/*def refund_order(order_id, refunded_by, reason):
|
| - |
|
1997 |
"""
|
| - |
|
1998 |
If the order is in RTO_RECEIVED_PRESTINE, DOA_CERT_VALID or DOA_CERT_INVALID state, it does the following:
|
| - |
|
1999 |
1. Creates a refund request for batch processing.
|
| - |
|
2000 |
2. Creates a return order for the warehouse executive to return the shipped material.
|
| - |
|
2001 |
3. Marks the current order as RTO_REFUNDED, DOA_VALID_REFUNDED or DOA_INVALID_REFUNDED final states.
|
| - |
|
2002 |
|
| - |
|
2003 |
If the order is in SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
|
| - |
|
2004 |
1. Creates a refund request for batch processing.
|
| - |
|
2005 |
2. Cancels the reservation of the item in the warehouse.
|
| - |
|
2006 |
3. Marks the current order as the REFUNDED final state.
|
| - |
|
2007 |
|
| - |
|
2008 |
For all COD orders, if the order is in INIT, SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
|
| - |
|
2009 |
1. Cancels the reservation of the item in the warehouse.
|
| - |
|
2010 |
2. Marks the current order as CANCELED.
|
| - |
|
2011 |
|
| - |
|
2012 |
In all cases, it updates the reason for cancellation or refund and the person who performed the action.
|
| - |
|
2013 |
|
| - |
|
2014 |
Returns True if it is successful, False otherwise.
|
| - |
|
2015 |
|
| - |
|
2016 |
Throws an exception if the order with the given id couldn't be found.
|
| - |
|
2017 |
|
| - |
|
2018 |
Parameters:
|
| - |
|
2019 |
- order_id
|
| - |
|
2020 |
- refunded_by
|
| - |
|
2021 |
- reason
|
| - |
|
2022 |
"""
|
| - |
|
2023 |
LOGGER.info("Refunding order id: {}", orderId);
|
| - |
|
2024 |
Order order = orderRepository.selectById(orderId);
|
| - |
|
2025 |
|
| - |
|
2026 |
if order.cod:
|
| - |
|
2027 |
logging.info("Refunding COD order with status " + str(order.status))
|
| - |
|
2028 |
status_transition = refund_status_transition
|
| - |
|
2029 |
if order.status not in status_transition.keys():
|
| - |
|
2030 |
raise TransactionServiceException(114, "This order can't be refunded")
|
| - |
|
2031 |
|
| - |
|
2032 |
if order.status in [OrderStatus.COD_VERIFICATION_PENDING, 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.ACCEPTED]:
|
| - |
|
2033 |
__update_inventory_reservation(order, refund=True)
|
| - |
|
2034 |
order.statusDescription = "Order Cancelled"
|
| - |
|
2035 |
#Shipment Id and Airway Bill No should be none in case of Cancellation
|
| - |
|
2036 |
order.logisticsTransactionId = None
|
| - |
|
2037 |
order.tracking_id = None
|
| - |
|
2038 |
order.airwaybill_no = None
|
| - |
|
2039 |
elif order.status == OrderStatus.BILLED:
|
| - |
|
2040 |
__create_return_order(order)
|
| - |
|
2041 |
order.statusDescription = "Order Cancelled"
|
| - |
|
2042 |
elif order.status in [OrderStatus.RTO_RECEIVED_PRESTINE, OrderStatus.RTO_RECEIVED_DAMAGED, OrderStatus.RTO_LOST_IN_TRANSIT]:
|
| - |
|
2043 |
if order.status != OrderStatus.RTO_LOST_IN_TRANSIT:
|
| - |
|
2044 |
__create_return_order(order)
|
| - |
|
2045 |
order.statusDescription = "RTO Refunded"
|
| - |
|
2046 |
elif order.status in [OrderStatus.LOST_IN_TRANSIT]:
|
| - |
|
2047 |
#__create_return_order(order)
|
| - |
|
2048 |
order.statusDescription = "Lost in Transit Refunded"
|
| - |
|
2049 |
elif order.status in [OrderStatus.DOA_CERT_INVALID, OrderStatus.DOA_CERT_VALID, OrderStatus.DOA_RECEIVED_DAMAGED, OrderStatus.DOA_LOST_IN_TRANSIT] :
|
| - |
|
2050 |
if order.status != OrderStatus.DOA_LOST_IN_TRANSIT:
|
| - |
|
2051 |
__create_return_order(order)
|
| - |
|
2052 |
__create_refund(order, 0, 'Should be unreachable for now')
|
| - |
|
2053 |
order.statusDescription = "DOA Refunded"
|
| - |
|
2054 |
elif order.status in [OrderStatus.RET_PRODUCT_UNUSABLE, OrderStatus.RET_PRODUCT_USABLE, OrderStatus.RET_RECEIVED_DAMAGED, OrderStatus.RET_LOST_IN_TRANSIT] :
|
| - |
|
2055 |
if order.status != OrderStatus.RET_LOST_IN_TRANSIT:
|
| - |
|
2056 |
__create_return_order(order)
|
| - |
|
2057 |
__create_refund(order, 0, 'Should be unreachable for now')
|
| - |
|
2058 |
order.statusDescription = "Return Refunded"
|
| - |
|
2059 |
elif order.status == OrderStatus.CANCEL_REQUEST_CONFIRMED:
|
| - |
|
2060 |
if order.previousStatus in [OrderStatus.COD_VERIFICATION_PENDING, 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.ACCEPTED]:
|
| - |
|
2061 |
__update_inventory_reservation(order, refund=True)
|
| - |
|
2062 |
order.statusDescription = "Order Cancelled on customer request"
|
| - |
|
2063 |
elif order.previousStatus == OrderStatus.BILLED:
|
| - |
|
2064 |
__create_return_order(order)
|
| - |
|
2065 |
order.statusDescription = "Order Cancelled on customer request"
|
| - |
|
2066 |
order.received_return_timestamp = datetime.datetime.now()
|
| - |
|
2067 |
else:
|
| - |
|
2068 |
status_transition = {OrderStatus.LOST_IN_TRANSIT : OrderStatus.LOST_IN_TRANSIT_REFUNDED,
|
| - |
|
2069 |
OrderStatus.RTO_RECEIVED_PRESTINE : OrderStatus.RTO_REFUNDED,
|
| - |
|
2070 |
OrderStatus.RTO_RECEIVED_DAMAGED : OrderStatus.RTO_DAMAGED_REFUNDED,
|
| - |
|
2071 |
OrderStatus.RTO_LOST_IN_TRANSIT : OrderStatus.RTO_LOST_IN_TRANSIT_REFUNDED,
|
| - |
|
2072 |
OrderStatus.DOA_CERT_INVALID : OrderStatus.DOA_INVALID_REFUNDED,
|
| - |
|
2073 |
OrderStatus.DOA_CERT_VALID : OrderStatus.DOA_VALID_REFUNDED,
|
| - |
|
2074 |
OrderStatus.DOA_RECEIVED_DAMAGED : OrderStatus.DOA_REFUNDED_RCVD_DAMAGED,
|
| - |
|
2075 |
OrderStatus.DOA_LOST_IN_TRANSIT : OrderStatus.DOA_REFUNDED_LOST_IN_TRANSIT,
|
| - |
|
2076 |
OrderStatus.RET_PRODUCT_UNUSABLE : OrderStatus.RET_PRODUCT_UNUSABLE_REFUNDED,
|
| - |
|
2077 |
OrderStatus.RET_PRODUCT_USABLE : OrderStatus.RET_PRODUCT_USABLE_REFUNDED,
|
| - |
|
2078 |
OrderStatus.RET_RECEIVED_DAMAGED : OrderStatus.RET_REFUNDED_RCVD_DAMAGED,
|
| - |
|
2079 |
OrderStatus.RET_LOST_IN_TRANSIT : OrderStatus.RET_REFUNDED_LOST_IN_TRANSIT,
|
| - |
|
2080 |
OrderStatus.SUBMITTED_FOR_PROCESSING : OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY,
|
| - |
|
2081 |
OrderStatus.INVENTORY_LOW : OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY,
|
| - |
|
2082 |
OrderStatus.LOW_INV_PO_RAISED : OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY,
|
| - |
|
2083 |
OrderStatus.LOW_INV_REVERSAL_IN_PROCESS : OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY,
|
| - |
|
2084 |
OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT : OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY,
|
| - |
|
2085 |
OrderStatus.ACCEPTED : OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY,
|
| - |
|
2086 |
OrderStatus.BILLED : OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY,
|
| - |
|
2087 |
OrderStatus.CANCEL_REQUEST_CONFIRMED : OrderStatus.CANCELLED_ON_CUSTOMER_REQUEST,
|
| - |
|
2088 |
OrderStatus.PAYMENT_FLAGGED : OrderStatus.PAYMENT_FLAGGED_DENIED
|
| - |
|
2089 |
}
|
| - |
|
2090 |
if order.status not in status_transition.keys():
|
| - |
|
2091 |
raise TransactionServiceException(114, "This order can't be refunded")
|
| - |
|
2092 |
|
| - |
|
2093 |
if order.status in [OrderStatus.RTO_RECEIVED_PRESTINE, OrderStatus.RTO_RECEIVED_DAMAGED, OrderStatus.RTO_LOST_IN_TRANSIT] :
|
| - |
|
2094 |
if order.status != OrderStatus.RTO_LOST_IN_TRANSIT:
|
| - |
|
2095 |
__create_return_order(order)
|
| - |
|
2096 |
__create_refund(order, order.wallet_amount, 'Order #{0} is RTO refunded'.format(order.id))
|
| - |
|
2097 |
order.statusDescription = "RTO Refunded"
|
| - |
|
2098 |
#Start:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
|
| - |
|
2099 |
try:
|
| - |
|
2100 |
crmServiceClient = CRMClient().get_client()
|
| - |
|
2101 |
ticket =Ticket()
|
| - |
|
2102 |
activity = Activity()
|
| - |
|
2103 |
|
| - |
|
2104 |
description = "Creating Ticket for " + order.statusDescription + " Order"
|
| - |
|
2105 |
ticket.creatorId = 1
|
| - |
|
2106 |
ticket.assigneeId = 34
|
| - |
|
2107 |
ticket.category = TicketCategory.RTO_REFUND
|
| - |
|
2108 |
ticket.priority = TicketPriority.MEDIUM
|
| - |
|
2109 |
ticket.status = TicketStatus.OPEN
|
| - |
|
2110 |
ticket.description = description
|
| - |
|
2111 |
ticket.orderId = order.id
|
| - |
|
2112 |
|
| - |
|
2113 |
activity.creatorId = 1
|
| - |
|
2114 |
activity.ticketAssigneeId = ticket.assigneeId
|
| - |
|
2115 |
activity.type = ActivityType.OTHER
|
| - |
|
2116 |
activity.description = description
|
| - |
|
2117 |
activity.ticketCategory = ticket.category
|
| - |
|
2118 |
activity.ticketDescription = ticket.description
|
| - |
|
2119 |
activity.ticketPriority = ticket.priority
|
| - |
|
2120 |
activity.ticketStatus = ticket.status
|
| - |
|
2121 |
|
| - |
|
2122 |
ticket.customerId= order.customer_id
|
| - |
|
2123 |
ticket.customerEmailId = order.customer_email
|
| - |
|
2124 |
ticket.customerMobileNumber = order.customer_mobilenumber
|
| - |
|
2125 |
ticket.customerName = order.customer_name
|
| - |
|
2126 |
activity.customerId = ticket.customerId
|
| - |
|
2127 |
activity.customerEmailId = order.customer_email
|
| - |
|
2128 |
activity.customerMobileNumber = order.customer_mobilenumber
|
| - |
|
2129 |
activity.customerName = order.customer_name
|
| - |
|
2130 |
|
| - |
|
2131 |
crmServiceClient.insertTicket(ticket, activity)
|
| - |
|
2132 |
|
| - |
|
2133 |
except:
|
| - |
|
2134 |
print "Ticket for RTO Refund is not created."
|
| - |
|
2135 |
#End:- Added By Manish Sharma for Creating a new Ticket: Category- RTO Refund on 21-Jun-2013
|
| - |
|
2136 |
elif order.status in [OrderStatus.LOST_IN_TRANSIT]:
|
| - |
|
2137 |
#__create_return_order(order)
|
| - |
|
2138 |
__create_refund(order, order.wallet_amount, 'Order #{0} is Lost in Transit'.format(order.id))
|
| - |
|
2139 |
order.statusDescription = "Lost in Transit Refunded"
|
| - |
|
2140 |
elif order.status in [OrderStatus.DOA_CERT_INVALID, OrderStatus.DOA_CERT_VALID, OrderStatus.DOA_RECEIVED_DAMAGED, OrderStatus.DOA_LOST_IN_TRANSIT] :
|
| - |
|
2141 |
if order.status != OrderStatus.DOA_LOST_IN_TRANSIT:
|
| - |
|
2142 |
__create_return_order(order)
|
| - |
|
2143 |
__create_refund(order, 0, 'This should be unreachable')
|
| - |
|
2144 |
order.statusDescription = "DOA Refunded"
|
| - |
|
2145 |
elif order.status in [OrderStatus.RET_PRODUCT_UNUSABLE, OrderStatus.RET_PRODUCT_USABLE, OrderStatus.RET_RECEIVED_DAMAGED, OrderStatus.RET_LOST_IN_TRANSIT] :
|
| - |
|
2146 |
if order.status != OrderStatus.RET_LOST_IN_TRANSIT:
|
| - |
|
2147 |
__create_return_order(order)
|
| - |
|
2148 |
__create_refund(order, 0, 'This should be unreachable')
|
| - |
|
2149 |
order.statusDescription = "Return Refunded"
|
| - |
|
2150 |
elif 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.ACCEPTED]:
|
| - |
|
2151 |
__update_inventory_reservation(order, refund=True)
|
| - |
|
2152 |
order.statusDescription = "Order Refunded"
|
| - |
|
2153 |
elif order.status == OrderStatus.CANCEL_REQUEST_CONFIRMED:
|
| - |
|
2154 |
if order.previousStatus 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.PAYMENT_FLAGGED, OrderStatus.ACCEPTED]:
|
| - |
|
2155 |
__update_inventory_reservation(order, refund=True)
|
| - |
|
2156 |
order.statusDescription = "Order Cancelled on customer request"
|
| - |
|
2157 |
elif order.previousStatus == OrderStatus.BILLED:
|
| - |
|
2158 |
__create_refund(order, order.wallet_amount, 'Order #{0} Cancelled on customer request'.format(order.id))
|
| - |
|
2159 |
order.statusDescription = "Order Cancelled on customer request"
|
| - |
|
2160 |
|
| - |
|
2161 |
elif order.status == OrderStatus.PAYMENT_FLAGGED:
|
| - |
|
2162 |
__update_inventory_reservation(order, refund=True)
|
| - |
|
2163 |
order.statusDescription = "Order Cancelled due to payment flagged"
|
| - |
|
2164 |
|
| - |
|
2165 |
# For orders that are cancelled after being billed, we need to scan in the scanned out
|
| - |
|
2166 |
# inventory item and change availability accordingly
|
| - |
|
2167 |
inventoryClient = InventoryClient().get_client()
|
| - |
|
2168 |
warehouse = inventoryClient.getWarehouse(order.warehouse_id)
|
| - |
|
2169 |
if warehouse.billingType == BillingType.OURS or warehouse.billingType == BillingType.OURS_EXTERNAL:
|
| - |
|
2170 |
#Now BILLED orders can also be refunded directly with low inventory cancellations
|
| - |
|
2171 |
if order.status in [OrderStatus.BILLED, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_FROM_WH]:
|
| - |
|
2172 |
__create_refund(order, order.wallet_amount, reason)
|
| - |
|
2173 |
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]):
|
| - |
|
2174 |
lineitem = order.lineitems[0]
|
| - |
|
2175 |
catalogClient = CatalogClient().get_client()
|
| - |
|
2176 |
item = catalogClient.getItem(lineitem.item_id)
|
| - |
|
2177 |
warehouseClient = WarehouseClient().get_client()
|
| - |
|
2178 |
if warehouse.billingType == BillingType.OURS:
|
| - |
|
2179 |
if ItemType.SERIALIZED == item.type:
|
| - |
|
2180 |
for serial_number in str(lineitem.serial_number).split(','):
|
| - |
|
2181 |
warehouseClient.scanSerializedItemForOrder(serial_number, ScanType.SALE_RET, order.id, order.fulfilmentWarehouseId, 1, order.warehouse_id)
|
| - |
|
2182 |
else:
|
| - |
|
2183 |
warehouseClient.scanForOrder(None, ScanType.SALE_RET, lineitem.quantity, order.id, order.fulfilmentWarehouseId, order.warehouse_id)
|
| - |
|
2184 |
if warehouse.billingType == BillingType.OURS_EXTERNAL:
|
| - |
|
2185 |
warehouseClient.scanForOursExternalSaleReturn(order.id, lineitem.transfer_price)
|
| - |
|
2186 |
if order.freebieItemId:
|
| - |
|
2187 |
warehouseClient.scanfreebie(order.id, order.freebieItemId, 0, ScanType.SALE_RET)
|
| - |
|
2188 |
|
| - |
|
2189 |
order.status = status_transition[order.status]
|
| - |
|
2190 |
order.statusDescription = OrderStatus._VALUES_TO_NAMES[order.status]
|
| - |
|
2191 |
order.refund_timestamp = datetime.datetime.now()
|
| - |
|
2192 |
order.refunded_by = refunded_by
|
| - |
|
2193 |
order.refund_reason = reason
|
| - |
|
2194 |
#to re evaluate the shipping charge if any order is being cancelled.
|
| - |
|
2195 |
#_revaluate_shiping(order_id)
|
| - |
|
2196 |
session.commit()
|
| - |
|
2197 |
return True*/
|
| - |
|
2198 |
return true;
|
| - |
|
2199 |
}
|
| - |
|
2200 |
|
| - |
|
2201 |
@Autowired
|
| - |
|
2202 |
DebitNoteRepository debitNoteRepository;
|
| - |
|
2203 |
|
| - |
|
2204 |
//initiate refund only if the stock is returned
|
| - |
|
2205 |
|
| 1993 |
}
|
2206 |
}
|
| 1994 |
|
2207 |
|