Subversion Repositories SmartDukaan

Rev

Rev 21134 | Blame | Compare with Previous | Last modification | View Log | RSS feed

'''
Created on 29-Mar-2010

@author: ashish
'''

import datetime

from shop2020.config.client.ConfigClient import ConfigClient

from shop2020.thriftpy.model.v1.order.ttypes import Transaction as T_Transaction, \
    LineItem as T_LineItem, Order as T_Order, Alert as T_Alert, OrderStatus, \
    DelayReason, PaymentSettlement as T_PaymentSettlement, \
    CODVerificationAgent as T_CODVerificationAgent, Attribute as T_Attribute, \
    EmiScheme as T_EmiScheme, RechargeTransaction as T_rechargeTransaction, \
    FRC as T_FRC, HotspotStore as T_HotSpotStore, SourceDetail as T_SourceDetail, \
    AmazonOrder as T_AmazonOrder, StoreOrderDetail as T_StoreOrderDetail, \
    StoreOrderCollection as T_StoreOrderCollection, \
    HotspotServiceMatrix as T_HotspotServiceMatrix, EbayOrder as T_EbayOrder, \
    AmazonFbaSalesSnapshot as T_AmazonFbaSalesSnapshot, \
    SnapdealOrder as T_SnapdealOrder, FlipkartOrder as flipkartOrder, \
    AmazonFbaOrderReturns as amazonFbaOrderReturn, \
    FlipkartAdvantageOrder as flipkartAdvantageOrder, HsOrder as homeshopOrder, \
    ReturnTransaction as RTransaction, ReturnOrderInfo as returnOrderInfo, \
    ReturnTransactionStatus, ReturnTxnResolutionStatus, \
    ReturnPickupRequest as RPickupRequest, ReturnTxnPickupStatus, \
    Creditor as TCreditor, CreditHistory as TCreditHistory, \
    UserSanction as TUserSanction, CreditTxnType, LoanHistory as TLoanHistory, \
    PaginatedCreditHistory as TPaginatedCreditHistory, \
    PaginatedLoanHistory as TPaginatedLoanHistory, \
    PaginatedUserSanction as TPaginatedUserSanction, \
    ShipmentLogisticsCostDetail as TShipmentLogisticsCostDetail, \
    OutstandingPayments as TOutstandingPayments, WarehouseAddress, Pmsa as TPmsa
from shop2020.utils.Utils import to_java_date


cutoff_date = ConfigClient().get_property("warehouse_company_cutoff_date")
cutoff_date = datetime.datetime.strptime(cutoff_date,'%Y-%m-%d')

def to_t_transaction(transaction):
    t_transaction = T_Transaction()
    t_transaction.id = transaction.id
    t_transaction.createdOn = to_java_date(transaction.createdOn)
    t_transaction.transactionStatus = transaction.status
    t_transaction.statusDescription = transaction.status_message
    t_transaction.customer_id = transaction.customer_id
    t_transaction.shoppingCartid = transaction.shopping_cart_id
    t_transaction.coupon_code = transaction.coupon_code
    t_transaction.sessionSource = transaction.session_source
    t_transaction.sessionStartTime = to_java_date(transaction.session_start_time)
    t_transaction.firstSource = transaction.first_source
    t_transaction.firstSourceTime = to_java_date(transaction.first_source_start_time)
    t_transaction.totalShippingCost = transaction.totalShippingCost
    t_transaction.payment_option = transaction.payment_option
    t_transaction.orders = []
    #populate orders
    for order in transaction.orders:
        t_order = to_t_order(order)
        t_transaction.orders.append(t_order)
    return t_transaction

