Subversion Repositories SmartDukaan

Rev

Rev 8488 | Rev 8942 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

'''
Created on 29-Mar-2010

@author: ashish
'''

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
from shop2020.utils.Utils import to_java_date
from shop2020.model.v1.order.impl.DataService import Alert, Transaction
import datetime

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.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.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
    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
    
    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_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
    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
    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)
    return t_amazonFbaSalesSnapshot