Subversion Repositories SmartDukaan

Rev

Rev 100 | Rev 122 | 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 Category, Item,\
    ItemInventory, Warehouse, Vendor
import time

def to_t_category(category):
    t_category = Category()
    t_category.id = category.id
    t_category.name = category.name
    t_category.isTopLevel = False
    if category.isRoot == 1:
        t_category.isTopLevel = True
    t_category.addedOn = int(time.mktime(category.addedOn.timetuple()))
    
    if category.parent:
        t_category.parent_id = category.parent.id
    if category.children:
        t_category.childCategories = []
        for child in category.children:
            t_category.childCategories.append(child.id)
    return t_category

def to_t_item(item):
    t_item = Item()
    t_item.id = item.id
    t_item.category_id = item.category.id
    t_item.itemInventory = to_t_item_inventory(item.currentInventory, item.id)
    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 = {}
    for inventory_item in item_inventory_list:
        t_item_inventory.availability[inventory_item.Warehouse.id] = inventory_item.availibility
    #TODO:- populate itemattribs here
    return t_item_inventory

def to_t_warehouse(warehouse):
    t_warehouse = Warehouse()
    t_warehouse.id = warehouse.id
    t_warehouse.location = warehouse.location
    #todo - add vendors as well here
    
def to_t_vendor(vendor):
    t_vendor = Vendor()
    t_vendor.id = vendor.id
    t_vendor.name = vendor.name