Subversion Repositories SmartDukaan

Rev

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

'''
Created on 23-Mar-2010

@author: ashish
'''
from shop2020.thriftpy.model.v1.catalog.ttypes import Item, ItemInventory, \
    Warehouse, VendorItemPricing, Vendor, Category, VendorItemMapping, \
    SourceItemPricing, Source, ItemType, \
    ProductNotificationRequest as TProductNotificationRequest, \
    ProductNotificationRequestCount as TProductNotificationRequestCount, \
    InventoryType, WarehouseType
from shop2020.utils.Utils import to_java_date
import time

def to_t_item(item):
    t_item = Item()
    if item is None:
        return t_item
    t_item.id = item.id
    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.bestDealValue:
        t_item.bestDealValue = item.bestDealValue
    
    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
    
    return t_item

def to_t_item_inventory(item_inventory_list, item_id):
    t_item_inventory = ItemInventory()
    t_item_inventory.id = item_id
    t_item_inventory.availability = {}
    t_item_inventory.reserved = {}
    for inventory_item in item_inventory_list:
        t_item_inventory.availability[inventory_item.warehouse.id] = inventory_item.availibility
        t_item_inventory.reserved[inventory_item.warehouse.id] = inventory_item.reserved
#        need review again        
#        if inventory_item.checkedOn:
#            t_item_inventory.lastCheckedOn = to_java_date(inventory_item.checkedOn)
    return t_item_inventory

def to_t_warehouse(warehouse):
    t_warehouse = Warehouse()
    t_warehouse.id = warehouse.id
    t_warehouse.displayName = warehouse.displayName
    t_warehouse.location = warehouse.location
    t_warehouse.tinNumber = warehouse.tinNumber
    t_warehouse.pincode = warehouse.pincode
    t_warehouse.billingType = warehouse.billingType
    t_warehouse.vendor = to_t_vendor(warehouse.vendor)
    t_warehouse.billingWarehouseId = warehouse.billingWarehouseId
    t_warehouse.shippingWarehouseId = warehouse.shippingWarehouseId
    t_warehouse.isAvailabilityMonitored = warehouse.isAvailabilityMonitored
    t_warehouse.transferDelayInHours = warehouse.transferDelayInHours
    t_warehouse.inventoryType = InventoryType._NAMES_TO_VALUES[warehouse.inventoryType]
    t_warehouse.warehouseType = WarehouseType._NAMES_TO_VALUES[warehouse.warehouseType]
    if warehouse.vendorString:
        t_warehouse.vendorString = warehouse.vendorString
    if warehouse.addedOn:
        t_warehouse.addedOn = to_java_date(warehouse.addedOn)
    if warehouse.lastCheckedOn:
        t_warehouse.lastCheckedOn = to_java_date(warehouse.lastCheckedOn)
    return t_warehouse

def to_t_vendor(vendor):
    t_vendor = Vendor()
    t_vendor.id = vendor.id
    t_vendor.name = vendor.name
    return t_vendor

def to_t_vendor_item_pricing(vendor_item_pricing):
    t_vendor_item_pricing = VendorItemPricing()
    t_vendor_item_pricing.vendorId = vendor_item_pricing.vendor.id
    t_vendor_item_pricing.itemId = vendor_item_pricing.item.id
    t_vendor_item_pricing.transferPrice = vendor_item_pricing.transfer_price
    t_vendor_item_pricing.dealerPrice = vendor_item_pricing.dealerPrice
    t_vendor_item_pricing.mop = vendor_item_pricing.mop
    return t_vendor_item_pricing

def to_t_vendor_item_mapping(vendor_item_mapping):
    t_vendor_item_mapping = VendorItemMapping()
    t_vendor_item_mapping.vendorId = vendor_item_mapping.vendor.id
    t_vendor_item_mapping.itemId = vendor_item_mapping.item.id
    t_vendor_item_mapping.itemKey = vendor_item_mapping.item_key
    return t_vendor_item_mapping
    

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