Subversion Repositories SmartDukaan

Rev

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