-
Notifications
You must be signed in to change notification settings - Fork 3
/
initdb.py
240 lines (228 loc) · 9.24 KB
/
initdb.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
"""
Copyright (C) 2013, 2014, 2015, 2016 Digital Freedom Foundation
Copyright (C) 2017, 2018 Digital Freedom Foundation & Accion Labs
This file is part of GNUKhata:A modular,robust and Free Accounting System.
GNUKhata is Free Software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation; either version 3 of
the License, or (at your option) any later version.and old.stockflag = 's'
GNUKhata 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public
License along with GNUKhata (COPYING); if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA59 Temple Place, Suite 330,
Contributors:
"Krishnakant Mane" <kk@gmail.com>
"Ishan Masdekar " <imasdekar@dff.org.in>
"Navin Karkera" <navin@dff.org.in>
"""
from gkcore import eng
from gkcore.models.gkdb import metadata
from gkcore.models import gkdb
from sqlalchemy.sql import select
from sqlalchemy import func
"""
This module is used only once per installation.
It will use the sqlalchemy's create_all function to convert all python based table spects to real sql tables.
Refer to gkdb.py in models package for structure of all tables expressed in the alchemy expression language.
After creating all tables, it will also create the signature based on timestamp and store in the database.
"""
metadata.create_all(eng)
print("database created successfully")
eng.execute(
"alter table groupsubgroups add foreign key (subgroupof) references groupsubgroups(groupcode)"
)
eng.execute(
"alter table categorysubcategories add foreign key (subcategoryof) references categorysubcategories(categorycode)"
)
eng.execute(
"alter table unitofmeasurement add foreign key (subunitof) references unitofmeasurement(uomid)"
)
try:
uomscount = eng.execute(
select([func.count(gkdb.unitofmeasurement.c.uomid).label("numofuom")])
)
numofuom = uomscount.fetchone()
if int(numofuom["numofuom"]) == 0:
# UQC list as per Indian GST law
dictofuqc = {
"BAG": "BAGS",
"BAL": "BALE",
"BDL": "BUNDLES",
"BKL": "BUCKLES",
"BOU": "BILLIONS OF UNITS",
"BOX": "BOX",
"BTL": "BOTTLES",
"BUN": "BUNCHES",
"CAN": "CANS",
"CBM": "CUBIC METER",
"CCM": "CUBIC CENTIMETER",
"CMS": "CENTIMETER",
"CRT": "Carat",
"CTN": "CARTONS",
"DOZ": "DOZEN",
"DRM": "DRUM",
"GGK": "GREAT GROSS",
"GMS": "GRAMS",
"GRS": "GROSS",
"GYD": "GROSS YARDS",
"KGS": "KILOGRAMS",
"KLR": "KILOLITER",
"KME": "KILOMETERS",
"MLT": "MILLILITER",
"MTR": "METER",
"MTS": "METRIC TON",
"NOS": "NUMBER",
"OTH": "OTHERS",
"PAC": "PACKS",
"PCS": "PIECES",
"PRS": "PAIRS",
"QTL": "QUINTAL",
"ROL": "ROLLS",
"SET": "SETS",
"SQF": "SQUARE FEET",
"SQM": "SQUARE METER",
"SQY": "SQUARE YARDS",
"TBS": "TABLETS",
"TGM": "TEN GRAMS",
"THD": "THOUSANDS",
"TON": "GREAT BRITAIN TON",
"TUB": "TUBES",
"UGS": "US GALLONS",
"UNT": "UNITS",
"YDS": "YARDS",
}
for unit, desc in list(dictofuqc.items()):
eng.execute(
"insert into unitofmeasurement(unitname, conversionrate, description, sysunit)values('%s',0.00,'%s',1)"
% (unit, desc)
)
dictofuqc.pop(unit, 0)
statescount = eng.execute(
select([func.count(gkdb.state.c.statecode).label("numberofstates")])
)
numberofstates = statescount.fetchone()
if int(numberofstates["numberofstates"]) == 0:
eng.execute(
"insert into state( statecode, statename, abbreviation)values(1, 'Jammu and Kashmir', 'JK')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(2, 'Himachal Pradesh', 'HP')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(3, 'Punjab', 'PB')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(4, 'Chandigarh', 'CH')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(5, 'Uttarakhand', 'UK')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(6, 'Haryana', 'HR')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(7, 'Delhi', 'DL')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(8, 'Rajasthan', 'RJ')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(9, 'Uttar Pradesh', 'UP')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(10, 'Bihar', 'BR')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(11, 'Sikkim', 'SK')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(12, 'Arunachal Pradesh', 'AR')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(13, 'Nagaland', 'NL')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(14, 'Manipur', 'MN')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(15, 'Mizoram', 'MZ')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(16, 'Tripura', 'TR')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(17, 'Meghalaya', 'ML')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(18, 'Assam', 'AS')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(19, 'West Bengal', 'WB')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(20, 'Jharkhand', 'JH')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(21, 'Odisha', 'OR')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(22, 'Chhattisgarh', 'CG')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(23, 'Madhya Pradesh', 'MP')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(24, 'Gujarat', 'GJ')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(25, 'Daman and Diu (Old)', 'DD')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(26, 'Daman and Diu & Dadra and Nagar Haveli (New)', 'DH')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(27, 'Maharashtra', 'MH')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(28, 'Andhra Pradesh', 'AP')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(29, 'Karnataka', 'KA')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(30, 'Goa', 'GA')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(31, 'Lakshdweep', 'LD')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(32, 'Kerala', 'KL')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(33, 'Tamil Nadu', 'TN')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(34, 'Pondicherry', 'PY')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(35, 'Andaman and Nicobar Islands', 'AN')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(36, 'Telangana', 'TS')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(37, 'Andhra Pradesh (New)', 'AP')"
)
eng.execute(
"insert into state( statecode, statename, abbreviation)values(38, 'Ladakh', 'LA')"
)
eng.execute("alter table transfernote add recieveddate date")
eng.execute("alter table delchal add noofpackages int")
eng.execute("alter table delchal add modeoftransport text")
except:
pass
print("secret signature generated")