Subversion Repositories SmartDukaan

Rev

Rev 386 | Rev 494 | 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
import time
from shop2020.utils.Utils import to_java_date

def to_t_item(item):
    t_item = Item()
    t_item.id = item.id
    t_item.catalogItemId = item.catalog_item_id
    t_item.vendorItemId = item.vendor_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.addedOn:
        t_item.addedOn = to_java_date(item.addedOn)
    t_item.itemStatus = item.status
    if item.prices:
        t_item.price = {}
        for price in item.prices:
            t_item.price[price.warehouse_id] = price.price
    t_item.itemInventory = to_t_item_inventory(item.currentInventory, item.id)
    
    t_item.otherInfo = to_t_other_info(item)
    return t_item

def to_t_other_info(item):
    t_other_info = {}
    for item_info in item.iteminfo:
        t_other_info[item_info.key] = item_info.value
    
def to_t_item_inventory(item_inventory_list, item_id):
    t_item_inventory = ItemInventory()
    t_item_inventory.id = item_id
    t_item_inventory.availability = {}
    for inventory_item in item_inventory_list:
        t_item_inventory.availability[inventory_item.warehouse.id] = inventory_item.availibility
#        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.location = warehouse.location
    t_warehouse.warehouseStatus = warehouse.status
    t_warehouse.tinNumber = warehouse.tinNumber
    t_warehouse.pincode = warehouse.pincode
    if t_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