| Line 18... |
Line 18... |
| 18 |
from shop2020.clients.WarehouseClient import WarehouseClient
|
18 |
from shop2020.clients.WarehouseClient import WarehouseClient
|
| 19 |
from shop2020.config.client.ConfigClient import ConfigClient
|
19 |
from shop2020.config.client.ConfigClient import ConfigClient
|
| 20 |
from shop2020.model.v1 import order
|
20 |
from shop2020.model.v1 import order
|
| 21 |
from shop2020.model.v1.order.impl.DataService import Transaction, LineItem, \
|
21 |
from shop2020.model.v1.order.impl.DataService import Transaction, LineItem, \
|
| 22 |
Order, BatchNoGenerator, InvoiceIDGenerator, TransactionRequiringExtraProcessing, \
|
22 |
Order, BatchNoGenerator, InvoiceIDGenerator, TransactionRequiringExtraProcessing, \
|
| 23 |
OrderInventory, Alert
|
23 |
OrderInventory, Alert, PaymentSettlement, EBSSettlementSummary
|
| 24 |
from shop2020.model.v1.order.impl.model.ReturnOrder import ReturnOrder
|
24 |
from shop2020.model.v1.order.impl.model.ReturnOrder import ReturnOrder
|
| 25 |
from shop2020.thriftpy.generic.ttypes import ExceptionType
|
25 |
from shop2020.thriftpy.generic.ttypes import ExceptionType
|
| 26 |
from shop2020.thriftpy.logistics.ttypes import DeliveryType
|
26 |
from shop2020.thriftpy.logistics.ttypes import DeliveryType
|
| 27 |
from shop2020.thriftpy.model.v1.catalog.ttypes import BillingType, \
|
27 |
from shop2020.thriftpy.model.v1.catalog.ttypes import BillingType, \
|
| 28 |
InventoryServiceException
|
28 |
InventoryServiceException
|
| 29 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
29 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
| 30 |
TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
|
30 |
TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
|
| 31 |
HotspotAction, TimeoutSummary
|
31 |
HotspotAction, TimeoutSummary
|
| 32 |
from shop2020.thriftpy.payments.ttypes import PaymentException
|
32 |
from shop2020.thriftpy.payments.ttypes import PaymentException
|
| 33 |
from shop2020.thriftpy.purchase.ttypes import PurchaseOrder, \
|
33 |
from shop2020.thriftpy.purchase.ttypes import PurchaseOrder, LineItem as POLineItem
|
| 34 |
LineItem as POLineItem
|
- |
|
| 35 |
from shop2020.thriftpy.warehouse.ttypes import ScanType, \
|
34 |
from shop2020.thriftpy.warehouse.ttypes import ScanType, WarehouseServiceException
|
| 36 |
WarehouseServiceException
|
- |
|
| 37 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
|
35 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
|
| 38 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
36 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
| 39 |
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
|
37 |
from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
|
| 40 |
from sqlalchemy.sql import func
|
38 |
from sqlalchemy.sql import func
|
| 41 |
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct
|
39 |
from sqlalchemy.sql.expression import and_, or_, desc, not_, distinct
|
| Line 2131... |
Line 2129... |
| 2131 |
if not provider_id or not order_status:
|
2129 |
if not provider_id or not order_status:
|
| 2132 |
raise TransactionServiceException(101, "bad provider id or order status")
|
2130 |
raise TransactionServiceException(101, "bad provider id or order status")
|
| 2133 |
query = Order.query.filter_by(logistics_provider_id = provider_id, status = order_status)
|
2131 |
query = Order.query.filter_by(logistics_provider_id = provider_id, status = order_status)
|
| 2134 |
return query.all()
|
2132 |
return query.all()
|
| 2135 |
|
2133 |
|
| - |
|
2134 |
def get_billed_orders_for_vendor(vendor_id, billing_date_from, billing_date_to):
|
| - |
|
2135 |
query = Order.query.filter_by(vendorId = vendor_id)
|
| - |
|
2136 |
query = query.filter(Order.status != OrderStatus.PAYMENT_PENDING)
|
| - |
|
2137 |
if billing_date_from:
|
| - |
|
2138 |
query = query.filter(Order.billing_timestamp >= billing_date_from)
|
| - |
|
2139 |
|
| - |
|
2140 |
if billing_date_to:
|
| - |
|
2141 |
query = query.filter(Order.billing_timestamp <= billing_date_to)
|
| - |
|
2142 |
|
| - |
|
2143 |
return query.all()
|
| - |
|
2144 |
|
| - |
|
2145 |
def save_bluedart_settlements(map_awb_and_amount):
|
| - |
|
2146 |
payment_client = PaymentClient().get_client()
|
| - |
|
2147 |
|
| - |
|
2148 |
for awb, amount in map_awb_and_amount.iteritems():
|
| - |
|
2149 |
order = Order.get_by(airwaybill_no = awb)
|
| - |
|
2150 |
|
| - |
|
2151 |
payment = payment_client.getSuccessfulPaymentForTxnId(order.transaction_id)
|
| - |
|
2152 |
settlement = PaymentSettlement()
|
| - |
|
2153 |
settlement.paymentId = payment.paymentId
|
| - |
|
2154 |
settlement.paymentGatewayId = payment.gatewayId
|
| - |
|
2155 |
settlement.netCollection = amount
|
| - |
|
2156 |
session.commit()
|
| - |
|
2157 |
|
| - |
|
2158 |
def save_payment_settlements(settlementDate, paymentGatewayId, paymentId, serviceTax, otherCharges, netCollection):
|
| - |
|
2159 |
|
| - |
|
2160 |
settlement = PaymentSettlement()
|
| - |
|
2161 |
settlement.settlementDate = settlementDate
|
| - |
|
2162 |
settlement.paymentGatewayId = paymentGatewayId
|
| - |
|
2163 |
settlement.paymentId = paymentId
|
| - |
|
2164 |
settlement.serviceTax = serviceTax
|
| - |
|
2165 |
settlement.otherCharges = otherCharges
|
| - |
|
2166 |
settlement.netCollection = netCollection
|
| - |
|
2167 |
session.commit()
|
| - |
|
2168 |
|
| - |
|
2169 |
def get_settlement_for_paymentId(payment_id):
|
| - |
|
2170 |
payment_settlement = PaymentSettlement.get_by(paymentId = payment_id)
|
| - |
|
2171 |
|
| - |
|
2172 |
return payment_settlement
|
| - |
|
2173 |
|
| - |
|
2174 |
def save_ebs_settlement_summary(settlement_id, settlement_date, transaction_date_from, transaction_date_to, amount):
|
| - |
|
2175 |
summary = EBSSettlementSummary()
|
| - |
|
2176 |
summary.settlementId = settlement_id
|
| - |
|
2177 |
summary.settlementDate = settlement_date
|
| - |
|
2178 |
summary.transactionDateFrom = transaction_date_from
|
| - |
|
2179 |
summary.transactionDateTo = transaction_date_to
|
| - |
|
2180 |
summary.amount = amount
|
| - |
|
2181 |
summary.detailsUploaded = False
|
| - |
|
2182 |
session.commit()
|
| - |
|
2183 |
|
| - |
|
2184 |
def get_ebs_settlement_summaries():
|
| - |
|
2185 |
summaries = EBSSettlementSummary.query.filter_by(detailsUploaded = False).order_by(EBSSettlementSummary.transactionDateFrom).all()
|
| - |
|
2186 |
summary_map = {}
|
| - |
|
2187 |
|
| - |
|
2188 |
for summary in summaries:
|
| - |
|
2189 |
transactionDateFrom = str(summary.transactionDateFrom.year) + '-' + str(summary.transactionDateFrom.month) + '-' + str(summary.transactionDateFrom.day)
|
| - |
|
2190 |
transactionDateTo = str(summary.transactionDateTo.year) + '-' + str(summary.transactionDateTo.month) + '-' + str(summary.transactionDateTo.day)
|
| - |
|
2191 |
|
| - |
|
2192 |
summary_map[summary.settlementId] = "%s to %s" %(transactionDateFrom, transactionDateTo)
|
| - |
|
2193 |
|
| - |
|
2194 |
return summary_map
|
| - |
|
2195 |
|
| - |
|
2196 |
def get_ebs_settlement_date(settlement_id):
|
| - |
|
2197 |
summary = EBSSettlementSummary.get_by(settlementId = settlement_id)
|
| - |
|
2198 |
|
| - |
|
2199 |
if summary:
|
| - |
|
2200 |
return summary.settlementDate
|
| - |
|
2201 |
|
| - |
|
2202 |
def mark_ebs_settlement_uploaded(settlement_id):
|
| - |
|
2203 |
summary = EBSSettlementSummary.get_by(settlementId = settlement_id)
|
| - |
|
2204 |
|
| - |
|
2205 |
if summary:
|
| - |
|
2206 |
summary.detailsUploaded = True
|
| - |
|
2207 |
session.commit()
|
| - |
|
2208 |
|
| 2136 |
def close_session():
|
2209 |
def close_session():
|
| 2137 |
if session.is_active:
|
2210 |
if session.is_active:
|
| 2138 |
print "session is active. closing it."
|
2211 |
print "session is active. closing it."
|
| 2139 |
session.close()
|
2212 |
session.close()
|
| 2140 |
|
2213 |
|