def to_t_order(order):
    t_order = T_Order()
    t_order.id = order.id
    t_order.warehouse_id = order.warehouse_id
    t_order.logistics_provider_id = order.logistics_provider_id
    if order.doa_logistics_provider_id is not None:
        t_order.doa_logistics_provider_id = order.doa_logistics_provider_id
    t_order.airwaybill_no = order.airwaybill_no
    t_order.tracking_id = order.tracking_id
    t_order.expected_delivery_time = to_java_date(order.expected_delivery_time)
    t_order.promised_delivery_time = to_java_date(order.promised_delivery_time)
    t_order.expected_shipping_time = to_java_date(order.expected_shipping_time)
    t_order.promised_shipping_time = to_java_date(order.promised_shipping_time)
    t_order.courier_delivery_time = to_java_date(order.courier_delivery_time)
    t_order.customer_id = order.customer_id
    t_order.customer_name = order.customer_name
    t_order.customer_mobilenumber = order.customer_mobilenumber
    t_order.customer_pincode = order.customer_pincode
    t_order.customer_address1 = order.customer_address1
    t_order.customer_address2 = order.customer_address2
    t_order.customer_city = order.customer_city
    t_order.customer_state = order.customer_state
    t_order.customer_email = order.customer_email    
    t_order.status = order.status 
    t_order.statusDescription = order.statusDescription
    t_order.total_amount = order.total_amount
    t_order.gvAmount = order.gvAmount
    t_order.total_weight = order.total_weight
    t_order.created_timestamp = to_java_date(order.created_timestamp)
    t_order.invoice_number = order.invoice_number
    t_order.seller_id = order.seller_id
    t_order.warehouse_address_id = order.warehouse_address_id
    t_order.billed_by = order.billed_by
    t_order.accepted_timestamp = to_java_date(order.accepted_timestamp)
    t_order.billing_timestamp = to_java_date(order.billing_timestamp)
    t_order.shipping_timestamp = to_java_date(order.shipping_timestamp)
    t_order.delivery_timestamp = to_java_date(order.delivery_timestamp)
    t_order.outofstock_timestamp = to_java_date(order.outofstock_timestamp)
    t_order.verification_timestamp = to_java_date(order.verification_timestamp)
    t_order.jacket_number = order.jacket_number
    t_order.receiver = order.receiver
    t_order.batchNo = order.batchNo
    t_order.serialNo = order.serialNo
    t_order.doaFlag = order.doaFlag
    t_order.pickupRequestNo = order.pickupRequestNo
    t_order.cod = order.cod
    t_order.originalOrderId = order.originalOrderId
    if order.delay_reason:
        t_order.delayReason = DelayReason._NAMES_TO_VALUES[order.delay_reason]
    t_order.delayReasonText = order.delayReasonText
    t_order.transactionId = order.transaction_id
    t_order.lineitems = []
    for lineitem in order.lineitems:
        t_lineitem = to_t_lineitem(lineitem)
        t_order.lineitems.append(t_lineitem)
    if order.reship_timestamp:
        t_order.reship_timestamp = to_java_date(order.reship_timestamp)
    if order.refund_timestamp:
        t_order.refund_timestamp = to_java_date(order.refund_timestamp)
    if order.doa_auth_timestamp:
        t_order.doa_auth_timestamp = to_java_date(order.doa_auth_timestamp)
    if order.new_order_id:
        t_order.new_order_id = order.new_order_id
    t_order.pickup_timestamp = to_java_date(order.pickup_timestamp)
    t_order.previousStatus = order.previousStatus
    t_order.vendorId = order.vendorId
    t_order.refundReason = order.refund_reason
    t_order.fulfilmentWarehouseId = order.fulfilmentWarehouseId
    t_order.vendorPaid = order.vendor_paid
    if order.purchase_order_id:
        t_order.purchaseOrderId = order.purchase_order_id
    if order.received_return_timestamp:
        t_order.received_return_timestamp = to_java_date(order.received_return_timestamp)
    if order.first_dlvyatmp_timestamp:
        t_order.first_attempt_timestamp = to_java_date(order.first_dlvyatmp_timestamp)
    t_order.orderType = order.orderType
    t_order.pickupStoreId = order.pickupStoreId
    t_order.logisticsCod = not order.pickupStoreId and order.cod
    t_order.otg = order.otg
    t_order.insurer = order.insurer
    t_order.insuranceAmount = order.insuranceAmount
    t_order.freebieItemId = order.freebieItemId
    t_order.source = order.source
    t_order.storeId = order.storeId
    t_order.advanceAmount = order.advanceAmount
    t_order.productCondition = order.productCondition
    t_order.dataProtectionInsurer = order.dataProtectionInsurer
    t_order.dataProtectionAmount = order.dataProtectionAmount
    t_order.taxType = order.taxType
    if order.logisticsTransactionId:
        t_order.logisticsTransactionId = order.logisticsTransactionId
    t_order.shippingCost = order.shippingCost
    t_order.shippingRefund = order.shippingRefund
    t_order.codCharges = order.codCharges
    t_order.wallet_amount = order.wallet_amount
    t_order.net_payable_amount = order.net_payable_amount
    return t_order

def to_t_lineitem(lineitem):
    t_lineitem = T_LineItem()
    t_lineitem.id = lineitem.id
    t_lineitem.item_id = lineitem.item_id
    t_lineitem.productGroup = lineitem.productGroup
    t_lineitem.brand = lineitem.brand
    t_lineitem.model_number = lineitem.model_number
    t_lineitem.color = lineitem.color
    t_lineitem.model_name = lineitem.model_name
    t_lineitem.extra_info = lineitem.extra_info
    t_lineitem.unit_weight = lineitem.unit_weight
    t_lineitem.unit_price = lineitem.unit_price
    t_lineitem.total_price = lineitem.total_price
    t_lineitem.transfer_price = lineitem.transfer_price
    t_lineitem.nlc = lineitem.nlc
    t_lineitem.total_weight = lineitem.total_weight 
    t_lineitem.quantity = lineitem.quantity
    t_lineitem.item_number = lineitem.item_number
    t_lineitem.serial_number = lineitem.serial_number
    t_lineitem.dealText = lineitem.dealText
    t_lineitem.warrantry_expiry_timestamp = to_java_date(lineitem.warranty_expiry_timestamp)
    t_lineitem.vatRate = lineitem.vatRate
    t_lineitem.mrp = lineitem.mrp
    t_lineitem.logisticsCost = lineitem.logisticsCost
    t_lineitem.codCollectionCharges = lineitem.codCollectionCharges
    t_lineitem.returnQty = lineitem.returnQty
    t_lineitem.damaged_expiry_timestamp = to_java_date(lineitem.damaged_expiry_timestamp)
    t_lineitem.igstRate = lineitem.igstRate
    t_lineitem.cgstRate = lineitem.cgstRate
    t_lineitem.sgstRate = lineitem.sgstRate
    t_lineitem.hsnCode = lineitem.hsnCode
    return t_lineitem

