Subversion Repositories SmartDukaan

Rev

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

'''
Created on 23-Mar-2010

@author: ashish
'''
from shop2020.model.v1.catalog.impl.DataService import Insurer, SnapdealItem, Item,\
    ExclusiveAffiliateItemInfo
from shop2020.thriftpy.model.v1.catalog.ttypes import Item, Category, \
    SourceItemPricing, Source, ItemType, \
    ProductNotificationRequest as TProductNotificationRequest, \
    ProductNotificationRequestCount as TProductNotificationRequestCount, \
    VoucherItemMapping, EntityTag as TEntityTag, Banner as TBanner, BannerMap as TBannerMap, \
    Insurer as TInsurer, BrandInfo as TBrandInfo, Amazonlisted as TAmazonlisted, \
    EbayItem as TEbayItem, BannerUriMapping as TBannerUriMapping, Campaign as TCampaign, \
    SnapdealItem as TSnapdealItem, SnapdealItemDetails as TSnapdealItemDetails,ProductFeedSubmit as TProductFeedSubmit, \
    MarketplaceItems as TMarketplaceItems, MarketplacePercentage as TMarketplacePercentage, \
    MarketPlaceItemPrice as TMarketPlaceItemPrice, FlipkartItem as TFlipkartItem,\
    FlipkartItemDetails as TFlipkartItemDetails,MarketplaceHistory as TMarketplaceHistory,\
    PrivateDeal as TPrivateDeal, AmazonOutOfSync as TAmazonOutOfSync, PdPriceComp as TPdPriceComp, CompetitorPricing as TCompetitorPricing, \
    AmazonPromotion as TAmazonPromotion, ExclusiveAffiliateItemInfo as TExclusiveAffiliateItemInfo, \
    HsItem as THsItem, VoiSnapdealItemInfo as TVoiSnapdealItemInfo, BulkItemPricing as TBulkItemPricing, DtrPricing as TDtrPricing, \
    CategoryHsnCode as TCategoryHsnCode, StateGstRate

from shop2020.utils.Utils import to_java_date, to_py_date
import datetime

def to_t_item(item, dealPrice=None):
    t_item = Item()
    if item is None:
        return t_item
    t_item.id = item.id
    t_item.dealPrice = dealPrice
    t_item.productGroup = item.product_group
    t_item.brand = item.brand
    t_item.modelNumber = item.model_number
    t_item.modelName = item.model_name
    t_item.color = item.color
    t_item.category = item.category
    t_item.catalogItemId = item.catalog_item_id
    t_item.weight = item.weight
    t_item.featureId = item.feature_id
    t_item.featureDescription = item.feature_description
    if item.startDate:
        t_item.startDate = to_java_date(item.startDate)
    if item.comingSoonStartDate:
        t_item.comingSoonStartDate = to_java_date(item.comingSoonStartDate)
    if item.expectedArrivalDate:
        t_item.expectedArrivalDate = to_java_date(item.expectedArrivalDate)
    if item.addedOn:
        t_item.addedOn = to_java_date(item.addedOn)
    if item.updatedOn:
        t_item.updatedOn = to_java_date(item.updatedOn)
    t_item.itemStatus = item.status
    t_item.status_description = item.status_description
    if item.sellingPrice:
        t_item.sellingPrice = item.sellingPrice
    if item.mrp:
        t_item.mrp = item.mrp    
    
    if item.comments:
        t_item.comments = item.comments
    if item.bestDealText:
        t_item.bestDealText = item.bestDealText
    if item.bestDealsDetailsText:
        t_item.bestDealsDetailsText = item.bestDealsDetailsText
    if item.bestDealsDetailsLink:
        t_item.bestDealsDetailsLink = item.bestDealsDetailsLink 
    if item.bestDealValue:
        t_item.bestDealValue = item.bestDealValue
    if item.asin:
        t_item.asin = item.asin    
    t_item.defaultForEntity = item.defaultForEntity
    t_item.bestSellingRank = item.bestSellingRank
    t_item.risky = item.risky
    t_item.expectedDelay = item.expectedDelay
    t_item.isWarehousePreferenceSticky = item.isWarehousePreferenceSticky
    t_item.warrantyPeriod = item.warranty_period
    t_item.preferredVendor = item.preferredVendor
    t_item.type = ItemType._NAMES_TO_VALUES[item.type]
    t_item.hasItemNo = item.hasItemNo
    t_item.activeOnStore = item.activeOnStore
    t_item.showSellingPrice = item.showSellingPrice
    t_item.preferredInsurer = item.preferredInsurer
    t_item.holdInventory = item.holdInventory
    t_item.defaultInventory = item.defaultInventory
    t_item.holdOverride = item.holdOverride
    t_item.packQuantity = item.packQuantity
    t_item.quantityStep = item.quantityStep
    t_item.minimumBuyQuantity = item.minimumBuyQuantity
    t_item.maximumBuyQuantity = item.maximumBuyQuantity
    t_item.hsnCode = item.hsnCode
    return t_item

def to_t_insurer(insurer):
    t_insurer = TInsurer()
    t_insurer.id = insurer.id
    t_insurer.name = insurer.name 
    t_insurer.address = insurer.address
    t_insurer.declaredAmount = insurer.declaredAmount
    t_insurer.creditedAmount = insurer.creditedAmount
    return t_insurer

def to_t_state_gst_rate(stateGstRate):
    t_state_gst_rate = StateGstRate()
    t_state_gst_rate.itemId = stateGstRate.itemId
    t_state_gst_rate.stateId = stateGstRate.stateId
    t_state_gst_rate.igstRate = stateGstRate.igstRate
    t_state_gst_rate.cgstRate = stateGstRate.cgstRate
    t_state_gst_rate.sgstRate = stateGstRate.sgstRate
    return t_state_gst_rate

