| 104 |
ashish |
1 |
'''
|
|
|
2 |
Created on 29-Mar-2010
|
|
|
3 |
|
|
|
4 |
@author: ashish
|
|
|
5 |
'''
|
|
|
6 |
|
|
|
7 |
from elixir import *
|
|
|
8 |
from elixir.entity import Entity
|
|
|
9 |
from elixir.fields import Field
|
|
|
10 |
from sqlalchemy.types import Integer
|
|
|
11 |
from elixir.relationships import OneToMany, ManyToOne
|
|
|
12 |
import datetime
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
#===============================================================================
|
|
|
17 |
# Different entities in the model
|
|
|
18 |
#===============================================================================
|
|
|
19 |
|
|
|
20 |
class Transaction(Entity):
|
| 132 |
ashish |
21 |
|
|
|
22 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 104 |
ashish |
23 |
createdOn = Field(DateTime)
|
|
|
24 |
expected_delivery_time = Field(DateTime)
|
|
|
25 |
status = Field(Integer)
|
|
|
26 |
status_message = Field(String(100))
|
|
|
27 |
customer_id = Field(Integer)
|
| 132 |
ashish |
28 |
shopping_cart_id = Field(Integer)
|
| 104 |
ashish |
29 |
payments = OneToMany("Payment")
|
|
|
30 |
shipments = OneToMany("Shipment")
|
|
|
31 |
lineitems = OneToMany("LineItem")
|
|
|
32 |
trails = OneToMany("TransactionTrail")
|
|
|
33 |
def __repr__(self):
|
|
|
34 |
return "Transaction: id %d" % (self.id)
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
class Payment(Entity):
|
| 115 |
ashish |
38 |
#using_options(auto_primarykey=False)
|
| 132 |
ashish |
39 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
|
|
40 |
payment_id = Field(Integer)
|
| 104 |
ashish |
41 |
merchant_tx_id = Field(String(30))
|
|
|
42 |
bank_tx_id = Field(String(30))
|
| 132 |
ashish |
43 |
mode = Field(String(30))
|
| 104 |
ashish |
44 |
amount = Field(Float)
|
|
|
45 |
status = Field(Integer)
|
|
|
46 |
status_message = Field(String(100))
|
|
|
47 |
start_time = Field(DateTime)
|
|
|
48 |
finish_time = Field(DateTime)
|
|
|
49 |
transaction = ManyToOne("Transaction")
|
|
|
50 |
|
|
|
51 |
def __repr__(self):
|
|
|
52 |
return "Payment: id %d"%(self.id)
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
class Shipment(Entity):
|
| 115 |
ashish |
56 |
#using_options(auto_primarykey=False)
|
| 132 |
ashish |
57 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 104 |
ashish |
58 |
address = Field(String(100))
|
|
|
59 |
tracking_id = Field(String(100))
|
|
|
60 |
status = Field(Integer)
|
|
|
61 |
status_message = Field(String(100))
|
|
|
62 |
shipment_time = Field(DateTime)
|
|
|
63 |
delivery_time = Field(DateTime)
|
|
|
64 |
declared_value = Field(Float)
|
|
|
65 |
insurance_value = Field(Float)
|
|
|
66 |
weight = Field(Float)
|
|
|
67 |
airway_bill_no = Field(String(30))
|
|
|
68 |
provider = Field(String(30))
|
|
|
69 |
transaction = ManyToOne("Transaction")
|
|
|
70 |
lineitems = OneToMany("LineItem")
|
|
|
71 |
|
|
|
72 |
def __repr__(self):
|
|
|
73 |
return "Shipment: id %d"%(self.id)
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
class LineItem(Entity):
|
| 115 |
ashish |
77 |
#using_options(auto_primarykey=False)
|
| 132 |
ashish |
78 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 104 |
ashish |
79 |
added_on = Field(DateTime)
|
|
|
80 |
item_id = Field(Integer)
|
|
|
81 |
additional_info = OneToMany("AdditionalInfo")
|
|
|
82 |
transaction = ManyToOne("Transaction")
|
| 115 |
ashish |
83 |
billing = ManyToOne("Billing")
|
| 104 |
ashish |
84 |
shipment = ManyToOne("Shipment")
|
| 132 |
ashish |
85 |
item_info = OneToOne("ItemInfo")
|
| 104 |
ashish |
86 |
def __repr__(self):
|
|
|
87 |
return "id %d item_id %d"%(self.id, self.item_id)
|
|
|
88 |
|
| 132 |
ashish |
89 |
class ItemInfo(Entity):
|
|
|
90 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
|
|
91 |
price = Field(Float)
|
|
|
92 |
weight = Field(Float)
|
|
|
93 |
line_item = ManyToOne("LineItem")
|
| 104 |
ashish |
94 |
|
|
|
95 |
class AdditionalInfo(Entity):
|
| 115 |
ashish |
96 |
#using_options(auto_primarykey=False)
|
| 132 |
ashish |
97 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 104 |
ashish |
98 |
key = Field(String(30))
|
|
|
99 |
value = Field(String(100))
|
|
|
100 |
line_item = ManyToOne("LineItem")
|
|
|
101 |
|
|
|
102 |
def __repr__(self):
|
|
|
103 |
return "Additonal info id %d key %s value %s" %(self.id, self.key, self.value)
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
class Billing(Entity):
|
| 115 |
ashish |
107 |
#using_options(auto_primarykey=False)
|
| 132 |
ashish |
108 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 104 |
ashish |
109 |
bill_number = Field(String(30))
|
|
|
110 |
created_on = Field(DateTime)
|
|
|
111 |
generated_by = Field(String(30))
|
| 115 |
ashish |
112 |
line_item = OneToMany("LineItem")
|
| 104 |
ashish |
113 |
|
| 132 |
ashish |
114 |
|
| 104 |
ashish |
115 |
def __repr__(self):
|
|
|
116 |
return "Billing: billing id %d billno %s " % (self.id, self.bill_number)
|
|
|
117 |
|
|
|
118 |
class TransactionTrail(Entity):
|
| 115 |
ashish |
119 |
#using_options(auto_primarykey=False)
|
| 132 |
ashish |
120 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
| 104 |
ashish |
121 |
field_changed = Field(String(30))
|
|
|
122 |
old_value = Field(String(30))
|
|
|
123 |
new_value = Field(String(30))
|
|
|
124 |
description = Field(String(100))
|
|
|
125 |
timestamp = Field(DateTime)
|
|
|
126 |
transaction = ManyToOne("Transaction")
|
|
|
127 |
|
|
|
128 |
|
|
|
129 |
def initialize():
|
| 132 |
ashish |
130 |
metadata.bind = "sqlite:///Transactionsnew.sqlite"
|
| 104 |
ashish |
131 |
metadata.bind.echo = True
|
|
|
132 |
setup_all(True)
|
|
|
133 |
|
|
|
134 |
|
|
|
135 |
if __name__=="__main__":
|
|
|
136 |
initialize()
|