Subversion Repositories SmartDukaan

Rev

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