def to_t_voucher_item_mapping(voucher):
    t_voucher = VoucherItemMapping()
    t_voucher.voucherType = voucher.voucherType
    t_voucher.itemId = voucher.item.id
    t_voucher.amount = voucher.amount
    return t_voucher

def to_t_category(category):
    t_category = Category()
    t_category.id = category.id
    t_category.label = category.label
    t_category.description = category.description
    t_category.parent_category_id = category.parent_category_id
    t_category.display_name = category.display_name
    return t_category

def to_t_source_item_pricing(source_item_pricing):
    t_source_item_pricing = SourceItemPricing()
    t_source_item_pricing.sourceId = source_item_pricing.source.id
    t_source_item_pricing.itemId = source_item_pricing.item.id
    t_source_item_pricing.mrp = source_item_pricing.mrp
    t_source_item_pricing.sellingPrice = source_item_pricing.sellingPrice
    return t_source_item_pricing

def to_t_source(source):
    t_source = Source()
    t_source.id = source.id
    t_source.name = source.name
    t_source.identifier = source.identifier
    return t_source

def to_t_product_notification_request(product_notification_request):
    t_product_notification_request = TProductNotificationRequest()
    
    if product_notification_request:
        t_product_notification_request.item = to_t_item(product_notification_request.item)
        t_product_notification_request.email = product_notification_request.email
        t_product_notification_request.addedOn = to_java_date(product_notification_request.addedOn)
    
    return t_product_notification_request

def to_t_product_notification_request_count(product_notification_request_count):
    
    t_product_notification_request_count = TProductNotificationRequestCount()
    
    if product_notification_request_count:
        item, count = product_notification_request_count
        t_product_notification_request_count.item = to_t_item(item)
        t_product_notification_request_count.count = count
    
    return t_product_notification_request_count

def to_t_entity_tag(entity_tag):
    t_entity_tag = TEntityTag()
    t_entity_tag.entityId = entity_tag.entityId
    t_entity_tag.tag = entity_tag.tag
    
def to_t_banner(banner):
    t_banner = TBanner()
    t_banner.bannerName = banner.bannerName
    t_banner.imageName = banner.imageName
    t_banner.link = banner.link
    t_banner.priority = banner.priority
    t_banner.hasMap = banner.hasMap
    t_banner.bannerType = banner.bannerType
    return t_banner

def to_t_banner_list(bannerList):
    t_banner_list = []
    for banner in bannerList:
        t_banner = TBanner()
        t_banner.bannerName = banner.bannerName
        t_banner.imageName = banner.imageName
        t_banner.link = banner.link
        t_banner.priority = banner.priority
        t_banner.hasMap = banner.hasMap
        t_banner.bannerType = banner.bannerType
        t_banner_list.append(t_banner)
    return t_banner_list
        

def to_t_banner_map(banner_map):
    t_banner_map = TBannerMap()
    t_banner_map.bannerName = banner_map.bannerName
    t_banner_map.mapLink = banner_map.mapLink
    t_banner_map.coordinates = banner_map.coordinates
    return t_banner_map

def to_t_uri_mapping(uriMapping):
    t_uri_mapping =TBannerUriMapping()
    t_uri_mapping.bannerName = uriMapping.bannerName
    t_uri_mapping.uri = uriMapping.uri
    t_uri_mapping.isActive = uriMapping.isActive
    t_uri_mapping.target = uriMapping.target
    return t_uri_mapping

def to_t_campaign(campaign):
    t_campaign = TCampaign()
    t_campaign.id = campaign.id
    t_campaign.campaignName = campaign.campaignName
    t_campaign.imageName = campaign.imageName
    return t_campaign

