Subversion Repositories SmartDukaan

Rev

Rev 5110 | Rev 5305 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
94 ashish 1
'''
2
Created on 23-Mar-2010
3
 
4
@author: ashish
5
'''
5110 mandeep.dh 6
from shop2020.thriftpy.model.v1.catalog.ttypes import Item, ItemInventory, \
7
    Warehouse, VendorItemPricing, Vendor, Category, VendorItemMapping, \
8
    SourceItemPricing, Source, ItemType, \
9
    ProductNotificationRequest as TProductNotificationRequest, \
10
    ProductNotificationRequestCount as TProductNotificationRequestCount, \
11
    InventoryType, WarehouseType
12
from shop2020.utils.Utils import to_java_date
94 ashish 13
import time
14
 
15
def to_t_item(item):
16
    t_item = Item()
576 chandransh 17
    if item is None:
18
        return t_item
94 ashish 19
    t_item.id = item.id
963 chandransh 20
    t_item.productGroup = item.product_group
21
    t_item.brand = item.brand
591 chandransh 22
    t_item.modelNumber = item.model_number
23
    t_item.modelName = item.model_name
609 chandransh 24
    t_item.color = item.color
591 chandransh 25
    t_item.category = item.category
122 ashish 26
    t_item.catalogItemId = item.catalog_item_id
27
    t_item.weight = item.weight
28
    t_item.featureId = item.feature_id
29
    t_item.featureDescription = item.feature_description
30
    if item.startDate:
31
        t_item.startDate = to_java_date(item.startDate)
5217 amit.gupta 32
    if item.comingSoonStartDate:
33
        t_item.comingSoonStartDate = to_java_date(item.comingSoonStartDate)
34
 
35
    print "Convertors  : t_item.comingSoonStartDate" + `t_item.comingSoonStartDate`
36
 
37
    if item.expectedArrivalDate:
38
        t_item.expectedArrivalDate = to_java_date(item.expectedArrivalDate)
39
    print "Convertors  : t_item.expectedArrivalDate" + `t_item.expectedArrivalDate`
122 ashish 40
    if item.addedOn:
41
        t_item.addedOn = to_java_date(item.addedOn)
609 chandransh 42
    if item.updatedOn:
43
        t_item.updatedOn = to_java_date(item.updatedOn)
122 ashish 44
    t_item.itemStatus = item.status
2035 rajveer 45
    t_item.status_description = item.status_description
609 chandransh 46
 
501 rajveer 47
    if item.sellingPrice:
609 chandransh 48
        t_item.sellingPrice = item.sellingPrice
630 chandransh 49
    if item.mrp:
501 rajveer 50
        t_item.mrp = item.mrp    
94 ashish 51
    t_item.itemInventory = to_t_item_inventory(item.currentInventory, item.id)
122 ashish 52
 
2028 ankur.sing 53
    if item.comments:
54
        t_item.comments = item.comments
609 chandransh 55
    if item.bestDealText:
56
        t_item.bestDealText = item.bestDealText
57
    if item.bestDealValue:
58
        t_item.bestDealValue = item.bestDealValue
59
 
1910 varun.gupt 60
    t_item.defaultForEntity = item.defaultForEntity
122 ashish 61
    t_item.otherInfo = to_t_other_info(item)
2065 ankur.sing 62
    t_item.bestSellingRank = item.bestSellingRank
2251 ankur.sing 63
    t_item.risky = item.risky
3355 chandransh 64
    t_item.expectedDelay = item.expectedDelay
4762 phani.kuma 65
    if item.preferredWarehouse:
66
        t_item.preferredWarehouse = int(item.preferredWarehouse)
67
    if item.defaultWarehouse:
68
        t_item.defaultWarehouse = int(item.defaultWarehouse)
4406 anupam.sin 69
    t_item.isWarehousePreferenceSticky = item.isWarehousePreferenceSticky
4295 varun.gupt 70
    t_item.warrantyPeriod = item.warranty_period
4506 phani.kuma 71
    t_item.preferredVendor = item.preferredVendor
5110 mandeep.dh 72
    t_item.type = ItemType._NAMES_TO_VALUES[item.type]
2065 ankur.sing 73
 
94 ashish 74
    return t_item
122 ashish 75
 
76
def to_t_other_info(item):
77
    t_other_info = {}
78
    for item_info in item.iteminfo:
79
        t_other_info[item_info.key] = item_info.value
94 ashish 80
 
81
def to_t_item_inventory(item_inventory_list, item_id):
82
    t_item_inventory = ItemInventory()
83
    t_item_inventory.id = item_id
84
    t_item_inventory.availability = {}
4431 phani.kuma 85
    t_item_inventory.reserved = {}
94 ashish 86
    for inventory_item in item_inventory_list:
122 ashish 87
        t_item_inventory.availability[inventory_item.warehouse.id] = inventory_item.availibility
4431 phani.kuma 88
        t_item_inventory.reserved[inventory_item.warehouse.id] = inventory_item.reserved
483 rajveer 89
#        need review again        
90
#        if inventory_item.checkedOn:
91
#            t_item_inventory.lastCheckedOn = to_java_date(inventory_item.checkedOn)
94 ashish 92
    return t_item_inventory
