This repository has been archived by the owner on Apr 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb.py
69 lines (52 loc) · 1.94 KB
/
db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Copyright 2008 Jonathan Doda
#
# This file is part of pos.py.
#
# pos.py is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 3,
# as published by the Free Software Foundation.
#
# pos.py is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pos.py. If not, see <http://www.gnu.org/licenses/>.
from sqlobject import *
import config
connection = connectionForURI(config.database_uri)
sqlhub.processConnection = connection
class Item(SQLObject):
upc = StringCol(notNull=True)
name = StringCol(notNull=True)
price = FloatCol(notNull=True)
upc_index = DatabaseIndex(upc, unique=True)
class Sale(SQLObject):
time = DateTimeCol(notNull=True)
type = EnumCol(enumValues=['PURCHASE', 'SHRINKAGE', 'GIVEAWAY'], notNull=True)
time_index = DatabaseIndex(time, unique=True)
class SaleItem(SQLObject):
sale = ForeignKey('Sale', notNull=True)
item = ForeignKey('Item', notNull=True)
price = FloatCol(notNull=True)
class Box(SQLObject):
upc = StringCol(notNull=True)
item = ForeignKey('Item', notNull=True)
quantity = IntCol(notNull=True)
cost = FloatCol(notNull=True)
upc_index = DatabaseIndex(upc, unique=True)
class Purchase(SQLObject):
time = DateTimeCol(notNull=True)
time_index = DatabaseIndex(time, unique=True)
class PurchaseBox(SQLObject):
purchase = ForeignKey('Purchase', notNull=True)
box = ForeignKey('Box', notNull=True)
cost = FloatCol(notNull=True)
if __name__ == '__main__':
Item.createTable()
Sale.createTable()
SaleItem.createTable()
Box.createTable()
Purchase.createTable()
PurchaseBox.createTable()