def to_t_alert(alert):
    t_alert = T_Alert()
    t_alert.id = alert.id
    t_alert.description = alert.description
    try:
        t_alert.timestamp = to_java_date(alert.timestamp)
    except:
        pass
    t_alert.type = alert.type
    t_alert.status = alert.status
    return t_alert

def to_t_payment_settlement(payment_settlement):
    t_payment_settlement = T_PaymentSettlement()
    
    if payment_settlement:
        t_payment_settlement.referenceId = payment_settlement.referenceId
        t_payment_settlement.paymentGatewayId = payment_settlement.paymentGatewayId
        t_payment_settlement.settlementDate = to_java_date(payment_settlement.settlementDate)
        t_payment_settlement.serviceTax = payment_settlement.serviceTax
        t_payment_settlement.otherCharges = payment_settlement.otherCharges
        t_payment_settlement.netCollection = payment_settlement.netCollection
    return t_payment_settlement

def to_t_verification_agent(codVerificationAgent):
    t_verification_agent = T_CODVerificationAgent()
    
    if codVerificationAgent:
        t_verification_agent.orderId = codVerificationAgent.orderId
        t_verification_agent.agentEmailId = codVerificationAgent.verificationAgent
    return t_verification_agent    

def to_t_attribute(attribute):
    t_attribute = T_Attribute() 
    if attribute:
        t_attribute.name = attribute.name
        t_attribute.value = attribute.value
    return t_attribute

def to_t_warehouse_address(warehouse_address_master):
    wha = WarehouseAddress() 
    if warehouse_address_master:
        wha.address = warehouse_address_master.address
        wha.id = warehouse_address_master.id
        wha.pin = warehouse_address_master.pin
        wha.state_id = warehouse_address_master.state_id
        wha.contact_number = warehouse_address_master.contact_number
        wha.contact_person = warehouse_address_master.contact_person
    return wha
def to_t_emi_scheme(emi_scheme):
    t_emi_scheme = T_EmiScheme()
    if emi_scheme:
        t_emi_scheme.id = emi_scheme.id
        t_emi_scheme.bankId = emi_scheme.bankId
        t_emi_scheme.bankName = emi_scheme.bankName
        t_emi_scheme.gatewayId = emi_scheme.gatewayId
        t_emi_scheme.tenure = emi_scheme.tenure
        t_emi_scheme.tenureDescription = emi_scheme.tenureDescription
        t_emi_scheme.minAmount = emi_scheme.minAmount
        t_emi_scheme.chargeType = emi_scheme.chargeType
        t_emi_scheme.chargeValue = emi_scheme.chargeValue
        t_emi_scheme.interestRate = emi_scheme.interestRate
    return t_emi_scheme

def to_t_rechargeTransaction(rechargeTransaction):
    t_recharge = T_rechargeTransaction()
    if rechargeTransaction:
        t_recharge.id = rechargeTransaction.id
        t_recharge.amount = rechargeTransaction.amount 
        t_recharge.circleId = rechargeTransaction.circleId
        t_recharge.operatorId = rechargeTransaction.operatorId
        t_recharge.plan = rechargeTransaction.plan 
        t_recharge.deviceNum = rechargeTransaction.deviceNum
        t_recharge.deviceType = rechargeTransaction.deviceType
        t_recharge.discount = rechargeTransaction.discount 
        t_recharge.email = rechargeTransaction.email
        t_recharge.name = rechargeTransaction.name
        t_recharge.cafNum = rechargeTransaction.cafNum
        t_recharge.simNum = rechargeTransaction.simNum
        t_recharge.isFrc = rechargeTransaction.isFrc
        t_recharge.status = rechargeTransaction.status
        t_recharge.storeId = rechargeTransaction.storeId
        t_recharge.alternateNum = rechargeTransaction.alternateNumber
        t_recharge.transactionTime = to_java_date(rechargeTransaction.transactionTime)
        t_recharge.description = rechargeTransaction.description
        t_recharge.payMethod = rechargeTransaction.payMethod
        t_recharge.paymentAmount = rechargeTransaction.paymentAmount
        t_recharge.spiceTID = rechargeTransaction.spiceTID
        t_recharge.providerTID = rechargeTransaction.providerTID
        t_recharge.aggTID = rechargeTransaction.aggTID
    return t_recharge

def to_t_frc(frc):
    t_frc = T_FRC()
    if frc:
        t_frc.id = frc.id
        t_frc.operatorId =frc.operatorId
        t_frc.circleId = frc.circleId
        t_frc.denomination = frc.denomination
        t_frc.maxDiscount = frc.maxDiscount
    return t_frc