def to_t_Amazonlisted(Amazonlisted):
    t_amazonlisted = TAmazonlisted()
    if Amazonlisted is None:
        return t_amazonlisted
    t_amazonlisted.asin = Amazonlisted.asin
    t_amazonlisted.brand = Amazonlisted.brand 
    t_amazonlisted.itemid = Amazonlisted.itemId
    t_amazonlisted.model = Amazonlisted.model
    t_amazonlisted.manufacturer_name = Amazonlisted.manufacturer_name
    t_amazonlisted.upc = Amazonlisted.upc
    t_amazonlisted.part_number = Amazonlisted.part_number
    t_amazonlisted.name = Amazonlisted.name
    t_amazonlisted.ean = Amazonlisted.ean
    t_amazonlisted.fbaPrice = Amazonlisted.fbaPrice
    t_amazonlisted.fbbPrice = Amazonlisted.fbbPrice
    t_amazonlisted.sellingPrice = Amazonlisted.sellingPrice
    t_amazonlisted.isFba = Amazonlisted.isFba
    t_amazonlisted.isFbb = Amazonlisted.isFbb
    t_amazonlisted.isNonFba = Amazonlisted.isNonFba
    t_amazonlisted.isInventoryOverride = Amazonlisted.isInventoryOverride
    t_amazonlisted.color = Amazonlisted.color
    t_amazonlisted.category = Amazonlisted.category
    t_amazonlisted.handlingTime = Amazonlisted.handlingTime
    t_amazonlisted.isCustomTime = Amazonlisted.isCustomTime
    t_amazonlisted.category_code = Amazonlisted.category_code
    t_amazonlisted.mfnPriceLastUpdatedOn = to_java_date(Amazonlisted.mfnPriceLastUpdatedOn)
    t_amazonlisted.fbaPriceLastUpdatedOn = to_java_date(Amazonlisted.fbaPriceLastUpdatedOn)
    t_amazonlisted.fbbPriceLastUpdatedOn = to_java_date(Amazonlisted.fbbPriceLastUpdatedOn)
    t_amazonlisted.mfnPriceLastUpdatedOnSc = to_java_date(Amazonlisted.mfnPriceLastUpdatedOnSc)
    t_amazonlisted.fbbPriceLastUpdatedOnSc = to_java_date(Amazonlisted.fbbPriceLastUpdatedOnSc)
    t_amazonlisted.fbaPriceLastUpdatedOnSc = to_java_date(Amazonlisted.fbaPriceLastUpdatedOnSc)
    t_amazonlisted.suppressMfnPriceUpdate = Amazonlisted.suppressMfnPriceUpdate
    t_amazonlisted.suppressFbaPriceUpdate = Amazonlisted.suppressFbaPriceUpdate
    t_amazonlisted.suppressFbbPriceUpdate = Amazonlisted.suppressFbbPriceUpdate
    t_amazonlisted.taxCode = Amazonlisted.taxCode
    t_amazonlisted.fbbtaxCode = Amazonlisted.fbbtaxCode
    t_amazonlisted.overrrideWanlc = Amazonlisted.overrrideWanlc
    t_amazonlisted.exceptionalWanlc = Amazonlisted.exceptionalWanlc
    t_amazonlisted.autoDecrement = Amazonlisted.autoDecrement
    t_amazonlisted.autoIncrement = Amazonlisted.autoIncrement
    t_amazonlisted.autoFavourite = Amazonlisted.autoFavourite
    t_amazonlisted.manualFavourite = Amazonlisted.manualFavourite
    t_amazonlisted.otherCost = Amazonlisted.otherCost
    t_amazonlisted.fbaPromoPrice = Amazonlisted.fbaPromoPrice
    t_amazonlisted.fbbPromoPrice = Amazonlisted.fbbPromoPrice
    t_amazonlisted.fbaPromoStartDate = to_java_date(Amazonlisted.fbaPromoStartDate)
    t_amazonlisted.fbaPromoEndDate = to_java_date(Amazonlisted.fbaPromoEndDate)
    t_amazonlisted.fbbPromoStartDate = to_java_date(Amazonlisted.fbbPromoStartDate)
    t_amazonlisted.fbbPromoEndDate = to_java_date(Amazonlisted.fbbPromoEndDate)
    t_amazonlisted.isFbaPromotionActive = Amazonlisted.fbaPromotionActive
    t_amazonlisted.isFbbPromotionActive = Amazonlisted.fbbPromotionActive
    t_amazonlisted.fbgPrice = Amazonlisted.fbgPrice
    t_amazonlisted.isFbg = Amazonlisted.isFbg
    t_amazonlisted.fbgtaxCode = Amazonlisted.fbgtaxCode
    t_amazonlisted.suppressFbgPriceUpdate = Amazonlisted.suppressFbgPriceUpdate
    t_amazonlisted.fbgPriceLastUpdatedOn = to_java_date(Amazonlisted.fbgPriceLastUpdatedOn)
    t_amazonlisted.fbgPriceLastUpdatedOnSc = to_java_date(Amazonlisted.fbgPriceLastUpdatedOnSc)
    t_amazonlisted.fbgPromoPrice = Amazonlisted.fbgPromoPrice
    t_amazonlisted.fbgPromoStartDate = to_java_date(Amazonlisted.fbgPromoStartDate)
    t_amazonlisted.fbgPromoEndDate = to_java_date(Amazonlisted.fbgPromoEndDate)
    t_amazonlisted.isFbgPromotionActive = Amazonlisted.fbgPromotionActive
    t_amazonlisted.fbdPrice = Amazonlisted.fbdPrice
    t_amazonlisted.isFbd = Amazonlisted.isFbd
    t_amazonlisted.fbdtaxCode = Amazonlisted.fbdtaxCode
    t_amazonlisted.suppressFbdPriceUpdate = Amazonlisted.suppressFbdPriceUpdate
    t_amazonlisted.fbdPriceLastUpdatedOn = to_java_date(Amazonlisted.fbdPriceLastUpdatedOn)
    t_amazonlisted.fbdPriceLastUpdatedOnSc = to_java_date(Amazonlisted.fbdPriceLastUpdatedOnSc)
    t_amazonlisted.fbdPromoPrice = Amazonlisted.fbdPromoPrice
    t_amazonlisted.fbdPromoStartDate = to_java_date(Amazonlisted.fbdPromoStartDate)
    t_amazonlisted.fbdPromoEndDate = to_java_date(Amazonlisted.fbdPromoEndDate)
    t_amazonlisted.isFbdPromotionActive = Amazonlisted.fbdPromotionActive 
     
    return t_amazonlisted

def to_t_ebay_item(ebay_item):
    t_ebay_item = TEbayItem()
    t_ebay_item.ebayListingId = ebay_item.ebayListingId
    t_ebay_item.itemId = ebay_item.itemId
    t_ebay_item.listingName = ebay_item.listingName
    t_ebay_item.listingPrice = ebay_item.listingPrice
    t_ebay_item.listingExpiryDate = to_java_date(ebay_item.listingExpiryDate)
    t_ebay_item.subsidy = ebay_item.subsidy
    return t_ebay_item

def to_t_brand_info(brand_info):
    t_brand_info = TBrandInfo()
    t_brand_info.name = brand_info.name
    t_brand_info.serviceCenterLocatorUrl = brand_info.serviceCenterLocatorUrl
    return t_brand_info

