Subversion Repositories SmartDukaan

Rev

Rev 1308 | Rev 1416 | 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))
746 rajveer 85
    using_options(shortnames=True)
86
    using_table_options(mysql_engine="InnoDB")
103 ashish 87
 
94 ashish 88
    def __repr__(self):
122 ashish 89
        return "<Item>%d</item>" % (self.id)
94 ashish 90
 
122 ashish 91
    @property
94 ashish 92
    def get_total_inventory(self):
93
        if self.currentInventory:
94
            i = 0
95
            for entry in self.currentInventory:
96
                i += entry.availability
97
            return i
98
 
99
        else:
100
            return 0;
103 ashish 101
 
122 ashish 102
    @property
94 ashish 103
    def get_all_warehouses(self):
1308 chandransh 104
        return [ci.warehouse for ci in self.currentInventory]
105
 
106
class VendorItemMapping(Entity):
107
    vendor = ManyToOne('Vendor', primary_key=True)
108
    item_key = Field(String(200), primary_key=True)
109
    item = ManyToOne('Item')
1352 chandransh 110
    vendor_category = Field(String(50))
1308 chandransh 111
    using_options(shortnames=True)
112
    using_table_options(mysql_engine="InnoDB")
113
 
114
class VendorItemPricing(Entity):
115
    vendor = ManyToOne('Vendor', primary_key=True)
116
    item = ManyToOne('Item', primary_key=True)
117
    mop = Field(Float)
118
    dealerPrice = Field(Float)
119
    transfer_price = Field(Float)
120
    using_options(shortnames=True)
121
    using_table_options(mysql_engine="InnoDB")
122
 
103 ashish 123
class ItemInfo(Entity):
122 ashish 124
    id = Field(Integer, primary_key=True, autoincrement=True)
103 ashish 125
    key = Field(String(30))
126
    value = Field(String(100))
127
    item = ManyToOne("Item")
746 rajveer 128
    using_options(shortnames=True)
129
    using_table_options(mysql_engine="InnoDB")
103 ashish 130
 
131
    def __repr__(self):
132
        return "<ItemInfo><key>%s</key><value>%s</value></ItemInfo>" % (self.key, self.value)
115 ashish 133
 
94 ashish 134
 
135
class CurrentInventorySnapshot(Entity):
115 ashish 136
    #id = Field(Integer, primary_key=True)
483 rajveer 137
    #checkedOn = Field(DateTime, default=datetime.datetime.now())
870 chandransh 138
    item = ManyToOne("Item", primary_key=True)
139
    warehouse = ManyToOne("Warehouse", primary_key=True)
94 ashish 140
    availibility = Field(Integer)
870 chandransh 141
    reserved = Field(Integer)
746 rajveer 142
    using_options(shortnames=True)
143
    using_table_options(mysql_engine="InnoDB")
94 ashish 144
 
145
    def __repr__(self):
146
        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)
147
 
148
class ItemInventoryHistory(Entity):
122 ashish 149
    id = Field(Integer, primary_key=True, autoincrement = True)    
94 ashish 150
    timestamp = Field(DateTime, default=datetime.datetime.now())
151
    availibility = Field(Integer)
152
    item = ManyToOne("Item")
153
    warehouse = ManyToOne("Warehouse")
746 rajveer 154
    using_options(shortnames=True)
155
    using_table_options(mysql_engine="InnoDB")
94 ashish 156
 
157
    def __repr__(self):
158
        pass
103 ashish 159
 
160
class ItemChangeLog(Entity):
122 ashish 161
    id = Field(Integer, primary_key=True, autoincrement=True)
103 ashish 162
    old_status = Field(Integer)
163
    new_status = Field(Integer)
1308 chandransh 164
    timestamp = Field(DateTime)
103 ashish 165
    item = ManyToOne("Item")
746 rajveer 166
    using_options(shortnames=True)
167
    using_table_options(mysql_engine="InnoDB")
94 ashish 168
 
103 ashish 169
    def __repr__(self):
170
        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 171
 
635 rajveer 172
class Category(Entity):
173
    id = Field(Integer, primary_key=True, autoincrement=True)
174
    object = Field(Binary)
746 rajveer 175
    using_options(shortnames=True)
176
    using_table_options(mysql_engine="InnoDB")
177
 
1249 chandransh 178
def initialize(dbname='catalog'):
746 rajveer 179
    #metadata.bind = "sqlite:///inventory-new.sqlite" #need to read it from configserver.
1122 chandransh 180
    #metadata.bind = 'mysql://root:shop2020@localhost/catalog'
1249 chandransh 181
    engine = create_engine('mysql://root:shop2020@localhost/' + dbname, pool_recycle=7200)
1122 chandransh 182
    metadata.bind = engine
94 ashish 183
    metadata.bind.echo = True
184
    setup_all(True)
115 ashish 185
 
186
if __name__=="__main__":
187
    initialize()