def to_t_hotspot(hotspot):
    t_hotspot = T_HotSpotStore();
    if hotspot:
        t_hotspot.id = hotspot.id 
        t_hotspot.hotspotId = hotspot.hotspotId
        t_hotspot.companyId = hotspot.companyId
        t_hotspot.name = hotspot.name
        t_hotspot.city = hotspot.city
        t_hotspot.collectedAmount = hotspot.collectedAmount
        t_hotspot.availableLimit = hotspot.availableLimit
        t_hotspot.creditLimit = hotspot.creditLimit
        t_hotspot.salt = hotspot.salt
        t_hotspot.password = hotspot.password
        t_hotspot.isActive = hotspot.isActive
        t_hotspot.circleId = hotspot.circleId
        t_hotspot.email = hotspot.email
        t_hotspot.line1 = hotspot.line1
        t_hotspot.line2 = hotspot.line2
        t_hotspot.state = hotspot.state
        t_hotspot.pin = hotspot.pin
        t_hotspot.phone = hotspot.phone
        t_hotspot.approvalEmail = hotspot.approvalEmail


    return t_hotspot

def to_t_sourcedetail(detail):
    t_sourcedetail = T_SourceDetail()
    if detail:
        t_sourcedetail.id = detail.id
        t_sourcedetail.name = detail.name
        t_sourcedetail.email = detail.email
        t_sourcedetail.tinNumber = detail.tinNumber
        t_sourcedetail.lastUpdatedOn = to_java_date(detail.lastUpdatedOn)
    return t_sourcedetail

def to_t_amazonorder(AmazonOrder):
    t_amazonorder = T_AmazonOrder()
    t_amazonorder.orderId=AmazonOrder.orderId
    t_amazonorder.amazonOrderCode=AmazonOrder.amazonOrderCode
    t_amazonorder.amazonOrderItemCode=AmazonOrder.amazonOrderItemCode
    t_amazonorder.transactionId=AmazonOrder.transactionId
    t_amazonorder.item_id=AmazonOrder.item_id
    t_amazonorder.status=AmazonOrder.status
    return t_amazonorder

def to_t_storeOrderDetail(storeOrderDetail):
    t_storeOrderDetail = T_StoreOrderDetail()
    if storeOrderDetail:
        t_storeOrderDetail.orderId = storeOrderDetail.orderId
        t_storeOrderDetail.storeId = storeOrderDetail.storeId
        t_storeOrderDetail.advanceAmount = storeOrderDetail.advanceAmount
        t_storeOrderDetail.cashAmount = storeOrderDetail.cashAmount
        t_storeOrderDetail.cardAmount = storeOrderDetail.cardAmount
        t_storeOrderDetail.payStatus = storeOrderDetail.payStatus
        t_storeOrderDetail.edcBank = storeOrderDetail.edcBank
        t_storeOrderDetail.cashRefundAmount = storeOrderDetail.cashRefundAmount
        t_storeOrderDetail.cardRefundAmount = storeOrderDetail.cardRefundAmount
        t_storeOrderDetail.approvalCode = storeOrderDetail.approvalCode
        t_storeOrderDetail.cardType = storeOrderDetail.cardType
    return t_storeOrderDetail

def to_t_storeOrderCollection(storeOrderCollection):
    t_storeOrderCollection = T_StoreOrderCollection()
    if storeOrderCollection:
        t_storeOrderCollection.hotspotId = storeOrderCollection.hotspotId
        t_storeOrderCollection.orderId = storeOrderCollection.orderId
        t_storeOrderCollection.collectionType = storeOrderCollection.collectionType
        t_storeOrderCollection.productName = storeOrderCollection.productName
        t_storeOrderCollection.advanceAmount = storeOrderCollection.advanceAmount
        t_storeOrderCollection.cash = storeOrderCollection.cash
        t_storeOrderCollection.card = storeOrderCollection.card
        t_storeOrderCollection.addedAt = to_java_date(storeOrderCollection.addedAt)
        t_storeOrderCollection.pushedAt = to_java_date(storeOrderCollection.pushedAt)
        t_storeOrderCollection.pushedToOcr = storeOrderCollection.pushedToOcr
    return t_storeOrderCollection

def to_t_hotspotServiceMatrix(hotspotServiceMatrix):
    t_hotspotServiceMatrix = T_HotspotServiceMatrix()
    if hotspotServiceMatrix:
        t_hotspotServiceMatrix.storeId = hotspotServiceMatrix.storeId
        t_hotspotServiceMatrix.hotspotId = hotspotServiceMatrix.hotspotId
        t_hotspotServiceMatrix.rechargeService = hotspotServiceMatrix.rechargeService
        t_hotspotServiceMatrix.storeWebsiteService = hotspotServiceMatrix.storeWebsiteService
        t_hotspotServiceMatrix.pickupFromStoreService = hotspotServiceMatrix.pickupFromStoreService
    return t_hotspotServiceMatrix

def to_t_ebayOrder(ebayOrder):
    t_ebayOrder = T_EbayOrder()
    t_ebayOrder.orderId = ebayOrder.orderId
    t_ebayOrder.salesRecordNumber = ebayOrder.salesRecordNumber
    t_ebayOrder.paisaPayId = ebayOrder.paisaPayId
    t_ebayOrder.ebayListingId = ebayOrder.ebayListingId
    t_ebayOrder.subsidyAmount = ebayOrder.subsidyAmount
    t_ebayOrder.ebayTxnDate = to_java_date(ebayOrder.ebayTxnDate)
    t_ebayOrder.transactionId = ebayOrder.transactionId
    t_ebayOrder.listingName = ebayOrder.listingName
    t_ebayOrder.listingPrice = ebayOrder.listingPrice
    t_ebayOrder.bluedartPaisaPayRef = ebayOrder.bluedartPaisaPayRef
    return t_ebayOrder 