def to_t_snapdeal_item(snapdealitem):
    if snapdealitem is None:
        t_snapdeal_item = TSnapdealItem()
        return t_snapdeal_item
    t_snapdeal_item = TSnapdealItem()
    t_snapdeal_item.item_id = snapdealitem[0].item_id
    t_snapdeal_item.warehouseId = snapdealitem[0].warehouseId
    t_snapdeal_item.exceptionPrice = snapdealitem[0].exceptionPrice
    t_snapdeal_item.transferPrice = snapdealitem[0].transferPrice
    t_snapdeal_item.sellingPrice = snapdealitem[0].sellingPrice
    t_snapdeal_item.courierCost = snapdealitem[0].courierCost
    t_snapdeal_item.courierCostMarketplace = snapdealitem[0].courierCostMarketplace
    t_snapdeal_item.commission = snapdealitem[0].commission
    t_snapdeal_item.serviceTax = snapdealitem[0].serviceTax
    t_snapdeal_item.isListedOnSnapdeal = snapdealitem[0].isListedOnSnapdeal
    t_snapdeal_item.suppressPriceFeed = snapdealitem[0].suppressPriceFeed
    t_snapdeal_item.suppressInventoryFeed = snapdealitem[0].suppressInventoryFeed
    t_snapdeal_item.maxNlc = snapdealitem[0].maxNlc
    t_snapdeal_item.skuAtSnapdeal = snapdealitem[0].skuAtSnapdeal
    t_snapdeal_item.supc = snapdealitem[0].supc
    t_snapdeal_item.shippingTime = snapdealitem[0].shippingTime
    t_snapdeal_item.isVoiListed = snapdealitem[0].isVoiListed
    t_snapdeal_item.voiSellingPrice = snapdealitem[0].voiSellingPrice
    t_snapdeal_item.suppressVoiPriceFeed = snapdealitem[0].suppressVoiPriceFeed
    t_snapdeal_item.voiPriceLastUpdatedOn = to_java_date(snapdealitem[0].voiPriceLastUpdatedOn)
    t_snapdeal_item.voiSkuAtSnapdeal = snapdealitem[0].voiSkuAtSnapdeal
    t_snapdeal_item.minimumPossibleSpVoi = snapdealitem[0].minimumPossibleSpVoi
    t_snapdeal_item.minimumPossibleTpVoi = snapdealitem[0].minimumPossibleTpVoi
    t_snapdeal_item.courierCostVoi = snapdealitem[0].courierCostVoi
    t_snapdeal_item.serviceTaxVoi = snapdealitem[0].serviceTaxVoi
    t_snapdeal_item.transferPriceVoi = snapdealitem[0].transferPriceVoi
    t_snapdeal_item.commissionVoi = snapdealitem[0].commissionVoi
    t_snapdeal_item.courierCostMarketplaceVoi = snapdealitem[0].courierCostMarketplaceVoi
    t_snapdeal_item.commissionPercentageVoi = snapdealitem[0].commissionPercentageVoi
    return t_snapdeal_item

def to_t_snapdeal_item_details(snapdealitem,snapdealItemInventory):
    if snapdealitem is None:
        t_snapdeal_item_details = TSnapdealItemDetails()
        return t_snapdeal_item_details
    t_snapdeal_item_details = TSnapdealItemDetails()
    t_snapdeal_item_details.item_id = snapdealitem[0].item_id
    t_snapdeal_item_details.warehouseId = snapdealitem[0].warehouseId
    t_snapdeal_item_details.exceptionPrice = snapdealitem[0].exceptionPrice
    t_snapdeal_item_details.transferPrice = snapdealitem[0].transferPrice
    t_snapdeal_item_details.sellingPrice = snapdealitem[0].sellingPrice
    t_snapdeal_item_details.courierCost = snapdealitem[0].courierCost
    t_snapdeal_item_details.courierCostMarketplace = snapdealitem[0].courierCostMarketplace
    t_snapdeal_item_details.commission = snapdealitem[0].commission
    t_snapdeal_item_details.serviceTax = snapdealitem[0].serviceTax
    t_snapdeal_item_details.brand = snapdealitem[1].brand
    t_snapdeal_item_details.model_name = snapdealitem[1].model_name
    t_snapdeal_item_details.model_number = snapdealitem[1].model_number
    t_snapdeal_item_details.color = snapdealitem[1].color
    t_snapdeal_item_details.risky = snapdealitem[1].risky
    t_snapdeal_item_details.itemStatus = snapdealitem[1].status
    t_snapdeal_item_details.isListedOnSnapdeal = snapdealitem[0].isListedOnSnapdeal
    t_snapdeal_item_details.weight = snapdealitem[1].weight
    t_snapdeal_item_details.mrp = snapdealitem[1].mrp
    t_snapdeal_item_details.websiteSellingPrice = snapdealitem[1].sellingPrice
    t_snapdeal_item_details.suppressPriceFeed = snapdealitem[0].suppressPriceFeed
    t_snapdeal_item_details.suppressInventoryFeed = snapdealitem[0].suppressInventoryFeed
    t_snapdeal_item_details.maxNlc = snapdealitem[0].maxNlc
    t_snapdeal_item_details.skuAtSnapdeal = snapdealitem[0].skuAtSnapdeal
    t_snapdeal_item_details.supc = snapdealitem[0].supc
    t_snapdeal_item_details.shippingTime = snapdealitem[0].shippingTime
    t_snapdeal_item_details.isVoiListed = snapdealitem[0].isVoiListed
    if snapdealItemInventory is not None:
        t_snapdeal_item_details.lastUpdatedInventory = snapdealItemInventory.availability
        t_snapdeal_item_details.lastUpdatedInventoryTimestamp = snapdealItemInventory.lastUpdatedOnSnapdeal 
    return t_snapdeal_item_details

def to_t_product_feed_submit(productfeedsubmit):
    if productfeedsubmit is None:
        t_product_feed_submit = TProductFeedSubmit()
        return t_product_feed_submit
    t_product_feed_submit = TProductFeedSubmit()
    t_product_feed_submit.catalogItemId = productfeedsubmit.catalogItemId
    t_product_feed_submit.stockLinkedFeed = productfeedsubmit.stockLinkedFeed
    return t_product_feed_submit

