Subversion Repositories SmartDukaan

Rev

Rev 5135 | 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 22-Mar-2010
3
 
4
@author: ashish
5
'''
4873 mandeep.dh 6
from elixir import metadata, setup_all
94 ashish 7
from elixir.entity import Entity
8
from elixir.fields import Field
4873 mandeep.dh 9
from elixir.options import using_options, using_table_options
10
from elixir.relationships import OneToMany, ManyToOne, ManyToMany
11
from sqlalchemy import create_engine
4897 rajveer 12
from sqlalchemy.types import Integer, String, DateTime, Float, Boolean, Text,\
5110 mandeep.dh 13
    Date, Enum
4873 mandeep.dh 14
import datetime
15
import elixir
94 ashish 16
 
1308 chandransh 17
class Vendor(Entity):
18
    id = Field(Integer, primary_key=True, autoincrement=True)
19
    name = Field(String(50))
5110 mandeep.dh 20
    warehouses = OneToMany('Warehouse')
1308 chandransh 21
    using_options(shortnames=True)
22
    using_table_options(mysql_engine="InnoDB")
23
 
94 ashish 24
class Warehouse(Entity):
122 ashish 25
    id = Field(Integer, primary_key=True, autoincrement=True)
759 chandransh 26
    displayName = Field(String(50))
483 rajveer 27
    location = Field(String(200))
122 ashish 28
    addedOn = Field(DateTime)
483 rajveer 29
    lastCheckedOn = Field(DateTime)
30
    tinNumber = Field(String(50))
31
    pincode = Field(String(10))
32
    vendorString = Field(String(50))
5110 mandeep.dh 33
    badInventory = OneToMany('BadInventorySnapshot')
94 ashish 34
    inventory = OneToMany('CurrentInventorySnapshot')
35
    inventoryHistory = OneToMany('ItemInventoryHistory')
643 chandransh 36
    logisticsLocation = Field(Integer)
5110 mandeep.dh 37
    vendor = ManyToOne('Vendor')
2841 chandransh 38
    billingType = Field(Integer)
5110 mandeep.dh 39
    inventoryType = Field(Enum('GOOD', 'BAD', 'VIRTUAL'))
40
    warehouseType = Field(Enum('OURS', 'THIRD_PARTY'))
41
    shippingWarehouseId = Field(Integer)
42
    billingWarehouseId = Field(Integer)
43
    transferDelayInHours = Field(Integer)
44
    isAvailabilityMonitored = Field(Boolean)
746 rajveer 45
    using_options(shortnames=True)
46
    using_table_options(mysql_engine="InnoDB")
94 ashish 47
 
48
    def __repr__(self):
49
        return "<warehouse>%s</warehouse>" %(self.location)
50
 
122 ashish 51
    @property
52
    def all_items(self):
53
        items = []
54
        for ci in self.inventory:
55
            items.append(ci.item)
56
        return items 
626 chandransh 57
 
58
class EntityIDGenerator(Entity):
59
    id=Field(Integer, primary_key=True)
60
    using_options(shortnames=True)
746 rajveer 61
    using_table_options(mysql_engine="InnoDB")
122 ashish 62
 
94 ashish 63
class Item(Entity):
122 ashish 64
    id = Field(Integer, primary_key=True, autoincrement=True)
963 chandransh 65
    product_group = Field(String(100))
4917 phani.kuma 66
    brand = Field(String(100), default='', server_default='')
67
    model_number = Field(String(50), default='', server_default='')
68
    model_name = Field(String(100), default='', server_default='')
69
    color = Field(String(20), default='', server_default='')
70
    category = Field(Integer, default=0, server_default="0")
483 rajveer 71
    comments = Field(String(200))
122 ashish 72
    catalog_item_id = Field(Integer)
73
    feature_id = Field(Integer)
74
    feature_description = Field(String(200))
483 rajveer 75
    mrp = Field(Float)
76
    sellingPrice = Field(Float)
77
    weight = Field(Float)
122 ashish 78
    addedOn = Field(DateTime)
609 chandransh 79
    updatedOn = Field(DateTime)
122 ashish 80
    startDate = Field(DateTime)
81
    retireDate = Field(DateTime)
5217 amit.gupta 82
    comingSoonStartDate = Field(DateTime)
83
    expectedArrivalDate = Field(DateTime)
483 rajveer 84
    status = Field(Integer)
2035 rajveer 85
    status_description = Field(String(100))
609 chandransh 86
    bestDealText = Field(String(100))
630 chandransh 87
    bestDealValue = Field(Float)
621 chandransh 88
    bestSellingRank = Field(Integer)
94 ashish 89
    currentInventory = OneToMany('CurrentInventorySnapshot')
90
    inventoryHistory = OneToMany('ItemInventoryHistory')
103 ashish 91
    iteminfo = OneToMany("ItemInfo")
92
    statusChangeLog = OneToMany("ItemChangeLog")
4762 phani.kuma 93
    preferredWarehouse = Field(Integer)
1910 varun.gupt 94
    defaultForEntity = Field(Boolean)
2251 ankur.sing 95
    risky = Field(Boolean)
3355 chandransh 96
    expectedDelay = Field(Integer)
4295 varun.gupt 97
    warranty_period = Field(Integer)
4762 phani.kuma 98
    defaultWarehouse = Field(Integer)
4406 anupam.sin 99
    isWarehousePreferenceSticky = Field(Boolean)
4506 phani.kuma 100
    preferredVendor = Field(Integer)
5135 mandeep.dh 101
    type = Field(Enum('SERIALIZED', 'NON_SERIALIZED'), default = 'NON_SERIALIZED', server_default='NON_SERIALIZED')
746 rajveer 102
    using_options(shortnames=True)
103
    using_table_options(mysql_engine="InnoDB")
103 ashish 104
 
94 ashish 105
    def __repr__(self):
122 ashish 106
        return "<Item>%d</item>" % (self.id)
94 ashish 107
 
122 ashish 108
    @property
94 ashish 109
    def get_total_inventory(self):
110
        if self.currentInventory:
111
            i = 0
112
            for entry in self.currentInventory:
113
                i += entry.availability
114
            return i
115
 
116
        else:
117
            return 0;
103 ashish 118
 
122 ashish 119
    @property
94 ashish 120
    def get_all_warehouses(self):
1308 chandransh 121
        return [ci.warehouse for ci in self.currentInventory]
122
 
123
class VendorItemMapping(Entity):
124
    vendor = ManyToOne('Vendor', primary_key=True)
125
    item_key = Field(String(200), primary_key=True)
126
    item = ManyToOne('Item')
127
    using_options(shortnames=True)
128
    using_table_options(mysql_engine="InnoDB")
129
 
130
class VendorItemPricing(Entity):
131
    vendor = ManyToOne('Vendor', primary_key=True)
132
    item = ManyToOne('Item', primary_key=True)
133
    mop = Field(Float)
134
    dealerPrice = Field(Float)
135
    transfer_price = Field(Float)
136
    using_options(shortnames=True)
137
    using_table_options(mysql_engine="InnoDB")
138
 
4897 rajveer 139
class VendorItemProcurementDelay(Entity):
140
    vendor = ManyToOne('Vendor', primary_key=True)
141
    item = ManyToOne('Item', primary_key=True)
142
    procurementDelay = Field(Integer)
143
    using_options(shortnames=True)
144
    using_table_options(mysql_engine="InnoDB")
145
 
4979 rajveer 146
class VendorHolidays(Entity):
147
    vendor = ManyToOne('Vendor', primary_key=True)
148
    holidayType = Field(Integer, primary_key=True, autoincrement=False)
149
    holidayValue = Field(Integer, primary_key=True, autoincrement=False)
150
    occasion = Field(String(100))
151
    using_options(shortnames=True)
152
    using_table_options(mysql_engine="InnoDB")
4897 rajveer 153
 
103 ashish 154
class ItemInfo(Entity):
122 ashish 155
    id = Field(Integer, primary_key=True, autoincrement=True)
103 ashish 156
    key = Field(String(30))
157
    value = Field(String(100))
158
    item = ManyToOne("Item")
746 rajveer 159
    using_options(shortnames=True)
160
    using_table_options(mysql_engine="InnoDB")
103 ashish 161
 
162
    def __repr__(self):
163
        return "<ItemInfo><key>%s</key><value>%s</value></ItemInfo>" % (self.key, self.value)
115 ashish 164
 
94 ashish 165
 
166
class CurrentInventorySnapshot(Entity):
870 chandransh 167
    item = ManyToOne("Item", primary_key=True)
168
    warehouse = ManyToOne("Warehouse", primary_key=True)
94 ashish 169
    availibility = Field(Integer)
870 chandransh 170
    reserved = Field(Integer)
746 rajveer 171
    using_options(shortnames=True)
172
    using_table_options(mysql_engine="InnoDB")
94 ashish 173
 
174
    def __repr__(self):
175
        return "<current inventory><availability> %s </availability><time>%s</time><item>%s</item><warehouse>%s</warehouse></current inventory>" %(self.availibility, self.checkedOn, self.item, self.warehouse)
176
 
5110 mandeep.dh 177
class BadInventorySnapshot(Entity):
178
    item = ManyToOne("Item", primary_key=True)
179
    warehouse = ManyToOne("Warehouse", primary_key=True)
180
    availability = Field(Integer)
181
    using_options(shortnames=True)
182
    using_table_options(mysql_engine="InnoDB")
183
 
94 ashish 184
class ItemInventoryHistory(Entity):
122 ashish 185
    id = Field(Integer, primary_key=True, autoincrement = True)    
94 ashish 186
    timestamp = Field(DateTime, default=datetime.datetime.now())
187
    availibility = Field(Integer)
188
    item = ManyToOne("Item")
189
    warehouse = ManyToOne("Warehouse")
746 rajveer 190
    using_options(shortnames=True)
191
    using_table_options(mysql_engine="InnoDB")
94 ashish 192
 
193
    def __repr__(self):
194
        pass
103 ashish 195
 
196
class ItemChangeLog(Entity):
122 ashish 197
    id = Field(Integer, primary_key=True, autoincrement=True)
103 ashish 198
    old_status = Field(Integer)
199
    new_status = Field(Integer)
1308 chandransh 200
    timestamp = Field(DateTime)
103 ashish 201
    item = ManyToOne("Item")
746 rajveer 202
    using_options(shortnames=True)
203
    using_table_options(mysql_engine="InnoDB")
94 ashish 204
 
103 ashish 205
    def __repr__(self):
206
        return "<Log><id>%d</id><item>%d</item><old_status>%d</old_status><new_status>%d</new_status></Log>" %(self.id,self.item.id, self.old_status, self.new_status)    
94 ashish 207
 
635 rajveer 208
class Category(Entity):
1970 rajveer 209
    id = Field(Integer, primary_key=True, autoincrement=False)
210
    label = Field(String(50))
211
    description = Field(String(200))
212
    parent_category_id = Field(Integer)
4762 phani.kuma 213
    display_name = Field(String(50))
746 rajveer 214
    using_options(shortnames=True)
215
    using_table_options(mysql_engine="InnoDB")
1970 rajveer 216
 
3008 rajveer 217
class SimilarItems(Entity):
218
    item = ManyToOne('Item', primary_key=True)
219
    catalog_item_id = Field(Integer, primary_key=True, autoincrement=False)
220
    using_options(shortnames=True)
221
    using_table_options(mysql_engine="InnoDB")
222
 
3079 rajveer 223
class ProductNotification(Entity):
224
    item = ManyToOne('Item', primary_key=True)
225
    email = Field(String(100), primary_key=True, autoincrement=False)
226
    addedOn = Field(DateTime, primary_key=True, autoincrement=False) 
227
    using_options(shortnames=True)
228
    using_table_options(mysql_engine="InnoDB")
3557 rajveer 229
 
230
class Source(Entity):
231
    id = Field(Integer, primary_key=True, autoincrement=True)
232
    name = Field(String(50))
233
    identifier = Field(String(100))
234
    using_options(shortnames=True)
235
    using_table_options(mysql_engine="InnoDB")
236
 
237
class SourceItemPricing(Entity):
238
    source = ManyToOne('Source', primary_key=True)
239
    item = ManyToOne('Item', primary_key=True)
240
    mrp = Field(Float)
241
    sellingPrice = Field(Float)
242
    using_options(shortnames=True)
243
    using_table_options(mysql_engine="InnoDB")
746 rajveer 244
 
4649 phani.kuma 245
class AuthorizationLog(Entity):
246
    id = Field(Integer, primary_key=True, autoincrement = True)    
247
    timestamp = Field(DateTime, default=datetime.datetime.now())
248
    item = ManyToOne('Item')
249
    username = Field(String(30))
250
    reason = Field(Text)
251
    using_options(shortnames=True)
252
    using_table_options(mysql_engine="InnoDB")
253
 
4873 mandeep.dh 254
class MissedInventoryUpdate(Entity):
4748 mandeep.dh 255
    id = Field(Integer, primary_key=True, autoincrement=True)
256
    itemKey = Field(String(200))
4873 mandeep.dh 257
    quantity = Field(Integer)
4748 mandeep.dh 258
    warehouseId = Field(Integer)
4873 mandeep.dh 259
    isIgnored = Field(Boolean)
260
    timestamp = Field(DateTime)
4748 mandeep.dh 261
    using_options(shortnames=True)
262
    using_table_options(mysql_engine="InnoDB")
263
 
3187 rajveer 264
def initialize(dbname='catalog', db_hostname="localhost"):
746 rajveer 265
    #metadata.bind = "sqlite:///inventory-new.sqlite" #need to read it from configserver.
1122 chandransh 266
    #metadata.bind = 'mysql://root:shop2020@localhost/catalog'
3187 rajveer 267
    engine = create_engine('mysql://root:shop2020@' + db_hostname + '/' + dbname, pool_recycle=7200)
1122 chandransh 268
    metadata.bind = engine
94 ashish 269
    metadata.bind.echo = True
270
    setup_all(True)
115 ashish 271
 
272
if __name__=="__main__":
273
    initialize()