def to_t_snapdealOrder(snapdealOrder):
    t_snapdealOrder = T_SnapdealOrder()
    t_snapdealOrder.orderId = snapdealOrder.orderId
    t_snapdealOrder.subOrderId = snapdealOrder.subOrderId
    t_snapdealOrder.referenceCode = snapdealOrder.referenceCode
    t_snapdealOrder.snapdealTxnDate = to_java_date(snapdealOrder.referenceCode)
    t_snapdealOrder.productName = snapdealOrder.productName
    t_snapdealOrder.listingPrice = snapdealOrder.listingPrice
    t_snapdealOrder.maxNlc = snapdealOrder.maxNlc
    return t_snapdealOrder 
    
def to_t_amazonFbaSalesSnapshot(amazonFbaSalesSnapshot):
    t_amazonFbaSalesSnapshot = T_AmazonFbaSalesSnapshot()
    if amazonFbaSalesSnapshot:
        t_amazonFbaSalesSnapshot.dateOfSale = to_java_date(datetime.datetime.combine(amazonFbaSalesSnapshot.dateOfSale,datetime.time(0,0)))
        t_amazonFbaSalesSnapshot.item_id    = amazonFbaSalesSnapshot.item_id 
        t_amazonFbaSalesSnapshot.totalOrderCount = amazonFbaSalesSnapshot.totalOrderCount 
        t_amazonFbaSalesSnapshot.amazonFbaInventory = amazonFbaSalesSnapshot.amazonFbaInventory
        t_amazonFbaSalesSnapshot.isOutOfStock = amazonFbaSalesSnapshot.isOutOfStock
        t_amazonFbaSalesSnapshot.salePrice = amazonFbaSalesSnapshot.salePrice
        t_amazonFbaSalesSnapshot.ourPrice = amazonFbaSalesSnapshot.ourPrice
        if amazonFbaSalesSnapshot.minFbaPrice is not None:
            t_amazonFbaSalesSnapshot.minFbaPrice = amazonFbaSalesSnapshot.minFbaPrice
        if amazonFbaSalesSnapshot.minMfnPrice is not None:    
            t_amazonFbaSalesSnapshot.minMfnPrice = amazonFbaSalesSnapshot.minMfnPrice
        t_amazonFbaSalesSnapshot.totalSale = amazonFbaSalesSnapshot.totalSale
        t_amazonFbaSalesSnapshot.promotionSale = amazonFbaSalesSnapshot.promotionSale    
        t_amazonFbaSalesSnapshot.promotionOrderCount = amazonFbaSalesSnapshot.promotionOrderCount
        t_amazonFbaSalesSnapshot.ourPriceSnapshotDate = to_java_date(amazonFbaSalesSnapshot.ourPriceSnapshotDate)
        t_amazonFbaSalesSnapshot.salePriceSnapshotDate = to_java_date(amazonFbaSalesSnapshot.salePriceSnapshotDate)
        t_amazonFbaSalesSnapshot.minFbaPriceSnapshotDate = to_java_date(amazonFbaSalesSnapshot.minFbaPriceSnapshotDate)
        t_amazonFbaSalesSnapshot.minMfnPriceSnapshotDate = to_java_date(amazonFbaSalesSnapshot.minMfnPriceSnapshotDate)
        t_amazonFbaSalesSnapshot.fcLocation = amazonFbaSalesSnapshot.fcLocation
    return t_amazonFbaSalesSnapshot

def to_t_flipkartOrder(flipkartorder):
    order = flipkartOrder()
    if flipkartorder:
        order.emiFee = flipkartorder.emiFee
        order.orderId = flipkartorder.orderId
        order.octroiFee = flipkartorder.octroiFee
        order.flipkartOrderId = flipkartorder.flipkartOrderId
        order.flipkartSubOrderId = flipkartorder.flipkartSubOrderId
        order.flipkartTxnDate = to_java_date(flipkartorder.flipkartTxnDate)
        order.shippingPrice = flipkartorder.shippingPrice
        order.maxNlc = flipkartorder.maxNlc
    return order

def to_t_amazonFbaOrderReturn(amazonfbaOrderReturn):
    orderReturn = amazonFbaOrderReturn()
    if amazonfbaOrderReturn:
        orderReturn.amazonOrderId = amazonfbaOrderReturn.amazonOrderId
        orderReturn.insertionTimestamp = to_java_date(amazonfbaOrderReturn.insertionTimestamp)
        orderReturn.sku = amazonfbaOrderReturn.sku
        orderReturn.creationTimestamp = to_java_date(amazonfbaOrderReturn.creationTimestamp)
        orderReturn.shippedQuantity = amazonfbaOrderReturn.shippedQuantity
        orderReturn.sellableReturnQuantity = amazonfbaOrderReturn.sellableReturnQuantity
        orderReturn.nonSellableReturnQuantity = amazonfbaOrderReturn.nonSellableReturnQuantity
    return orderReturn
        