def to_t_marketplace_items(marketplaceItem):
    t_marketplace_item = TMarketplaceItems() 
    if marketplaceItem is None:
        return t_marketplace_item
    t_marketplace_item.itemId = marketplaceItem.itemId
    t_marketplace_item.source = marketplaceItem.source
    t_marketplace_item.emiFee = marketplaceItem.emiFee
    t_marketplace_item.courierCost = marketplaceItem.courierCost
    t_marketplace_item.courierCostMarketplace = marketplaceItem.courierCostMarketplace
    t_marketplace_item.closingFee = marketplaceItem.closingFee
    t_marketplace_item.commission = marketplaceItem.commission
    t_marketplace_item.returnProvision = marketplaceItem.returnProvision
    t_marketplace_item.vat = marketplaceItem.vat
    t_marketplace_item.packagingCost = marketplaceItem.packagingCost
    t_marketplace_item.otherCost = marketplaceItem.otherCost
    t_marketplace_item.serviceTax = marketplaceItem.serviceTax
    t_marketplace_item.autoIncrement = marketplaceItem.autoIncrement
    t_marketplace_item.autoDecrement = marketplaceItem.autoDecrement
    t_marketplace_item.autoFavourite = marketplaceItem.autoFavourite
    t_marketplace_item.manualFavourite = marketplaceItem.manualFavourite
    t_marketplace_item.currentSp = marketplaceItem.currentSp
    t_marketplace_item.currentTp = marketplaceItem.currentTp
    t_marketplace_item.minimumPossibleSp = marketplaceItem.minimumPossibleSp
    t_marketplace_item.minimumPossibleTp = marketplaceItem.minimumPossibleTp
    t_marketplace_item.lastCheckedTimestamp = to_java_date(marketplaceItem.lastCheckedTimestamp)
    t_marketplace_item.maximumSellingPrice = marketplaceItem.maximumSellingPrice
    t_marketplace_item.pgFee = marketplaceItem.pgFee
    return t_marketplace_item

def to_t_marketplace_itemprice(marketplaceitemprice):
    t_marketplace_priceitem = TMarketPlaceItemPrice()    
    t_marketplace_priceitem.item_id = marketplaceitemprice.item_id
    t_marketplace_priceitem.source = marketplaceitemprice.source
    t_marketplace_priceitem.sellingPrice = marketplaceitemprice.sellingPrice
    t_marketplace_priceitem.lastUpdatedOn = to_java_date(marketplaceitemprice.lastUpdatedOn)
    t_marketplace_priceitem.lastUpdatedOnMarketplace = to_java_date(marketplaceitemprice.lastUpdatedOnMarketplace)
    t_marketplace_priceitem.isPriceOverride = marketplaceitemprice.suppressPriceFeed
    t_marketplace_priceitem.isListedOnSource = marketplaceitemprice.isListedOnSource
    return t_marketplace_priceitem 

def to_t_marketplacepercentage(marketplacePercentage):
    t_marketplacepercentage = TMarketplacePercentage()
    if marketplacePercentage is None:
        return t_marketplacepercentage
    t_marketplacepercentage.source =  marketplacePercentage.source
    t_marketplacepercentage.emiFee =  marketplacePercentage.emiFee
    t_marketplacepercentage.closingFee = marketplacePercentage.closingFee
    t_marketplacepercentage.returnProvision = marketplacePercentage.returnProvision
    t_marketplacepercentage.commission = marketplacePercentage.commission
    t_marketplacepercentage.serviceTax = marketplacePercentage.serviceTax
    t_marketplacepercentage.pgFee = marketplacePercentage.pgFee
    return t_marketplacepercentage

def to_t_flipkart_item(flipkartItem):
    t_flipkartitem = TFlipkartItem()
    if flipkartItem is None:
        return t_flipkartitem
    t_flipkartitem.item_id = flipkartItem[0].item_id  
    t_flipkartitem.exceptionPrice = flipkartItem[0].exceptionPrice
    t_flipkartitem.warehouseId = flipkartItem[0].warehouseId
    t_flipkartitem.commissionValue  =  flipkartItem[0].commissionValue
    t_flipkartitem.serviceTaxValue  =  flipkartItem[0].serviceTaxValue
    t_flipkartitem.maxNlc = flipkartItem[0].maxNlc
    t_flipkartitem.skuAtFlipkart = flipkartItem[0].skuAtFlipkart
    t_flipkartitem.isListedOnFlipkart = flipkartItem[0].isListedOnFlipkart
    t_flipkartitem.suppressPriceFeed = flipkartItem[0].suppressPriceFeed
    t_flipkartitem.suppressInventoryFeed = flipkartItem[0].suppressInventoryFeed
    #t_flipkartitem.updatedOn = to_java_date(flipkartItem.updatedOn)
    t_flipkartitem.updatedBy = flipkartItem[0].updatedBy
    t_flipkartitem.flipkartSerialNumber = flipkartItem[0].flipkartSerialNumber
    t_flipkartitem.isFaListed = flipkartItem[0].isFaListed
    return t_flipkartitem

def to_t_flipkart_item_details(flipkartitem,flipkartItemInventory):
    if flipkartitem is None:
        t_flipkart_item_details = TFlipkartItemDetails()
        return t_flipkart_item_details
    t_flipkart_item_details = TFlipkartItemDetails()
    t_flipkart_item_details.item_id = flipkartitem[0].item_id
    t_flipkart_item_details.warehouseId = flipkartitem[0].warehouseId
    t_flipkart_item_details.exceptionPrice = flipkartitem[0].exceptionPrice
    t_flipkart_item_details.commission = flipkartitem[0].commissionValue
    t_flipkart_item_details.serviceTax = flipkartitem[0].serviceTaxValue
    t_flipkart_item_details.brand = flipkartitem[1].brand
    t_flipkart_item_details.model_name = flipkartitem[1].model_name
    t_flipkart_item_details.model_number = flipkartitem[1].model_number
    t_flipkart_item_details.color = flipkartitem[1].color
    t_flipkart_item_details.risky = flipkartitem[1].risky
    t_flipkart_item_details.itemStatus = flipkartitem[1].status
    t_flipkart_item_details.isListedOnFlipkart = flipkartitem[0].isListedOnFlipkart
    t_flipkart_item_details.weight = flipkartitem[1].weight
    t_flipkart_item_details.mrp = flipkartitem[1].mrp
    t_flipkart_item_details.websiteSellingPrice = flipkartitem[1].sellingPrice
    t_flipkart_item_details.suppressPriceFeed = flipkartitem[0].suppressPriceFeed
    t_flipkart_item_details.suppressInventoryFeed = flipkartitem[0].suppressInventoryFeed
    t_flipkart_item_details.maxNlc = flipkartitem[0].maxNlc
    t_flipkart_item_details.skuAtFlipkart = flipkartitem[0].skuAtFlipkart
    t_flipkart_item_details.flipkartSerialNumber = flipkartitem[0].flipkartSerialNumber
    t_flipkart_item_details.category = flipkartitem[1].category
    t_flipkart_item_details.isFaListed = flipkartitem[0].isFaListed
    if flipkartItemInventory is not None:
        t_flipkart_item_details.lastUpdatedInventory = flipkartItemInventory.availability
        #t_flipkart_item_details.lastUpdatedInventoryTimestamp = flipkartItemInventory.lastUpdatedOnFlipkart 
    return t_flipkart_item_details

