Subversion Repositories SmartDukaan

Rev

Rev 3187 | Rev 3557 | 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)
3355 chandransh 91
    expectedDelay = 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')
1352 chandransh 117
    vendor_category = Field(String(50))
1308 chandransh 118
    using_options(shortnames=True)
119
    using_table_options(mysql_engine="InnoDB")
120
 
121
class VendorItemPricing(Entity):
122
    vendor = ManyToOne('Vendor', primary_key=True)
123
    item = ManyToOne('Item', primary_key=True)
124
    mop = Field(Float)
125
    dealerPrice = Field(Float)
126
    transfer_price = Field(Float)
127
    using_options(shortnames=True)
128
    using_table_options(mysql_engine="InnoDB")
129
 
103 ashish 130
class ItemInfo(Entity):
122 ashish 131
    id = Field(Integer, primary_key=True, autoincrement=True)
103 ashish 132
    key = Field(String(30))
133
    value = Field(String(100))
134
    item = ManyToOne("Item")
746 rajveer 135
    using_options(shortnames=True)
136
    using_table_options(mysql_engine="InnoDB")
103 ashish 137
 
138
    def __repr__(self):
139
        return "<ItemInfo><key>%s</key><value>%s</value></ItemInfo>" % (self.key, self.value)
115 ashish 140
 
94 ashish 141
 
142
class CurrentInventorySnapshot(Entity):
115 ashish 143
    #id = Field(Integer, primary_key=True)
483 rajveer 144
    #checkedOn = Field(DateTime, default=datetime.datetime.now())
870 chandransh 145
    item = ManyToOne("Item", primary_key=True)
146
    warehouse = ManyToOne("Warehouse", primary_key=True)
94 ashish 147
    availibility = Field(Integer)
870 chandransh 148
    reserved = Field(Integer)
746 rajveer 149
    using_options(shortnames=True)
150
    using_table_options(mysql_engine="InnoDB")
94 ashish 151
 
152
    def __repr__(self):
153
        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)
154
 
155
class ItemInventoryHistory(Entity):
122 ashish 156
    id = Field(Integer, primary_key=True, autoincrement = True)    
94 ashish 157
    timestamp = Field(DateTime, default=datetime.datetime.now())
158
    availibility = Field(Integer)
159
    item = ManyToOne("Item")
160
    warehouse = ManyToOne("Warehouse")
746 rajveer 161
    using_options(shortnames=True)
162
    using_table_options(mysql_engine="InnoDB")
94 ashish 163
 
164
    def __repr__(self):
165
        pass
103 ashish 166
 
167
class ItemChangeLog(Entity):
122 ashish 168
    id = Field(Integer, primary_key=True, autoincrement=True)
103 ashish 169
    old_status = Field(Integer)
170
    new_status = Field(Integer)
1308 chandransh 171
    timestamp = Field(DateTime)
103 ashish 172
    item = ManyToOne("Item")
746 rajveer 173
    using_options(shortnames=True)
174
    using_table_options(mysql_engine="InnoDB")
94 ashish 175
 
103 ashish 176
    def __repr__(self):
177
        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 178
 
635 rajveer 179
class Category(Entity):
1970 rajveer 180
    id = Field(Integer, primary_key=True, autoincrement=False)
181
    label = Field(String(50))
182
    description = Field(String(200))
183
    parent_category_id = Field(Integer)
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")
746 rajveer 199
 
3187 rajveer 200
def initialize(dbname='catalog', db_hostname="localhost"):
746 rajveer 201
    #metadata.bind = "sqlite:///inventory-new.sqlite" #need to read it from configserver.
1122 chandransh 202
    #metadata.bind = 'mysql://root:shop2020@localhost/catalog'
3187 rajveer 203
    engine = create_engine('mysql://root:shop2020@' + db_hostname + '/' + dbname, pool_recycle=7200)
1122 chandransh 204
    metadata.bind = engine
94 ashish 205
    metadata.bind.echo = True
206
    setup_all(True)
115 ashish 207
 
208
if __name__=="__main__":
209
    initialize()