def to_t_flipkartAdvantageOrder(faOrder):
    fa_Order = flipkartAdvantageOrder()
    if faOrder:
        fa_Order.fkOrderId = faOrder.fkOrderId
        fa_Order.fkOrderItemId = faOrder.fkOrderItemId
        fa_Order.sku = faOrder.sku
        fa_Order.creationTimestamp = to_java_date(faOrder.creationTimestamp)
        fa_Order.customerName = faOrder.customerName
        fa_Order.customerAddress = faOrder.customerAddress
        fa_Order.pincode = faOrder.pincode
        fa_Order.customerCity = faOrder.customerCity
        fa_Order.customerState = faOrder.customerState
        fa_Order.customerPhone = faOrder.customerPhone
        fa_Order.status = faOrder.status
        fa_Order.quantity = faOrder.quantity
        fa_Order.totalPrice = faOrder.totalPrice
        fa_Order.listPrice = faOrder.listPrice
        fa_Order.modifiedDate = to_java_date(faOrder.modifiedDate)
        fa_Order.listingId = faOrder.listingId
        fa_Order.cancelReason = faOrder.cancelReason
        fa_Order.returnReason = faOrder.returnReason
        fa_Order.freebieItemId = faOrder.freebieItemId
        fa_Order.productTitle = faOrder.productTitle
        
    return fa_Order

def to_t_hsOrder(hsOrder):
    hs_Order = homeshopOrder()
    hs_Order.orderId = hsOrder.orderId
    hs_Order.catalogueName = hsOrder.catalogueName
    hs_Order.courierName = hsOrder.courierName
    hs_Order.hsItemId = hsOrder.hsItemId
    hs_Order.hsOrderDate = to_java_date(hsOrder.hsOrderDate)
    hs_Order.hsOrderNo = hsOrder.hsOrderNo
    hs_Order.hsProductId = hsOrder.hsProductId
    hs_Order.hsSubOrderNo = hsOrder.hsSubOrderNo
    hs_Order.paymentMode = hsOrder.paymentMode
    hs_Order.sellerSku = hsOrder.sellerSku
    hs_Order.slaDays = hsOrder.slaDays
    hs_Order.shippingName = hsOrder.shippingName
    return hs_Order 


def to_t_returnTransaction(returnTransaction):
    rTransaction = RTransaction()
    rTransaction.id = returnTransaction.id
    if returnTransaction.status:
        rTransaction.status = ReturnTransactionStatus._NAMES_TO_VALUES[returnTransaction.status]
    rTransaction.customer_email = returnTransaction.customer_email
    rTransaction.customer_name = returnTransaction.customer_name
    rTransaction.customer_id = returnTransaction.customer_id
    rTransaction.address_id = returnTransaction.address_id
    rTransaction.ticketId = returnTransaction.ticketId
    rTransaction.createdAt = to_java_date(returnTransaction.createdAt)
    if returnTransaction.processedAt:
        rTransaction.processedAt = to_java_date(returnTransaction.processedAt)
    if returnTransaction.authorizedAt:
        rTransaction.authorizedAt = to_java_date(returnTransaction.authorizedAt)
    if returnTransaction.closedAt:
        rTransaction.closedAt = to_java_date(returnTransaction.closedAt)
    if returnTransaction.customerAddress:
        rTransaction.customerAddress = returnTransaction.customerAddress
    if returnTransaction.pincode:
        rTransaction.pincode = returnTransaction.pincode
    if returnTransaction.customerCity:
        rTransaction.customerCity = returnTransaction.customerCity
    if returnTransaction.customerState:
        rTransaction.customerState = returnTransaction.customerState
    if returnTransaction.customerPhone:
        rTransaction.customerPhone = returnTransaction.customerPhone
    rTransaction.returnOrders = []
    
    for returnOrder in returnTransaction.returnOrders:
        rTransaction.returnOrders.append(to_t_returnOrderInfo(returnOrder))
    return rTransaction

def to_t_returnOrderInfo(returnorderInfo):
    print returnorderInfo
    return_OrderInfo = returnOrderInfo()
    if returnorderInfo is None:
        return return_OrderInfo
    return_OrderInfo.id = returnorderInfo.id
    return_OrderInfo.returnTransactionId = returnorderInfo.returnTransaction_id
    return_OrderInfo.masterOrderId = returnorderInfo.masterOrderId
    return_OrderInfo.orderId = returnorderInfo.orderId
    return_OrderInfo.lineItemId = returnorderInfo.lineItemId
    return_OrderInfo.logisticsRequestId = returnorderInfo.logisticsRequestId
    return_OrderInfo.returnQuantity = returnorderInfo.returnQuantity
    return_OrderInfo.receivedQuantity = returnorderInfo.receivedQuantity
    return_OrderInfo.createdAt = to_java_date(returnorderInfo.createdAt)
    if returnorderInfo.processedAt:
        return_OrderInfo.processedAt = to_java_date(returnorderInfo.processedAt)
    return_OrderInfo.returnStatus = returnorderInfo.returnStatus
    if returnorderInfo.reshippedAt:
        return_OrderInfo.reshippedAt = to_java_date(returnorderInfo.reshippedAt)
    if returnorderInfo.receivedAt:
        return_OrderInfo.receivedAt = to_java_date(returnorderInfo.receivedAt)
    if returnorderInfo.refundReason:
        return_OrderInfo.refundReason = returnorderInfo.refundReason
    if returnorderInfo.refundedBy:
        return_OrderInfo.refundedBy = returnorderInfo.refundedBy
    if returnorderInfo.refundedAt:
        return_OrderInfo.refundedAt = to_java_date(returnorderInfo.refundedAt)
    return_OrderInfo.lineitem = to_t_lineitem(returnorderInfo.lineitem)
    if returnorderInfo.logisticsRequestId:
        return_OrderInfo.returnPickUpRequest = to_t_rPickupRequest(returnorderInfo.returnPickUpRequest)
    return_OrderInfo.warehouse_id = returnorderInfo.warehouse_id
    if returnorderInfo.refundAmount:
        return_OrderInfo.refundAmount = returnorderInfo.refundAmount
    return_OrderInfo.refundType = returnorderInfo.refundType
    return_OrderInfo.refundDescription = returnorderInfo.refundDescription
    return_OrderInfo.shippingType = returnorderInfo.shippingType
    return_OrderInfo.replacementOrderId = returnorderInfo.replacementOrderId
    return_OrderInfo.receivedReturnType = returnorderInfo.receivedReturnType
    return_OrderInfo.freebieItemId = returnorderInfo.freebieItemId
    return_OrderInfo.returnAction = returnorderInfo.returnAction
    return_OrderInfo.returnPickupType = returnorderInfo.returnPickupType
    if returnorderInfo.returnTxnResolutionStatus:
        return_OrderInfo.returnTxnResolutionStatus = ReturnTxnResolutionStatus._NAMES_TO_VALUES[returnorderInfo.returnTxnResolutionStatus]
    return return_OrderInfo