def to_t_market_place_history(marketplaceHistory):
    t_marketplace_history = TMarketplaceHistory()
    if marketplaceHistory is None:
        return t_marketplace_history
    t_marketplace_history.item_id = marketplaceHistory.item_id
    t_marketplace_history.source = marketplaceHistory.source
    t_marketplace_history.timestamp = to_java_date(marketplaceHistory.timestamp)
    if marketplaceHistory.lowestPossibleTp is None:
        t_marketplace_history.lowest_possible_tp =0
    else:
        t_marketplace_history.lowest_possible_tp = int(marketplaceHistory.lowestPossibleTp)
    if marketplaceHistory.lowestPossibleSp is None:
        t_marketplace_history.lowest_possible_sp = 0
    else:
        t_marketplace_history.lowest_possible_sp = int(marketplaceHistory.lowestPossibleSp)
    t_marketplace_history.ourInventory = marketplaceHistory.ourInventory
    t_marketplace_history.otherInventory = marketplaceHistory.otherInventory
    t_marketplace_history.secondLowestInventory = marketplaceHistory.secondLowestInventory
    t_marketplace_history.ourRank = marketplaceHistory.ourRank
    if marketplaceHistory.ourOfferPrice is None:
        t_marketplace_history.ourOfferPrice = 0
    else: 
        t_marketplace_history.ourOfferPrice = int(marketplaceHistory.ourOfferPrice)
    if marketplaceHistory.ourSellingPrice is None:
        t_marketplace_history.ourSellingPrice = 0
    else:
        t_marketplace_history.ourSellingPrice = int(marketplaceHistory.ourSellingPrice)
    if marketplaceHistory.ourTp is None:
        t_marketplace_history.ourTp = 0
    else:
        t_marketplace_history.ourTp = int(marketplaceHistory.ourTp)
    if marketplaceHistory.ourNlc is None:
        t_marketplace_history.ourNlc = 0
    else:
        t_marketplace_history.ourNlc = int(marketplaceHistory.ourNlc)
    t_marketplace_history.competitiveCategory = marketplaceHistory.competitiveCategory
    t_marketplace_history.risky = marketplaceHistory.risky
    if marketplaceHistory.lowestOfferPrice is None:
        t_marketplace_history.lowestOfferPrice = 0
    else:
        t_marketplace_history.lowestOfferPrice = int(marketplaceHistory.lowestOfferPrice)
    if marketplaceHistory.lowestSellingPrice is None:
        t_marketplace_history.lowestSellingPrice = 0
    else:
        t_marketplace_history.lowestSellingPrice = int(marketplaceHistory.lowestSellingPrice)
    if marketplaceHistory.lowestTp is None:
        t_marketplace_history.lowestTp = 0
    else:
        t_marketplace_history.lowestTp = int(marketplaceHistory.lowestTp)
    if marketplaceHistory.lowestSellerName is None:
        t_marketplace_history.lowestSellerName = ''
    else:
        t_marketplace_history.lowestSellerName = marketplaceHistory.lowestSellerName
    if marketplaceHistory.proposedSellingPrice is None:
        t_marketplace_history.proposedSellingPrice = 0
    else:
        t_marketplace_history.proposedSellingPrice = int(marketplaceHistory.proposedSellingPrice)
    if marketplaceHistory.proposedTp is None:
        t_marketplace_history.proposedTp = 0
    else:
        t_marketplace_history.proposedTp = int(marketplaceHistory.proposedTp)
    if marketplaceHistory.targetNlc is None:
        t_marketplace_history.targetNlc = 0
    else:
        t_marketplace_history.targetNlc = int(marketplaceHistory.targetNlc)
    t_marketplace_history.salesPotential = marketplaceHistory.salesPotential
    if marketplaceHistory.secondLowestSellerName is None:
        t_marketplace_history.secondLowestSellerName = ''
    else:
        t_marketplace_history.secondLowestSellerName = marketplaceHistory.secondLowestSellerName
    if marketplaceHistory.secondLowestSellingPrice is None:
        t_marketplace_history.secondLowestSellingPrice=0
    else:
        t_marketplace_history.secondLowestSellingPrice = int(marketplaceHistory.secondLowestSellingPrice)
    if marketplaceHistory.secondLowestOfferPrice is None:
        t_marketplace_history.secondLowestOfferPrice = 0
    else:
        t_marketplace_history.secondLowestOfferPrice = int(marketplaceHistory.secondLowestOfferPrice)
    if marketplaceHistory.secondLowestTp is None:
        t_marketplace_history.secondLowestTp=0
    else:
        t_marketplace_history.secondLowestTp = int(marketplaceHistory.secondLowestTp)
    t_marketplace_history.marginIncreasedPotential = marketplaceHistory.marginIncreasedPotential
    if marketplaceHistory.margin is None:
        t_marketplace_history.margin = 0
    else:
        t_marketplace_history.margin = int(marketplaceHistory.margin)
    t_marketplace_history.ourEnoughStock = marketplaceHistory.ourEnoughStock
    t_marketplace_history.totalSeller = marketplaceHistory.totalSeller
    t_marketplace_history.averageSale = marketplaceHistory.avgSales
    t_marketplace_history.toGroup = marketplaceHistory.toGroup
    t_marketplace_history.decision = marketplaceHistory.decision
    t_marketplace_history.reason = marketplaceHistory.reason
    return t_marketplace_history
    
