Subversion Repositories SmartDukaan

Rev

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