def to_t_rPickupRequest(returnPickupRequest):
    rPickupRequest = RPickupRequest()
    rPickupRequest.id = returnPickupRequest.id
    rPickupRequest.logisticsProviderId = returnPickupRequest.logisticsProviderId
    rPickupRequest.pickupRequestNo = returnPickupRequest.pickupRequestNo
    if returnPickupRequest.confirmedAt:
        rPickupRequest.confirmedAt = to_java_date(returnPickupRequest.confirmedAt)
    if returnPickupRequest.promised_pickup_timestamp:
        rPickupRequest.promised_pickup_timestamp = to_java_date(returnPickupRequest.promised_pickup_timestamp)
    if returnPickupRequest.pickedUpAt:
        rPickupRequest.pickedUpAt = to_java_date(returnPickupRequest.pickedUpAt)
    rPickupRequest.pickupStatus = ReturnTxnPickupStatus._NAMES_TO_VALUES[returnPickupRequest.pickupStatus]
    return rPickupRequest

def to_t_Creditor(creditor):
    t_Creditor = TCreditor()
    t_Creditor.id = creditor.id
    t_Creditor.created = to_java_date(creditor.created)
    t_Creditor.name = creditor.name
    t_Creditor.updated = to_java_date(creditor.updated)
    t_Creditor.active = creditor.active
    return t_Creditor

def to_t_CreditHistory(creditHistory):
    t_CreditHistory = TCreditHistory()
    t_CreditHistory.id = creditHistory.id
    t_CreditHistory.user_id = creditHistory.user_id
    t_CreditHistory.creditor_id = creditHistory.creditor_id
    t_CreditHistory.payment_id = creditHistory.payment_id
    t_CreditHistory.amount = creditHistory.amount
    if creditHistory.credit_type:
        t_CreditHistory.credit_type = CreditTxnType._NAMES_TO_VALUES[creditHistory.credit_type]
    t_CreditHistory.shipping_id = creditHistory.shipping_id
    t_CreditHistory.created = to_java_date(creditHistory.created)
    return t_CreditHistory

def to_t_UserSanction(userSanction, ticketSize):
    t_UserSanction = TUserSanction()
    t_UserSanction.user_id = userSanction.user_id
    t_UserSanction.creditor_id = userSanction.creditor_id
    t_UserSanction.user_ref_id = userSanction.user_ref_id
    t_UserSanction.credit_limit = userSanction.credit_limit
    t_UserSanction.credit_blocked = userSanction.credit_blocked
    t_UserSanction.loan = userSanction.loan
    t_UserSanction.active = userSanction.active
    t_UserSanction.created = to_java_date(userSanction.created)
    if userSanction.updated:
        t_UserSanction.updated = to_java_date(userSanction.updated)
    t_UserSanction.ticket_size = ticketSize
        
    return t_UserSanction

def to_t_LoanHistory(loanHistory):
    t_LoanHistory = TLoanHistory()
    t_LoanHistory.id = loanHistory.id
    t_LoanHistory.user_id = loanHistory.user_id
    t_LoanHistory.creditor_id = loanHistory.creditor_id
    t_LoanHistory.payment_id = loanHistory.payment_id
    t_LoanHistory.amount = loanHistory.amount
    if loanHistory.credit_type:
        t_LoanHistory.credit_type = CreditTxnType._NAMES_TO_VALUES[loanHistory.credit_type]
    t_LoanHistory.created = to_java_date(loanHistory.created)
    if loanHistory.updated:
        t_LoanHistory.updated = to_java_date(loanHistory.updated)
    t_LoanHistory.loan_id = loanHistory.loan_id
    if loanHistory.due_date:
        t_LoanHistory.due_date = to_java_date(loanHistory.due_date)  
    if loanHistory.value_date:
        t_LoanHistory.value_date = to_java_date(loanHistory.value_date)
    if loanHistory.invoiceNumber:
        t_LoanHistory.invoiceNumber = loanHistory.invoiceNumber
        
    return t_LoanHistory