def to_t_private_deal(private_deal_item):
    if private_deal_item is None:
        t_private_deal_item = TPrivateDeal()
        return t_private_deal_item
    t_private_deal_item = TPrivateDeal()
    t_private_deal_item.item_id = private_deal_item.item_id
    t_private_deal_item.dealPrice = private_deal_item.dealPrice
    t_private_deal_item.dealFreebieItemId = private_deal_item.dealFreebieItemId
    t_private_deal_item.startDate = to_java_date(private_deal_item.startDate)
    t_private_deal_item.endDate = to_java_date(private_deal_item.endDate)
    t_private_deal_item.dealTextOption = private_deal_item.dealTextOption
    if private_deal_item.dealText is None: 
        t_private_deal_item.dealText = ''
    else:
        t_private_deal_item.dealText = private_deal_item.dealText    
    t_private_deal_item.isCod = private_deal_item.isCod
    t_private_deal_item.rank = private_deal_item.rank
    t_private_deal_item.dealFreebieOption = private_deal_item.dealFreebieOption
    t_private_deal_item.isActive = private_deal_item.isActive
    return t_private_deal_item

def to_t_amazonoutofsync(amazonOutOfSync):
    t_amazonoutofsync = TAmazonOutOfSync()
    if amazonOutOfSync is None:
        return t_amazonoutofsync
    else:
        t_amazonoutofsync.item_id = amazonOutOfSync.item_id
        t_amazonoutofsync.mfn = amazonOutOfSync.mfn
        t_amazonoutofsync.fba = amazonOutOfSync.fba
        t_amazonoutofsync.fbb = amazonOutOfSync.fbb
        return t_amazonoutofsync

def to_t_private_deals_comparison(item):
    xstr = lambda s: s or ""
    t_pdcomp = TPdPriceComp()
    pdComp = item[0]
    catItem  = item[1]
    t_pdcomp.item_id = pdComp.item_id
    t_pdcomp.dealPrice = pdComp.dealPrice
    t_pdcomp.saholicPrice = pdComp.saholicPrice
    t_pdcomp.sdPrice = pdComp.sdPrice
    t_pdcomp.fkPrice = pdComp.fkPrice
    t_pdcomp.amazonPrice = pdComp.amazonPrice
    t_pdcomp.productName = xstr(catItem.brand)+" "+xstr(catItem.model_name)+" "+xstr(catItem.model_number)+" "+xstr(catItem.color)
    t_pdcomp.lastProcessedTimestamp = to_java_date(pdComp.lastProcessedTimestamp)
    return t_pdcomp
        
def to_t_snapdeal_marketplace_item(item):
    mpItem = item[1]
    dItem = item[2]
    t_sd_item = to_t_snapdeal_item(item)
    t_sd_item.marketplaceItems = to_t_marketplace_items(mpItem)
    t_sd_item.item = to_t_item(dItem)
    return t_sd_item
'''
def to_t_deal_tag(dealTag):
    t_deal_tag = TDealTag()
    t_deal_tag.id = dealTag.id
    t_deal_tag.name = dealTag.name
    return t_deal_tag

def to_t_item_tag(itemTag):
    t_item_tag = TItemTag()
    t_item_tag.itemId = itemTag.itemId
    t_item_tag.tagId = itemTag.tagId
    t_item_tag.startDate = to_java_date(itemTag.startDate)
    t_item_tag.endDate = to_java_date(itemTag.endDate)
    t_item_tag.status = itemTag.status
    return t_item_tag
'''

def to_t_flipkart_marketplace_item(item):
    mpItem = item[1]
    dItem = item[2]
    t_fk_item = to_t_flipkart_item(item)
    t_fk_item.marketplaceItems = to_t_marketplace_items(mpItem)
    t_fk_item.item = to_t_item(dItem)
    return t_fk_item

def to_t_competitor_pricing(compPricing):
    xstr = lambda s: s or ""
    item = compPricing[0]
    catItem = compPricing[1]
    t_comp = TCompetitorPricing()
    t_comp.productName = xstr(catItem.brand)+" "+xstr(catItem.model_name)+" "+xstr(catItem.model_number)+" "+xstr(catItem.color)
    t_comp.item_id = item.item_id
    t_comp.lowestSnapdealPrice = item.lowestSnapdealPrice
    t_comp.lowestFlipkartPrice = item.lowestFlipkartPrice
    t_comp.lowestAmazonPrice = item.lowestAmazonPrice
    t_comp.ourSnapdealPrice = item.ourSnapdealPrice
    t_comp.ourSnapdealOfferPrice = item.ourSnapdealOfferPrice
    t_comp.ourSnapdealInventory = item.ourSnapdealInventory
    t_comp.lowestSnapdealOfferPrice = item.lowestSnapdealOfferPrice
    if item.lowestSnapdealSeller is None:
        t_comp.lowestSnapdealSeller=''
    else:
        t_comp.lowestSnapdealSeller = item.lowestSnapdealSeller
    t_comp.lowestSnapdealSellerInventory = item.lowestSnapdealSellerInventory
    t_comp.ourFlipkartPrice = item.ourFlipkartPrice
    t_comp.ourFlipkartInventory = item.ourFlipkartInventory
    if item.lowestFlipkartSeller is None:
        t_comp.lowestFlipkartSeller=''
    else:
        t_comp.lowestFlipkartSeller = item.lowestFlipkartSeller
    t_comp.ourAmazonPrice = item.ourAmazonPrice
    t_comp.lowestAmazonPrice = item.lowestAmazonPrice
    if item.lowestAmazonSeller is None:
        t_comp.lowestAmazonSeller=''
    else:
        t_comp.lowestAmazonSeller = item.lowestAmazonSeller
    return t_comp

