| 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):
|
|
|
21 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
|
|
22 |
createdOn = Field(DateTime)
|
|
|
23 |
expected_delivery_time = Field(DateTime)
|
|
|
24 |
status = Field(Integer)
|
|
|
25 |
status_message = Field(String(100))
|
|
|
26 |
customer_id = Field(Integer)
|
|
|
27 |
payments = OneToMany("Payment")
|
|
|
28 |
shipments = OneToMany("Shipment")
|
|
|
29 |
lineitems = OneToMany("LineItem")
|
|
|
30 |
trails = OneToMany("TransactionTrail")
|
|
|
31 |
def __repr__(self):
|
|
|
32 |
return "Transaction: id %d" % (self.id)
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
class Payment(Entity):
|
|
|
36 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
|
|
37 |
merchant_tx_id = Field(String(30))
|
|
|
38 |
bank_tx_id = Field(String(30))
|
|
|
39 |
amount = Field(Float)
|
|
|
40 |
status = Field(Integer)
|
|
|
41 |
status_message = Field(String(100))
|
|
|
42 |
start_time = Field(DateTime)
|
|
|
43 |
finish_time = Field(DateTime)
|
|
|
44 |
transaction = ManyToOne("Transaction")
|
|
|
45 |
|
|
|
46 |
def __repr__(self):
|
|
|
47 |
return "Payment: id %d"%(self.id)
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
class Shipment(Entity):
|
|
|
51 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
|
|
52 |
address = Field(String(100))
|
|
|
53 |
tracking_id = Field(String(100))
|
|
|
54 |
status = Field(Integer)
|
|
|
55 |
status_message = Field(String(100))
|
|
|
56 |
shipment_time = Field(DateTime)
|
|
|
57 |
delivery_time = Field(DateTime)
|
|
|
58 |
declared_value = Field(Float)
|
|
|
59 |
insurance_value = Field(Float)
|
|
|
60 |
weight = Field(Float)
|
|
|
61 |
airway_bill_no = Field(String(30))
|
|
|
62 |
provider = Field(String(30))
|
|
|
63 |
transaction = ManyToOne("Transaction")
|
|
|
64 |
lineitems = OneToMany("LineItem")
|
|
|
65 |
|
|
|
66 |
def __repr__(self):
|
|
|
67 |
return "Shipment: id %d"%(self.id)
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
class LineItem(Entity):
|
|
|
71 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
|
|
72 |
added_on = Field(DateTime)
|
|
|
73 |
item_id = Field(Integer)
|
|
|
74 |
additional_info = OneToMany("AdditionalInfo")
|
|
|
75 |
transaction = ManyToOne("Transaction")
|
|
|
76 |
billing = OneToOne("Billing")
|
|
|
77 |
shipment = ManyToOne("Shipment")
|
|
|
78 |
|
|
|
79 |
def __repr__(self):
|
|
|
80 |
return "id %d item_id %d"%(self.id, self.item_id)
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
class AdditionalInfo(Entity):
|
|
|
84 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
|
|
85 |
key = Field(String(30))
|
|
|
86 |
value = Field(String(100))
|
|
|
87 |
line_item = ManyToOne("LineItem")
|
|
|
88 |
|
|
|
89 |
def __repr__(self):
|
|
|
90 |
return "Additonal info id %d key %s value %s" %(self.id, self.key, self.value)
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
class Billing(Entity):
|
|
|
94 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
|
|
95 |
bill_number = Field(String(30))
|
|
|
96 |
created_on = Field(DateTime)
|
|
|
97 |
generated_by = Field(String(30))
|
|
|
98 |
line_item = OneToOne("LineItem")
|
|
|
99 |
|
|
|
100 |
def __repr__(self):
|
|
|
101 |
return "Billing: billing id %d billno %s " % (self.id, self.bill_number)
|
|
|
102 |
|
|
|
103 |
class TransactionTrail(Entity):
|
|
|
104 |
id = Field(Integer, primary_key=True, autoincrement=True)
|
|
|
105 |
field_changed = Field(String(30))
|
|
|
106 |
old_value = Field(String(30))
|
|
|
107 |
new_value = Field(String(30))
|
|
|
108 |
description = Field(String(100))
|
|
|
109 |
timestamp = Field(DateTime)
|
|
|
110 |
transaction = ManyToOne("Transaction")
|
|
|
111 |
|
|
|
112 |
|
|
|
113 |
def initialize():
|
|
|
114 |
metadata.bind = "sqlite:///Order.sqlite"
|
|
|
115 |
metadata.bind.echo = True
|
|
|
116 |
setup_all(True)
|
|
|
117 |
|
|
|
118 |
|
|
|
119 |
if __name__=="__main__":
|
|
|
120 |
initialize()
|