def to_t_PaginatedCreditHistory(hasMore, totalCount, creditHistoryList):
    t_PaginatedCreditHostory = TPaginatedCreditHistory()
    t_PaginatedCreditHostory.hasMore = hasMore
    t_PaginatedCreditHostory.totalCount = totalCount
    creditHistory = []
    for credit_history in creditHistoryList:
        creditHistory.append(to_t_CreditHistory(credit_history))
    t_PaginatedCreditHostory.creditHistoryList = creditHistory
    
    return t_PaginatedCreditHostory

def to_t_PaginatedLoanHistory(hasMore, totalCount, loanHistoryList):
    t_PaginatedLoanHistory = TPaginatedLoanHistory()
    t_PaginatedLoanHistory.hasMore = hasMore
    t_PaginatedLoanHistory.totalCount = totalCount
    loanHistory = []
    for loan_history in loanHistoryList:
        loanHistory.append(to_t_LoanHistory(loan_history))
    t_PaginatedLoanHistory.loanHistoryList = loanHistory
    
    return t_PaginatedLoanHistory

def to_t_PaginatedUserSanction(hasMore, totalCount, userSanctionList):
    t_PaginatedUserSanction = TPaginatedUserSanction()
    t_PaginatedUserSanction.hasMore = hasMore
    t_PaginatedUserSanction.totalCount = totalCount
    t_PaginatedUserSanction.userSanctions = userSanctionList
    
    return t_PaginatedUserSanction

def to_t_OutstandingPayments(outstandingPayment,counterName):
    t_OutstandingPayment = TOutstandingPayments()
    t_OutstandingPayment.user_id = outstandingPayment.user_id
    t_OutstandingPayment.counter_name = counterName
    t_OutstandingPayment.creditor_id = outstandingPayment.creditor_id
    t_OutstandingPayment.payment_id = outstandingPayment.payment_id
    t_OutstandingPayment.totalAmount = outstandingPayment.totalAmount 
    t_OutstandingPayment.created =  to_java_date(outstandingPayment.createdDate)
    return t_OutstandingPayment

def __loanHistoryObj(user_id, creditor_id, paymentId, amount, credit_type, loan_id, value_date=None, invoiceNumber=None):
    loanobj = TLoanHistory()
    loanobj.user_id = user_id
    loanobj.creditor_id = creditor_id    
    loanobj.payment_id = paymentId
    loanobj.amount = amount
    loanobj.credit_type = credit_type
    loanobj.loan_id = loan_id
    if value_date is not None:
        loanobj.value_date = to_java_date(value_date)
    if invoiceNumber is not None:
        loanobj.invoiceNumber = invoiceNumber
    return loanobj
    
def to_t_ShipmentLogisticsCostDetail(shipmentLogisticsCostDetail):
    t_ShipmentLogisticsCostDetail = TShipmentLogisticsCostDetail()
    t_ShipmentLogisticsCostDetail.logisticsTransactionId = shipmentLogisticsCostDetail.logisticsTransactionId
    t_ShipmentLogisticsCostDetail.airwayBillNo = shipmentLogisticsCostDetail.airwayBillNo
    t_ShipmentLogisticsCostDetail.shipmentAmount = shipmentLogisticsCostDetail.shipmentAmount
    t_ShipmentLogisticsCostDetail.shipmentWeight = shipmentLogisticsCostDetail.shipmentWeight
    t_ShipmentLogisticsCostDetail.shipmentLogsiticsCost = shipmentLogisticsCostDetail.shipmentLogsiticsCost
    t_ShipmentLogisticsCostDetail.shipmentCodCollectionCharges = shipmentLogisticsCostDetail.shipmentCodCollectionCharges
    t_ShipmentLogisticsCostDetail.createdAt = to_java_date(shipmentLogisticsCostDetail.createdAt)
    if shipmentLogisticsCostDetail.updatedAt:
        t_ShipmentLogisticsCostDetail.updatedAt = to_java_date(shipmentLogisticsCostDetail.updatedAt)
    t_ShipmentLogisticsCostDetail.packageDimensions = shipmentLogisticsCostDetail.packageDimensions
        
    return t_ShipmentLogisticsCostDetail

def to_t_pmsa(pmsa, l1_user_email="", l2_user_email=""):
    t_pmsa = TPmsa()
    if pmsa is None:
        return t_pmsa
    t_pmsa.id = pmsa.id
    t_pmsa.name = pmsa.name
    t_pmsa.pin = pmsa.pin
    t_pmsa.phone = pmsa.phone
    t_pmsa.emailId = pmsa.emailId
    t_pmsa.address = pmsa.address
    t_pmsa.state = pmsa.state
    t_pmsa.level = pmsa.level
    t_pmsa.activated = pmsa.activated
    t_pmsa.code = pmsa.code
    t_pmsa.createdAt = to_java_date(pmsa.createdAt)
    t_pmsa.l1_email = l1_user_email
    t_pmsa.l2_email = l2_user_email
    return t_pmsa