Subversion Repositories SmartDukaan

Rev

Rev 3089 | Rev 3355 | 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
'''
2841 chandransh 6
import datetime
7
import elixir
94 ashish 8
from elixir.entity import Entity
9
from elixir.fields import Field
2841 chandransh 10
from sqlalchemy.types import Integer, String, DateTime, Float, Boolean
1122 chandransh 11
from sqlalchemy import create_engine
94 ashish 12
from elixir.relationships import OneToMany, ManyToOne
2841 chandransh 13
from elixir.options import using_options, using_table_options
14
from elixir import metadata, setup_all
94 ashish 15
 
1308 chandransh 16
class Vendor(Entity):
17
    id = Field(Integer, primary_key=True, autoincrement=True)
18
    name = Field(String(50))
19
    warehouses = OneToMany('Warehouse')
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)
1308 chandransh 36
    vendor = ManyToOne('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
    mop = Field(Float)
70
    sellingPrice = Field(Float)
609 chandransh 71
    dealerPrice = Field(Float)
724 chandransh 72
    transfer_price = Field(Float)
483 rajveer 73
    weight = Field(Float)
122 ashish 74
    addedOn = Field(DateTime)
609 chandransh 75
    updatedOn = Field(DateTime)
122 ashish 76
    startDate = Field(DateTime)
77
    retireDate = Field(DateTime)
483 rajveer 78
    status = Field(Integer)
2035 rajveer 79
    status_description = Field(String(100))
609 chandransh 80
    bestDealText = Field(String(100))
630 chandransh 81
    bestDealValue = Field(Float)
621 chandransh 82
    bestSellingRank = Field(Integer)
94 ashish 83
    currentInventory = OneToMany('CurrentInventorySnapshot')
84
    inventoryHistory = OneToMany('ItemInventoryHistory')
103 ashish 85
    iteminfo = OneToMany("ItemInfo")
86
    statusChangeLog = OneToMany("ItemChangeLog")
724 chandransh 87
    hotspotCategory = Field(String(50))
1416 chandransh 88
    preferredWarehouse = Field(String(50))
1910 varun.gupt 89
    defaultForEntity = Field(Boolean)
2251 ankur.sing 90
    risky = Field(Boolean)
746 rajveer 91
    using_options(shortnames=True)
92
    using_table_options(mysql_engine="InnoDB")
103 ashish 93
 
94 ashish 94
    def __repr__(self):
122 ashish 95
        return "<Item>%d</item>" % (self.id)
94 ashish 96
 
122 ashish 97
    @property
94 ashish 98
    def get_total_inventory(self):
99
        if self.currentInventory:
100
            i = 0
101
            for entry in self.currentInventory:
102
                i += entry.availability
103
            return i
104
 
105
        else:
106
            return 0;
103 ashish 107
 
122 ashish 108
    @property
94 ashish 109
    def get_all_warehouses(self):
1308 chandransh 110
        return [ci.warehouse for ci in self.currentInventory]
111
 
112
class VendorItemMapping(Entity):
113
    vendor = ManyToOne('Vendor', primary_key=True)
114
    item_key = Field(String(200), primary_key=True)
115
    item = ManyToOne('Item')
1352 chandransh 116
    vendor_category = Field(String(50))
1308 chandransh 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)
746 rajveer 183
    using_options(shortnames=True)
184
    using_table_options(mysql_engine="InnoDB")
1970 rajveer 185
 
3008 rajveer 186
class SimilarItems(Entity):
187
    item = ManyToOne('Item', primary_key=True)
188
    catalog_item_id = Field(Integer, primary_key=True, autoincrement=False)
189
    using_options(shortnames=True)
190
    using_table_options(mysql_engine="InnoDB")
191
 
3079 rajveer 192
class ProductNotification(Entity):
193
    item = ManyToOne('Item', primary_key=True)
194
    email = Field(String(100), primary_key=True, autoincrement=False)
195
    addedOn = Field(DateTime, primary_key=True, autoincrement=False) 
196
    using_options(shortnames=True)
197
    using_table_options(mysql_engine="InnoDB")
746 rajveer 198
 
3187 rajveer 199
def initialize(dbname='catalog', db_hostname="localhost"):
746 rajveer 200
    #metadata.bind = "sqlite:///inventory-new.sqlite" #need to read it from configserver.
1122 chandransh 201
    #metadata.bind = 'mysql://root:shop2020@localhost/catalog'
3187 rajveer 202
    engine = create_engine('mysql://root:shop2020@' + db_hostname + '/' + dbname, pool_recycle=7200)
1122 chandransh 203
    metadata.bind = engine
94 ashish 204
    metadata.bind.echo = True
205
    setup_all(True)
115 ashish 206
 
207
if __name__=="__main__":
208
    initialize()