| Line 13... |
Line 13... |
| 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.UserClient import UserClient
|
16 |
from shop2020.clients.UserClient import UserClient
|
| 17 |
from shop2020.clients.WarehouseClient import WarehouseClient
|
17 |
from shop2020.clients.WarehouseClient import WarehouseClient
|
| - |
|
18 |
from shop2020.config.client.ConfigClient import ConfigClient
|
| 18 |
from shop2020.model.v1 import order
|
19 |
from shop2020.model.v1 import order
|
| 19 |
from shop2020.model.v1.order.impl.DataService import Transaction, LineItem, \
|
20 |
from shop2020.model.v1.order.impl.DataService import Transaction, LineItem, \
|
| 20 |
Order, BatchNoGenerator, InvoiceIDGenerator, \
|
21 |
Order, BatchNoGenerator, InvoiceIDGenerator, \
|
| 21 |
TransactionRequiringExtraProcessing, OrderInventory, Alert
|
22 |
TransactionRequiringExtraProcessing, OrderInventory, Alert
|
| 22 |
from shop2020.model.v1.order.impl.model.ReturnOrder import ReturnOrder
|
23 |
from shop2020.model.v1.order.impl.model.ReturnOrder import ReturnOrder
|
| 23 |
from shop2020.thriftpy.logistics.ttypes import DeliveryType
|
24 |
from shop2020.thriftpy.logistics.ttypes import DeliveryType
|
| 24 |
from shop2020.thriftpy.model.v1.catalog.ttypes import BillingType
|
25 |
from shop2020.thriftpy.model.v1.catalog.ttypes import BillingType
|
| 25 |
from shop2020.thriftpy.model.v1.order.ttypes import \
|
26 |
from shop2020.thriftpy.model.v1.order.ttypes import \
|
| 26 |
TransactionServiceException, TransactionStatus, OrderStatus, DelayReason, \
|
27 |
TransactionServiceException, TransactionStatus, OrderStatus, DelayReason, \
|
| 27 |
ExtraTransactionProcessingType, HotspotAction, TimeoutSummary
|
28 |
ExtraTransactionProcessingType, HotspotAction, TimeoutSummary
|
| - |
|
29 |
from shop2020.thriftpy.payments.ttypes import PaymentException
|
| 28 |
from shop2020.thriftpy.warehouse.ttypes import PurchaseOrder, \
|
30 |
from shop2020.thriftpy.warehouse.ttypes import PurchaseOrder, \
|
| 29 |
LineItem as POLineItem, ScanType
|
31 |
LineItem as POLineItem, ScanType
|
| 30 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
|
32 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
|
| 31 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
33 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
| 32 |
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
|
34 |
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
|
| Line 35... |
Line 37... |
| 35 |
from string import Template
|
37 |
from string import Template
|
| 36 |
from textwrap import dedent
|
38 |
from textwrap import dedent
|
| 37 |
import datetime
|
39 |
import datetime
|
| 38 |
import logging
|
40 |
import logging
|
| 39 |
import os
|
41 |
import os
|
| - |
|
42 |
import sys
|
| 40 |
import sys, traceback
|
43 |
import traceback
|
| 41 |
import time
|
44 |
import time
|
| 42 |
from shop2020.config.client.ConfigClient import ConfigClient
|
- |
|
| 43 |
logging.basicConfig(level=logging.DEBUG)
|
45 |
logging.basicConfig(level=logging.DEBUG)
|
| 44 |
|
46 |
|
| 45 |
|
47 |
|
| 46 |
try:
|
48 |
try:
|
| 47 |
config_client = ConfigClient()
|
49 |
config_client = ConfigClient()
|
| Line 582... |
Line 584... |
| 582 |
logging.info("Accepting order no: " + str(orderId))
|
584 |
logging.info("Accepting order no: " + str(orderId))
|
| 583 |
order = get_order(orderId)
|
585 |
order = get_order(orderId)
|
| 584 |
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]:
|
586 |
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]:
|
| 585 |
if not order.cod:
|
587 |
if not order.cod:
|
| 586 |
if order.transaction.status == TransactionStatus.AUTHORIZED:
|
588 |
if order.transaction.status == TransactionStatus.AUTHORIZED:
|
| 587 |
__capture_txn(order.transaction.id)
|
589 |
__capture_txn(order)
|
| 588 |
order.status = OrderStatus.ACCEPTED
|
590 |
order.status = OrderStatus.ACCEPTED
|
| 589 |
order.statusDescription = "Order Accepted"
|
591 |
order.statusDescription = "Order Accepted"
|
| 590 |
order.accepted_timestamp = datetime.datetime.now()
|
592 |
order.accepted_timestamp = datetime.datetime.now()
|
| 591 |
session.commit()
|
593 |
session.commit()
|
| 592 |
logging.info("Successfully accepted the order no.:" + str(orderId))
|
594 |
logging.info("Successfully accepted the order no.:" + str(orderId))
|
| 593 |
return True
|
595 |
return True
|
| 594 |
else:
|
596 |
else:
|
| 595 |
logging.warning("Accept called for the unacceptable order: " + str(orderId))
|
597 |
logging.warning("Accept called for the unacceptable order: " + str(orderId))
|
| 596 |
return False
|
598 |
return False
|
| 597 |
|
599 |
|
| 598 |
def __capture_txn(txnId):
|
600 |
def __capture_txn(order):
|
| - |
|
601 |
txnId = order.transaction_id
|
| 599 |
logging.info("Capturing payment for merchant txn:" + str(txnId))
|
602 |
logging.info("Capturing payment for merchant txn:" + str(txnId))
|
| - |
|
603 |
try:
|
| 600 |
payment_client = PaymentClient().get_client()
|
604 |
payment_client = PaymentClient().get_client()
|
| 601 |
capture_result = payment_client.capturePayment(txnId)
|
605 |
capture_result = payment_client.capturePayment(txnId)
|
| 602 |
if capture_result:
|
606 |
if capture_result:
|
| 603 |
logging.info("Successfully captured payment for merchant txn:" + str(txnId))
|
607 |
logging.info("Successfully captured payment for merchant txn:" + str(txnId))
|
| 604 |
change_transaction_status(txnId, TransactionStatus.IN_PROCESS, "Payment received")
|
608 |
change_transaction_status(txnId, TransactionStatus.IN_PROCESS, "Payment received")
|
| - |
|
609 |
else:
|
| - |
|
610 |
raise TransactionServiceException(115, "Payment capture failed.")
|
| - |
|
611 |
except PaymentException as e:
|
| - |
|
612 |
if e.error_code == 106:
|
| - |
|
613 |
order.status = OrderStatus.CAPTURE_IN_PROCESS
|
| - |
|
614 |
session.commit()
|
| - |
|
615 |
raise TransactionServiceException(122, "Unable to capture payment due to connection issue.")
|
| 605 |
else:
|
616 |
else:
|
| 606 |
raise TransactionServiceException(115, "Payment capture failed.")
|
617 |
raise TransactionServiceException(115, "Payment capture failed.")
|
| 607 |
|
618 |
|
| 608 |
def add_billing_details(orderId, invoice_number, imeiNumber, itemNumber, billedBy, jacketNumber, billingType, vendorId):
|
619 |
def add_billing_details(orderId, invoice_number, imeiNumber, itemNumber, billedBy, jacketNumber, billingType, vendorId):
|
| 609 |
if jacketNumber is None or jacketNumber <= 0:
|
620 |
if jacketNumber is None or jacketNumber <= 0:
|
| 610 |
raise TransactionServiceException(110, "Invalid jacket number")
|
621 |
raise TransactionServiceException(110, "Invalid jacket number")
|
| 611 |
|
622 |
|