def to_t_amazon_promotion(amazonPromotion):
    t_amazonPromotion = TAmazonPromotion()
    t_amazonPromotion.sku = amazonPromotion.sku
    t_amazonPromotion.startDate = to_java_date(datetime.datetime.combine(amazonPromotion.startDate, datetime.datetime.min.time()))
    t_amazonPromotion.endDate = to_java_date(datetime.datetime.combine(amazonPromotion.endDate, datetime.datetime.min.time()))
    t_amazonPromotion.updatedOnMarketplace = to_java_date(amazonPromotion.updatedOnMarketplace)
    t_amazonPromotion.promotionActive = amazonPromotion.promotionActive
    t_amazonPromotion.addedOn = to_java_date(amazonPromotion.addedOn)
    t_amazonPromotion.standardPrice = amazonPromotion.standardPrice
    t_amazonPromotion.salePrice = amazonPromotion.salePrice
    t_amazonPromotion.stateId = amazonPromotion.stateId
    t_amazonPromotion.promotionType = amazonPromotion.promotionType
    return t_amazonPromotion

def to_t_Amazonlisted_promo(amazonDetails):
    amazonlisted = amazonDetails[0]
    fbaPromo = amazonDetails[1]
    fbbPromo = amazonDetails[2]
    fbgPromo = amazonDetails[3]
    fbdPromo = amazonDetails[4]
    t_amazon = to_t_Amazonlisted(amazonlisted)
    if not (fbaPromo is None or len(fbaPromo)==0):
        t_amazon.maxFbaSalePrice = fbaPromo[0].salePrice
    if not (fbbPromo is None or len(fbbPromo)==0):
        t_amazon.maxFbbSalePrice = fbbPromo[0].salePrice
    if not (fbgPromo is None or len(fbgPromo)==0):
        t_amazon.maxFbgSalePrice = fbgPromo[0].salePrice
    if not (fbdPromo is None or len(fbdPromo)==0):
        t_amazon.maxFbdSalePrice = fbdPromo[0].salePrice
    return t_amazon

def to_t_exclusive_affiliate_item_info(afItemInfo):
    tinfo = TExclusiveAffiliateItemInfo()
    tinfo.affiliateId = afItemInfo[0].affiliateId
    tinfo.active = afItemInfo[0].isActive
    tinfo.affiliateName = afItemInfo[1]
    tinfo.offerImageUrl = afItemInfo[0].offerUrl
    tinfo.offerText = afItemInfo[0].offerText
    tinfo.itemId = afItemInfo[0].itemId
    tinfo.mOfferImageUrl = afItemInfo[0].mOfferUrl
    tinfo.mOfferText = afItemInfo[0].mOfferText
    tinfo.affiliateUrl = afItemInfo[0].affiliateUrl
    return tinfo
    
def to_t_hsItem(hsItem):
    t_hsItem = THsItem()
    t_hsItem.itemId = hsItem.item_id
    t_hsItem.listingPrice = hsItem.selling_price
    return t_hsItem

def to_t_voiSnapdealItemInfo(voiSnapdealItemInfo):
    t_voiSnapdealItemInfo = TVoiSnapdealItemInfo()
    t_voiSnapdealItemInfo.item_id = voiSnapdealItemInfo.item_id
    t_voiSnapdealItemInfo.voiSkuAtSnapdeal = voiSnapdealItemInfo.voiSkuAtSnapdeal
    t_voiSnapdealItemInfo.sellingPriceSnapdeal = voiSnapdealItemInfo.sellingPriceSnapdeal
    t_voiSnapdealItemInfo.transferPriceSnapdeal = voiSnapdealItemInfo.transferPriceSnapdeal
    t_voiSnapdealItemInfo.fixedMargin = voiSnapdealItemInfo.fixedMargin
    t_voiSnapdealItemInfo.fixedMarginPercentage = voiSnapdealItemInfo.fixedMarginPercentage
    t_voiSnapdealItemInfo.logisticCostSnapdeal = voiSnapdealItemInfo.logisticCostSnapdeal
    t_voiSnapdealItemInfo.woodenPackagingCost = voiSnapdealItemInfo.woodenPackagingCost
    t_voiSnapdealItemInfo.weightSnapdeal = voiSnapdealItemInfo.weightSnapdeal
    return t_voiSnapdealItemInfo

def to_t_bulk_pricing(bulkPricing):
    t_bulkpricing = TBulkItemPricing()
    t_bulkpricing.id = bulkPricing.id
    t_bulkpricing.item_id = bulkPricing.item_id
    t_bulkpricing.quantity = bulkPricing.quantity
    t_bulkpricing.price = bulkPricing.price
    return t_bulkpricing

def to_t_categoryHsnCode(categoryHsnCode):
    t_categoryHsnCode = TCategoryHsnCode()
    t_categoryHsnCode.categoryId = categoryHsnCode.categoryId
    t_categoryHsnCode.hsnCode = categoryHsnCode.hsnCode
    t_categoryHsnCode.description = categoryHsnCode.description
    return t_categoryHsnCode

def to_t_dtr_pricing(dtrPricing):
    d_item, bulkPricingMap = dtrPricing
    t_dtr_pricing = TDtrPricing()
    if d_item is None:
        return t_dtr_pricing
    t_dtr_pricing.catalog_item_id = d_item.catalog_item_id
    t_dtr_pricing.bulkPricing = bulkPricingMap
    t_dtr_pricing.sellingPrice = d_item.sellingPrice
    t_dtr_pricing.minimumBuyQuantity = d_item.minimumBuyQuantity
    t_dtr_pricing.maximumBuyQuantity = d_item.maximumBuyQuantity
    return t_dtr_pricing