| Line 17... |
Line 17... |
| 17 |
from shop2020.clients.WarehouseClient import WarehouseClient
|
17 |
from shop2020.clients.WarehouseClient import WarehouseClient
|
| 18 |
from shop2020.model.v1 import order
|
18 |
from shop2020.model.v1 import order
|
| 19 |
from shop2020.model.v1.order.impl.DataService import Transaction, LineItem, \
|
19 |
from shop2020.model.v1.order.impl.DataService import Transaction, LineItem, \
|
| 20 |
Order, BatchNoGenerator, InvoiceIDGenerator, TransactionRequiringExtraProcessing, \
|
20 |
Order, BatchNoGenerator, InvoiceIDGenerator, TransactionRequiringExtraProcessing, \
|
| 21 |
OrderInventory, Alert, PaymentSettlement, EBSSettlementSummary, \
|
21 |
OrderInventory, Alert, PaymentSettlement, EBSSettlementSummary, \
|
| 22 |
CodVerificationAgent, RechargeVoucherTracker
|
22 |
CodVerificationAgent, Attribute, RechargeVoucherTracker
|
| - |
|
23 |
|
| 23 |
from shop2020.model.v1.order.impl.model.ReturnOrder import ReturnOrder
|
24 |
from shop2020.model.v1.order.impl.model.ReturnOrder import ReturnOrder
|
| 24 |
from shop2020.thriftpy.generic.ttypes import ExceptionType
|
25 |
from shop2020.thriftpy.generic.ttypes import ExceptionType
|
| 25 |
from shop2020.thriftpy.logistics.ttypes import DeliveryType
|
26 |
from shop2020.thriftpy.logistics.ttypes import DeliveryType, PickUpType
|
| 26 |
from shop2020.thriftpy.model.v1.catalog.ttypes import BillingType, \
|
27 |
from shop2020.thriftpy.model.v1.catalog.ttypes import BillingType, \
|
| 27 |
InventoryServiceException, WarehouseType, ItemType, InventoryType
|
28 |
InventoryServiceException, WarehouseType, ItemType, InventoryType
|
| 28 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
29 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
| 29 |
TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
|
30 |
TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
|
| 30 |
HotspotAction, TimeoutSummary, OrderStatusGroups
|
31 |
HotspotAction, TimeoutSummary, OrderStatusGroups, OrderType
|
| 31 |
from shop2020.thriftpy.payments.ttypes import PaymentException
|
32 |
from shop2020.thriftpy.payments.ttypes import PaymentException
|
| 32 |
from shop2020.thriftpy.warehouse.ttypes import ScanType, \
|
33 |
from shop2020.thriftpy.warehouse.ttypes import ScanType, \
|
| 33 |
WarehouseServiceException
|
34 |
WarehouseServiceException
|
| 34 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
|
35 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
|
| 35 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
36 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
| 36 |
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
|
37 |
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
|
| 37 |
from sqlalchemy.sql import func
|
38 |
from sqlalchemy.sql import func
|
| 38 |
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct
|
39 |
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct, select
|
| 39 |
from string import Template
|
40 |
from string import Template
|
| 40 |
from textwrap import dedent
|
41 |
from textwrap import dedent
|
| 41 |
import datetime
|
42 |
import datetime
|
| 42 |
import logging
|
43 |
import logging
|
| 43 |
import os
|
44 |
import os
|
| Line 182... |
Line 183... |
| 182 |
|
183 |
|
| 183 |
transaction = get_transaction(transaction_id)
|
184 |
transaction = get_transaction(transaction_id)
|
| 184 |
|
185 |
|
| 185 |
return transaction.status
|
186 |
return transaction.status
|
| 186 |
|
187 |
|
| 187 |
def change_transaction_status(transaction_id, new_status, description, selfPickup):
|
188 |
def change_transaction_status(transaction_id, new_status, description, pickUp, orderType):
|
| 188 |
transaction = get_transaction(transaction_id)
|
189 |
transaction = get_transaction(transaction_id)
|
| 189 |
transaction.status = new_status
|
190 |
transaction.status = new_status
|
| 190 |
transaction.status_message = description
|
191 |
transaction.status_message = description
|
| 191 |
if new_status == TransactionStatus.FAILED:
|
192 |
if new_status == TransactionStatus.FAILED:
|
| 192 |
for order in transaction.orders:
|
193 |
for order in transaction.orders:
|
| Line 199... |
Line 200... |
| 199 |
order.statusDescription = "Submitted to warehouse"
|
200 |
order.statusDescription = "Submitted to warehouse"
|
| 200 |
elif new_status == TransactionStatus.FLAGGED:
|
201 |
elif new_status == TransactionStatus.FLAGGED:
|
| 201 |
order.status = OrderStatus.PAYMENT_FLAGGED
|
202 |
order.status = OrderStatus.PAYMENT_FLAGGED
|
| 202 |
order.statusDescription = "Payment flagged by gateway"
|
203 |
order.statusDescription = "Payment flagged by gateway"
|
| 203 |
order.cod = False
|
204 |
order.cod = False
|
| - |
|
205 |
order.orderType = orderType
|
| 204 |
#After we got payment success, we will set logistics info also
|
206 |
#After we got payment success, we will set logistics info also
|
| 205 |
logistics_client = LogisticsClient().get_client()
|
207 |
logistics_client = LogisticsClient().get_client()
|
| 206 |
#FIXME line item is only one now. If multiple will come, need to fix.
|
208 |
#FIXME line item is only one now. If multiple will come, need to fix.
|
| 207 |
item_id = order.lineitems[0].item_id
|
209 |
item_id = order.lineitems[0].item_id
|
| 208 |
logistics_info = logistics_client.getLogisticsInfo(order.customer_pincode, item_id, DeliveryType.PREPAID)
|
210 |
logistics_info = logistics_client.getLogisticsInfo(order.customer_pincode, item_id, DeliveryType.PREPAID)
|
| Line 228... |
Line 230... |
| 228 |
item_pricing = catalog_client.getItemPricing(item_id, -1)
|
230 |
item_pricing = catalog_client.getItemPricing(item_id, -1)
|
| 229 |
order.lineitems[0].transfer_price = item_pricing.transferPrice
|
231 |
order.lineitems[0].transfer_price = item_pricing.transferPrice
|
| 230 |
except:
|
232 |
except:
|
| 231 |
print "Not able to get transfer price. Skipping"
|
233 |
print "Not able to get transfer price. Skipping"
|
| 232 |
|
234 |
|
| 233 |
if selfPickup:
|
235 |
if pickUp == PickUpType.SELF or pickUp == PickUpType.RUNNER:
|
| 234 |
order.logistics_provider_id = 4
|
236 |
logisticsClient = LogisticsClient().get_client()
|
| - |
|
237 |
order.logistics_provider_id = logisticsClient.getProviderForPickupType(pickUp)
|
| 235 |
order.airwaybill_no = 'Self Pickup'
|
238 |
order.airwaybill_no = PickUpType._VALUES_TO_NAMES.get(pickUp)
|
| 236 |
order.tracking_id = order.airwaybill_no
|
239 |
order.tracking_id = order.airwaybill_no
|
| 237 |
|
240 |
|
| 238 |
voucherAmount = catalog_client.getVoucherAmount(item_id, VoucherType.SPICEDECK_MOBILE)
|
241 |
voucherAmount = catalog_client.getVoucherAmount(item_id, VoucherType.SPICEDECK_MOBILE)
|
| 239 |
if voucherAmount:
|
242 |
if voucherAmount:
|
| 240 |
__create_recharge_voucher_tracker(order, voucherAmount, VoucherType.SPICEDECK_MOBILE)
|
243 |
__create_recharge_voucher_tracker(order, voucherAmount, VoucherType.SPICEDECK_MOBILE)
|
| Line 242... |
Line 245... |
| 242 |
elif new_status == TransactionStatus.COD_IN_PROCESS:
|
245 |
elif new_status == TransactionStatus.COD_IN_PROCESS:
|
| 243 |
for order in transaction.orders:
|
246 |
for order in transaction.orders:
|
| 244 |
order.status = OrderStatus.COD_VERIFICATION_PENDING
|
247 |
order.status = OrderStatus.COD_VERIFICATION_PENDING
|
| 245 |
order.statusDescription = "Verification Pending"
|
248 |
order.statusDescription = "Verification Pending"
|
| 246 |
order.cod = True
|
249 |
order.cod = True
|
| - |
|
250 |
order.orderType = orderType
|
| 247 |
#After we got payment success, we will set logistics info also
|
251 |
#After we got payment success, we will set logistics info also
|
| 248 |
logistics_client = LogisticsClient().get_client()
|
252 |
logistics_client = LogisticsClient().get_client()
|
| 249 |
#FIXME line item is only one now. If multiple will come, need to fix.
|
253 |
#FIXME line item is only one now. If multiple will come, need to fix.
|
| 250 |
item_id = order.lineitems[0].item_id
|
254 |
item_id = order.lineitems[0].item_id
|
| 251 |
logistics_info = logistics_client.getLogisticsInfo(order.customer_pincode, item_id, DeliveryType.COD)
|
255 |
logistics_info = logistics_client.getLogisticsInfo(order.customer_pincode, item_id, DeliveryType.COD)
|
| Line 626... |
Line 630... |
| 626 |
try:
|
630 |
try:
|
| 627 |
payment_client = PaymentClient().get_client()
|
631 |
payment_client = PaymentClient().get_client()
|
| 628 |
capture_result = payment_client.capturePayment(txnId)
|
632 |
capture_result = payment_client.capturePayment(txnId)
|
| 629 |
if capture_result:
|
633 |
if capture_result:
|
| 630 |
logging.info("Successfully captured payment for merchant txn:" + str(txnId))
|
634 |
logging.info("Successfully captured payment for merchant txn:" + str(txnId))
|
| 631 |
change_transaction_status(txnId, TransactionStatus.IN_PROCESS, "Payment received", False)
|
635 |
change_transaction_status(txnId, TransactionStatus.IN_PROCESS, "Payment received", PickUpType.COURIER, order.orderType)
|
| 632 |
else:
|
636 |
else:
|
| 633 |
raise TransactionServiceException(115, "Payment capture failed.")
|
637 |
raise TransactionServiceException(115, "Payment capture failed.")
|
| 634 |
except PaymentException as e:
|
638 |
except PaymentException as e:
|
| 635 |
if e.error_code == 106:
|
639 |
if e.error_code == 106:
|
| 636 |
order.status = OrderStatus.CAPTURE_IN_PROCESS
|
640 |
order.status = OrderStatus.CAPTURE_IN_PROCESS
|
| Line 663... |
Line 667... |
| 663 |
if ItemType.SERIALIZED == item.type and not (serialNumbers and serialNumbers[0]):
|
667 |
if ItemType.SERIALIZED == item.type and not (serialNumbers and serialNumbers[0]):
|
| 664 |
raise TransactionServiceException(110, "No Serial Number supplied")
|
668 |
raise TransactionServiceException(110, "No Serial Number supplied")
|
| 665 |
if serialNumbers:
|
669 |
if serialNumbers:
|
| 666 |
lineitem.serial_number = serialNumbers[0]
|
670 |
lineitem.serial_number = serialNumbers[0]
|
| 667 |
|
671 |
|
| 668 |
order.invoice_number = get_next_invoice_number()
|
672 |
order.invoice_number = get_next_invoice_number(order.orderType)
|
| 669 |
else:
|
673 |
else:
|
| 670 |
order.invoice_number = invoice_number
|
674 |
order.invoice_number = invoice_number
|
| 671 |
# In case of hotspot billing, we should try to verify that color billed in ETP is same as color in order.
|
675 |
# In case of hotspot billing, we should try to verify that color billed in ETP is same as color in order.
|
| 672 |
if billedOrdersColorMap.has_key(orderId):
|
676 |
if billedOrdersColorMap.has_key(orderId):
|
| 673 |
etpColor = billedOrdersColorMap.get(orderId)
|
677 |
etpColor = billedOrdersColorMap.get(orderId)
|
| Line 992... |
Line 996... |
| 992 |
query = query.order_by(desc(Order.created_timestamp))
|
996 |
query = query.order_by(desc(Order.created_timestamp))
|
| 993 |
if limit != 0:
|
997 |
if limit != 0:
|
| 994 |
query = query.limit(limit)
|
998 |
query = query.limit(limit)
|
| 995 |
return query.all()
|
999 |
return query.all()
|
| 996 |
|
1000 |
|
| 997 |
def get_next_invoice_number():
|
1001 |
def get_next_invoice_number(orderType):
|
| - |
|
1002 |
if OrderType.B2Cbulk == orderType:
|
| - |
|
1003 |
orderType = OrderType.B2C
|
| 998 |
entity_id = InvoiceIDGenerator.query.with_lockmode("update").one()
|
1004 |
entity_id = InvoiceIDGenerator.query.filter(InvoiceIDGenerator.orderType == orderType).with_lockmode("update").one()
|
| 999 |
invoice_number = entity_id.id + 1
|
1005 |
invoice_number = entity_id.id + 1
|
| 1000 |
entity_id.id = invoice_number
|
1006 |
entity_id.id = invoice_number
|
| 1001 |
return invoice_number
|
1007 |
return invoice_number
|
| 1002 |
|
1008 |
|
| 1003 |
def toggle_doa_flag(order_id):
|
1009 |
def toggle_doa_flag(order_id):
|
| Line 1651... |
Line 1657... |
| 1651 |
new_order.created_timestamp = current_time
|
1657 |
new_order.created_timestamp = current_time
|
| 1652 |
new_order.originalOrderId = order.originalOrderId if order.originalOrderId is not None else order.id
|
1658 |
new_order.originalOrderId = order.originalOrderId if order.originalOrderId is not None else order.id
|
| 1653 |
|
1659 |
|
| 1654 |
new_order.transaction = order.transaction
|
1660 |
new_order.transaction = order.transaction
|
| 1655 |
new_order.cod = is_cod
|
1661 |
new_order.cod = is_cod
|
| - |
|
1662 |
new_order.orderType = order.orderType
|
| 1656 |
|
1663 |
|
| 1657 |
for line_item in order.lineitems:
|
1664 |
for line_item in order.lineitems:
|
| 1658 |
litem = LineItem()
|
1665 |
litem = LineItem()
|
| 1659 |
litem.item_id = line_item.item_id
|
1666 |
litem.item_id = line_item.item_id
|
| 1660 |
litem.productGroup = line_item.productGroup
|
1667 |
litem.productGroup = line_item.productGroup
|
| Line 2603... |
Line 2610... |
| 2603 |
return Order.query.filter(Order.vendor_paid == 1).filter(Order.status.in_(orderStatusGroup.refundedOrders)).all()
|
2610 |
return Order.query.filter(Order.vendor_paid == 1).filter(Order.status.in_(orderStatusGroup.refundedOrders)).all()
|
| 2604 |
|
2611 |
|
| 2605 |
def get_all_verification_agents(minOrderId, maxOrderId):
|
2612 |
def get_all_verification_agents(minOrderId, maxOrderId):
|
| 2606 |
return CodVerificationAgent.query.filter(CodVerificationAgent.orderId >= minOrderId).filter(CodVerificationAgent.orderId <= maxOrderId).all()
|
2613 |
return CodVerificationAgent.query.filter(CodVerificationAgent.orderId >= minOrderId).filter(CodVerificationAgent.orderId <= maxOrderId).all()
|
| 2607 |
|
2614 |
|
| - |
|
2615 |
def get_all_attributes_for_order_id(orderId):
|
| - |
|
2616 |
return Attribute.query.filter(Attribute.orderId == orderId).all()
|
| - |
|
2617 |
|
| - |
|
2618 |
def set_order_attribute_for_transaction(transactionId, t_attribute):
|
| - |
|
2619 |
for order in Order.query.filter_by(transaction_id = transactionId).all():
|
| - |
|
2620 |
attribute = Attribute()
|
| - |
|
2621 |
attribute.orderId = order.id
|
| - |
|
2622 |
attribute.name = t_attribute.name
|
| - |
|
2623 |
attribute.value = t_attribute.value
|
| - |
|
2624 |
session.commit()
|
| - |
|
2625 |
|
| - |
|
2626 |
|
| 2608 |
def close_session():
|
2627 |
def close_session():
|
| 2609 |
if session.is_active:
|
2628 |
if session.is_active:
|
| 2610 |
print "session is active. closing it."
|
2629 |
print "session is active. closing it."
|
| 2611 |
session.close()
|
2630 |
session.close()
|
| 2612 |
|
2631 |
|