Subversion Repositories SmartDukaan

Rev

Rev 1416 | Rev 1970 | 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
'''
6
from elixir import *
7
from elixir.entity import Entity
8
from elixir.fields import Field
635 rajveer 9
from sqlalchemy.types import Integer, Binary
1122 chandransh 10
from sqlalchemy import create_engine
94 ashish 11
from elixir.relationships import OneToMany, ManyToOne
12
import datetime
746 rajveer 13
import elixir
94 ashish 14
 
1308 chandransh 15
class Vendor(Entity):
16
    id = Field(Integer, primary_key=True, autoincrement=True)
17
    name = Field(String(50))
18
    warehouses = OneToMany('Warehouse')
19
    using_options(shortnames=True)
20
    using_table_options(mysql_engine="InnoDB")
21
 
94 ashish 22
class Warehouse(Entity):
122 ashish 23
    id = Field(Integer, primary_key=True, autoincrement=True)
759 chandransh 24
    displayName = Field(String(50))
483 rajveer 25
    location = Field(String(200))
103 ashish 26
    status = Field(Integer)
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))
94 ashish 32
    inventory = OneToMany('CurrentInventorySnapshot')
33
    inventoryHistory = OneToMany('ItemInventoryHistory')
643 chandransh 34
    logisticsLocation = Field(Integer)
1308 chandransh 35
    vendor = ManyToOne('Vendor')
746 rajveer 36
    using_options(shortnames=True)
37
    using_table_options(mysql_engine="InnoDB")
94 ashish 38
 
39
    def __repr__(self):
40
        return "<warehouse>%s</warehouse>" %(self.location)
41
 
122 ashish 42
    @property
43
    def all_items(self):
44
        items = []
45
        for ci in self.inventory:
46
            items.append(ci.item)
47
        return items 
626 chandransh 48
 
49
class EntityIDGenerator(Entity):
50
    id=Field(Integer, primary_key=True)
51
    using_options(shortnames=True)
746 rajveer 52
    using_table_options(mysql_engine="InnoDB")
122 ashish 53
 
94 ashish 54
class Item(Entity):
122 ashish 55
    id = Field(Integer, primary_key=True, autoincrement=True)
963 chandransh 56
    product_group = Field(String(100))
57
    brand = Field(String(100))
483 rajveer 58
    model_number = Field(String(50))
59
    model_name = Field(String(50))
609 chandransh 60
    color = Field(String(20))
626 chandransh 61
    category = Field(Integer)
483 rajveer 62
    comments = Field(String(200))
122 ashish 63
    catalog_item_id = Field(Integer)
64
    feature_id = Field(Integer)
65
    feature_description = Field(String(200))
483 rajveer 66
    mrp = Field(Float)
67
    mop = Field(Float)
68
    sellingPrice = Field(Float)
609 chandransh 69
    dealerPrice = Field(Float)
724 chandransh 70
    transfer_price = Field(Float)
483 rajveer 71
    weight = Field(Float)
122 ashish 72
    addedOn = Field(DateTime)
609 chandransh 73
    updatedOn = Field(DateTime)
122 ashish 74
    startDate = Field(DateTime)
75
    retireDate = Field(DateTime)
483 rajveer 76
    status = Field(Integer)
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")
724 chandransh 84
    hotspotCategory = Field(String(50))
1416 chandransh 85
    preferredWarehouse = Field(String(50))
1910 varun.gupt 86
    defaultForEntity = Field(Boolean)
746 rajveer 87
    using_options(shortnames=True)
88
    using_table_options(mysql_engine="InnoDB")
103 ashish 89
 
94 ashish 90
    def __repr__(self):
122 ashish 91
        return "<Item>%d</item>" % (self.id)
94 ashish 92
 
122 ashish 93
    @property
94 ashish 94
    def get_total_inventory(self):
95
        if self.currentInventory:
96
            i = 0
97
            for entry in self.currentInventory:
98
                i += entry.availability
99
            return i
100
 
101
        else:
102
            return 0;
103 ashish 103
 
122 ashish 104
    @property
94 ashish 105
    def get_all_warehouses(self):
1308 chandransh 106
        return [ci.warehouse for ci in self.currentInventory]
107
 
108
class VendorItemMapping(Entity):
109
    vendor = ManyToOne('Vendor', primary_key=True)
110
    item_key = Field(String(200), primary_key=True)
111
    item = ManyToOne('Item')
1352 chandransh 112
    vendor_category = Field(String(50))
1308 chandransh 113
    using_options(shortnames=True)
114
    using_table_options(mysql_engine="InnoDB")
115
 
116
class VendorItemPricing(Entity):
117
    vendor = ManyToOne('Vendor', primary_key=True)
118
    item = ManyToOne('Item', primary_key=True)
119
    mop = Field(Float)
120
    dealerPrice = Field(Float)
121
    transfer_price = Field(Float)
122
    using_options(shortnames=True)
123
    using_table_options(mysql_engine="InnoDB")
124
 
103 ashish 125
class ItemInfo(Entity):
122 ashish 126
    id = Field(Integer, primary_key=True, autoincrement=True)
103 ashish 127
    key = Field(String(30))
128
    value = Field(String(100))
129
    item = ManyToOne("Item")
746 rajveer 130
    using_options(shortnames=True)
131
    using_table_options(mysql_engine="InnoDB")
103 ashish 132
 
133
    def __repr__(self):
134
        return "<ItemInfo><key>%s</key><value>%s</value></ItemInfo>" % (self.key, self.value)
115 ashish 135
 
94 ashish 136
 
137
class CurrentInventorySnapshot(Entity):
115 ashish 138
    #id = Field(Integer, primary_key=True)
483 rajveer 139
    #checkedOn = Field(DateTime, default=datetime.datetime.now())
870 chandransh 140
    item = ManyToOne("Item", primary_key=True)
141
    warehouse = ManyToOne("Warehouse", primary_key=True)
94 ashish 142
    availibility = Field(Integer)
870 chandransh 143
    reserved = Field(Integer)
746 rajveer 144
    using_options(shortnames=True)
145
    using_table_options(mysql_engine="InnoDB")
94 ashish 146
 
147
    def __repr__(self):
148
        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)
149
 
150
class ItemInventoryHistory(Entity):
122 ashish 151
    id = Field(Integer, primary_key=True, autoincrement = True)    
94 ashish 152
    timestamp = Field(DateTime, default=datetime.datetime.now())
153
    availibility = Field(Integer)
154
    item = ManyToOne("Item")
155
    warehouse = ManyToOne("Warehouse")
746 rajveer 156
    using_options(shortnames=True)
157
    using_table_options(mysql_engine="InnoDB")
94 ashish 158
 
159
    def __repr__(self):
160
        pass
103 ashish 161
 
162
class ItemChangeLog(Entity):
122 ashish 163
    id = Field(Integer, primary_key=True, autoincrement=True)
103 ashish 164
    old_status = Field(Integer)
165
    new_status = Field(Integer)
1308 chandransh 166
    timestamp = Field(DateTime)
103 ashish 167
    item = ManyToOne("Item")
746 rajveer 168
    using_options(shortnames=True)
169
    using_table_options(mysql_engine="InnoDB")
94 ashish 170
 
103 ashish 171
    def __repr__(self):
172
        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 173
 
635 rajveer 174
class Category(Entity):
175
    id = Field(Integer, primary_key=True, autoincrement=True)
176
    object = Field(Binary)
746 rajveer 177
    using_options(shortnames=True)
178
    using_table_options(mysql_engine="InnoDB")
179
 
1249 chandransh 180
def initialize(dbname='catalog'):
746 rajveer 181
    #metadata.bind = "sqlite:///inventory-new.sqlite" #need to read it from configserver.
1122 chandransh 182
    #metadata.bind = 'mysql://root:shop2020@localhost/catalog'
1249 chandransh 183
    engine = create_engine('mysql://root:shop2020@localhost/' + dbname, pool_recycle=7200)
1122 chandransh 184
    metadata.bind = engine
94 ashish 185
    metadata.bind.echo = True
186
    setup_all(True)
115 ashish 187
 
188
if __name__=="__main__":
189
    initialize()