93
 
94
def to_t_warehouse(warehouse):
95
    t_warehouse = Warehouse()
96
    t_warehouse.id = warehouse.id
759 chandransh 97
    t_warehouse.displayName = warehouse.displayName
94 ashish 98
    t_warehouse.location = warehouse.location
483 rajveer 99
    t_warehouse.tinNumber = warehouse.tinNumber
100
    t_warehouse.pincode = warehouse.pincode
2841 chandransh 101
    t_warehouse.billingType = warehouse.billingType
5110 mandeep.dh 102
    t_warehouse.vendor = to_t_vendor(warehouse.vendor)
103
    t_warehouse.billingWarehouseId = warehouse.billingWarehouseId
104
    t_warehouse.shippingWarehouseId = warehouse.shippingWarehouseId
105
    t_warehouse.isAvailabilityMonitored = warehouse.isAvailabilityMonitored
106
    t_warehouse.transferDelayInHours = warehouse.transferDelayInHours
107
    t_warehouse.inventoryType = InventoryType._NAMES_TO_VALUES[warehouse.inventoryType]
108
    t_warehouse.warehouseType = WarehouseType._NAMES_TO_VALUES[warehouse.warehouseType]
494 rajveer 109
    if warehouse.vendorString:
483 rajveer 110
        t_warehouse.vendorString = warehouse.vendorString
122 ashish 111
    if warehouse.addedOn:
112
        t_warehouse.addedOn = to_java_date(warehouse.addedOn)
483 rajveer 113
    if warehouse.lastCheckedOn:
114
        t_warehouse.lastCheckedOn = to_java_date(warehouse.lastCheckedOn)
122 ashish 115
    return t_warehouse
1341 chandransh 116
 
117
def to_t_vendor(vendor):
118
    t_vendor = Vendor()
119
    t_vendor.id = vendor.id
120
    t_vendor.name = vendor.name
1348 chandransh 121
    return t_vendor
1341 chandransh 122
 
123
def to_t_vendor_item_pricing(vendor_item_pricing):
124
    t_vendor_item_pricing = VendorItemPricing()
1348 chandransh 125
    t_vendor_item_pricing.vendorId = vendor_item_pricing.vendor.id
126
    t_vendor_item_pricing.itemId = vendor_item_pricing.item.id
1341 chandransh 127
    t_vendor_item_pricing.transferPrice = vendor_item_pricing.transfer_price
128
    t_vendor_item_pricing.dealerPrice = vendor_item_pricing.dealerPrice
1348 chandransh 129
    t_vendor_item_pricing.mop = vendor_item_pricing.mop
1970 rajveer 130
    return t_vendor_item_pricing
131
 
2116 ankur.sing 132
def to_t_vendor_item_mapping(vendor_item_mapping):
133
    t_vendor_item_mapping = VendorItemMapping()
134
    t_vendor_item_mapping.vendorId = vendor_item_mapping.vendor.id
135
    t_vendor_item_mapping.itemId = vendor_item_mapping.item.id
136
    t_vendor_item_mapping.itemKey = vendor_item_mapping.item_key
2120 ankur.sing 137
    return t_vendor_item_mapping
2116 ankur.sing 138
 
139
 
1970 rajveer 140
def to_t_category(category):
141
    t_category = Category()
142
    t_category.id = category.id
143
    t_category.label = category.label
144
    t_category.description = category.description
145
    t_category.parent_category_id = category.parent_category_id
4762 phani.kuma 146
    t_category.display_name = category.display_name
3557 rajveer 147
    return t_category
148
 
149
def to_t_source_item_pricing(source_item_pricing):
150
    t_source_item_pricing = SourceItemPricing()
151
    t_source_item_pricing.sourceId = source_item_pricing.source.id
152
    t_source_item_pricing.itemId = source_item_pricing.item.id
153
    t_source_item_pricing.mrp = source_item_pricing.mrp
154
    t_source_item_pricing.sellingPrice = source_item_pricing.sellingPrice
155
    return t_source_item_pricing
156
 
157
def to_t_source(source):
158
    t_source = Source()
159
    t_source.id = source.id
160
    t_source.name = source.name
161
    t_source.identifier = source.identifier
162
    return t_source
4295 varun.gupt 163
 
164
def to_t_product_notification_request(product_notification_request):
165
    t_product_notification_request = TProductNotificationRequest()
166
 
167
    if product_notification_request:
168
        t_product_notification_request.item = to_t_item(product_notification_request.item)
169
        t_product_notification_request.email = product_notification_request.email
170
        t_product_notification_request.addedOn = to_java_date(product_notification_request.addedOn)
171
 
172
    return t_product_notification_request
173
 
174
def to_t_product_notification_request_count(product_notification_request_count):
175
 
176
    t_product_notification_request_count = TProductNotificationRequestCount()
177
 
178
    if product_notification_request_count:
179
        item, count = product_notification_request_count
180
        t_product_notification_request_count.item = to_t_item(item)
181
        t_product_notification_request_count.count = count
182
 
183
    return t_product_notification_request_count