-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatabase_init_queryes.py
381 lines (341 loc) · 11.9 KB
/
database_init_queryes.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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
#import ui_global
def database_shema():
Rs = []
#Константы и хранимые настройки RS_constants
Rs.append('''
CREATE TABLE IF NOT EXISTS RS_constants (
id INTEGER PRIMARY KEY AUTOINCREMENT,
use_series TEXT DEFAULT 0
NOT NULL,
use_properties TEXT DEFAULT 0
NOT NULL,
use_mark TEXT DEFAULT 0
NOT NULL,
add_if_not_in_plan TEXT DEFAULT 0
NOT NULL,
path TEXT NOT NULL
DEFAULT "//storage/emulated/0/Android/data/ru.travelfood.simple_ui/",
delete_files TEXT DEFAULT 0
NOT NULL,
reserved TEXT NOT NULL,
max_id_doc INTEGER NOT NULL
DEFAULT (1),
allow_overscan TEXT DEFAULT 0
NOT NULL,
release TEXT
)
''')
# Классификатор единиц измерения RS_classifier_units
Rs.append('''
CREATE TABLE IF NOT EXISTS RS_classifier_units (
id TEXT NOT NULL
PRIMARY KEY,
code TEXT NOT NULL,
name TEXT NOT NULL
)
''')
# Виды номенклатуры RS_types_goods
Rs.append('''
CREATE TABLE IF NOT EXISTS RS_types_goods (
id TEXT NOT NULL
PRIMARY KEY,
name TEXT NOT NULL,
use_mark INT DEFAULT (0)
)
''')
# Номенклатура RS_goods
Rs.append('''
CREATE TABLE IF NOT EXISTS RS_goods (
id TEXT NOT NULL
PRIMARY KEY,
code TEXT NOT NULL,
name TEXT NOT NULL,
art TEXT,
unit TEXT REFERENCES RS_classifier_units (id),
type_good TEXT NOT NULL
REFERENCES RS_types_goods (id) ON DELETE NO ACTION
MATCH [FULL],
description TEXT
)
''')
# Характеристики номенклатуры RS_properties
Rs.append('''
CREATE TABLE IF NOT EXISTS RS_properties (
id TEXT NOT NULL
PRIMARY KEY ON CONFLICT REPLACE,
id_owner TEXT NOT NULL
REFERENCES RS_goods (id) ON DELETE NO ACTION
ON UPDATE NO ACTION,
name TEXT NOT NULL
)
''')
# Упаковки Единицы измерения RS_units
Rs.append('''
CREATE TABLE IF NOT EXISTS RS_units (
id TEXT NOT NULL
PRIMARY KEY,
id_owner TEXT NOT NULL
REFERENCES RS_goods (id),
code TEXT NOT NULL,
name TEXT NOT NULL,
nominator INTEGER NOT NULL,
denominator INTEGER NOT NULL,
int_reduction TEXT NOT NULL
)
''')
# Серии номенклатуры RS_series
Rs.append('''
CREATE TABLE IF NOT EXISTS RS_series (
id TEXT NOT NULL
PRIMARY KEY,
name TEXT NOT NULL,
best_before TEXT,
type_goods TEXT NOT NULL,
number TEXT NOT NULL,
production_date TEXT NOT NULL
)
''')
# Штрихкоды RS_barcodes
Rs.append( '''
CREATE TABLE IF NOT EXISTS RS_barcodes (
barcode TEXT NOT NULL
PRIMARY KEY,
id_good TEXT NOT NULL,
id_property TEXT,
id_series TEXT,
id_unit TEXT,
ratio INT DEFAULT (1)
NOT NULL
)
''')
#Коды маркировки RS_marking_codes
Rs.append( '''
CREATE TABLE IF NOT EXISTS RS_marking_codes (
id TEXT NOT NULL
PRIMARY KEY,
mark_code TEXT NOT NULL,
id_good TEXT NOT NULL
REFERENCES RS_goods (id),
id_property TEXT NOT NULL
REFERENCES RS_properties (id),
id_series TEXT NOT NULL
REFERENCES RS_series (id),
id_unit TEXT NOT NULL
REFERENCES RS_units (id)
)
''')
# Контрагенты RS_countragents
Rs.append('''
CREATE TABLE IF NOT EXISTS RS_countragents (
id TEXT NOT NULL
PRIMARY KEY,
name TEXT NOT NULL,
full_name TEXT NOT NULL,
inn TEXT NOT NULL,
kpp TEXT NOT NULL
)
''')
# Склады RS_warehouses
Rs.append('''
CREATE TABLE IF NOT EXISTS RS_warehouses (
id TEXT NOT NULL
PRIMARY KEY,
name TEXT NOT NULL
)
''')
Rs.append('''
CREATE TABLE IF NOT EXISTS RS_cells (
id TEXT PRIMARY KEY
NOT NULL,
name TEXT NOT NULL,
barcode TEXT
)''')
# Виды цен номенклатуры RS_price_types
Rs.append('''
CREATE TABLE IF NOT EXISTS RS_price_types (
id TEXT NOT NULL
PRIMARY KEY,
name TEXT NOT NULL
)
''')
# Цены номенклатуры RS_prices
Rs.append('''
CREATE TABLE IF NOT EXISTS RS_prices (
id INTEGER PRIMARY KEY AUTOINCREMENT,
id_price_types TEXT NOT NULL
REFERENCES RS_price_types (id),
id_goods TEXT NOT NULL
REFERENCES RS_goods (id),
id_properties TEXT NOT NULL
REFERENCES RS_properties (id),
price REAL,
id_unit TEXT NOT NULL
REFERENCES RS_units (id)
)
''')
Rs.append('''
CREATE TABLE IF NOT EXISTS RS_doc_types (
doc_type TEXT PRIMARY KEY ON CONFLICT REPLACE
NOT NULL,
is_adr_storage INT DEFAULT (0)
)
''')
# Все документы списком RS_docs
Rs.append('''
CREATE TABLE IF NOT EXISTS RS_docs (
id_doc TEXT NOT NULL
PRIMARY KEY,
doc_type TEXT NOT NULL,
doc_n TEXT NOT NULL,
doc_date TEXT NOT NULL,
id_countragents TEXT NOT NULL
REFERENCES RS_countragents (id),
id_warehouse TEXT NOT NULL
REFERENCES RS_warehouses (id),
verified INTEGER,
sent INTEGER,
add_mark_selection INTEGER,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
control TEXT DEFAULT 0,
is_group_scan TEXT DEFAULT 0,
allow_fact_input TEXT DEFAULT 0
)
''')
# Табличная часть документов RS_docs_table
Rs.append('''
CREATE TABLE IF NOT EXISTS RS_docs_table (
id INTEGER PRIMARY KEY AUTOINCREMENT,
id_doc TEXT NOT NULL
REFERENCES RS_docs (id_doc) ON DELETE CASCADE
ON UPDATE SET DEFAULT,
id_good TEXT NOT NULL
REFERENCES RS_goods (id),
id_properties TEXT REFERENCES RS_properties (id),
id_series TEXT REFERENCES RS_series (id),
id_unit TEXT NOT NULL
REFERENCES RS_units (id),
qtty REAL,
d_qtty REAL,
qtty_plan REAL,
price REAL,
id_price TEXT REFERENCES RS_price_types (id),
sent INTEGER,
last_updated DATETIME DEFAULT CURRENT_TIMESTAMP,
is_plan TEXT DEFAULT "True",
id_cell TEXT REFERENCES RS_cells (id)
)
''')
# Коды маркировки в документе RS_docs_barcodes
Rs.append('''
CREATE TABLE IF NOT EXISTS RS_docs_barcodes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
id_doc TEXT NOT NULL
REFERENCES RS_docs (id_doc) ON DELETE CASCADE,
id_good TEXT NOT NULL
REFERENCES RS_goods (id),
id_property TEXT NOT NULL
REFERENCES RS_properties (id),
id_series TEXT NOT NULL
REFERENCES RS_series (id),
id_unit TEXT NOT NULL
REFERENCES RS_units (id) ,
--# id_barcode TEXT NOT NULL
--# REFERENCES RS_marking_codes (id),
barcode_from_scanner TEXT,
is_plan TEXT DEFAULT 0
NOT NULL,
approved TEXT DEFAULT 0,
GTIN TEXT,
Series TEXT
)
''')
#Поток произвольных штрихкодов
Rs.append('''
CREATE TABLE IF NOT EXISTS RS_barc_flow (
id_doc TEXT REFERENCES RS_docs (id_doc),
barcode TEXT
)
''')
Rs.append('''
CREATE TABLE IF NOT EXISTS RS_adr_docs (
id_doc TEXT NOT NULL
PRIMARY KEY,
doc_type TEXT NOT NULL,
doc_n TEXT NOT NULL,
doc_date TEXT NOT NULL,
id_warehouse TEXT NOT NULL
REFERENCES RS_warehouses (id),
verified INTEGER,
sent INTEGER,
add_mark_selection INTEGER,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
control TEXT DEFAULT 0,
allow_fact_input TEXT DEFAULT 0
)
''')
Rs.append('''
CREATE TABLE IF NOT EXISTS RS_adr_docs_table (
id INTEGER PRIMARY KEY AUTOINCREMENT,
id_doc TEXT NOT NULL
REFERENCES RS_adr_docs (id_doc) ON DELETE CASCADE
ON UPDATE SET DEFAULT,
id_good TEXT NOT NULL
REFERENCES RS_goods (id),
id_properties TEXT REFERENCES RS_properties (id),
id_series TEXT REFERENCES RS_series (id),
id_unit TEXT REFERENCES RS_units (id),
qtty REAL,
qtty_plan REAL,
sent INTEGER,
last_updated DATETIME DEFAULT CURRENT_TIMESTAMP,
is_plan TEXT DEFAULT True,
id_cell TEXT REFERENCES RS_cells (id),
table_type TEXT NOT NULL
DEFAULT 'out'
)
''')
Rs.append('''
CREATE TABLE IF NOT EXISTS Error_log (
log TEXT NOT NULL
DEFAULT (''),
timestamp DATETIME DEFAULT (CURRENT_TIMESTAMP))
''')
Rs.append('''
CREATE INDEX IF NOT EXISTS cell_name ON RS_cells (
name
)
''')
Rs.append('''
CREATE INDEX IF NOT EXISTS cell_name ON RS_cells (
barcode
)
''')
# RS_constants + RS_classifier_units + RS_types_goods
# Rs = + RS_goods + RS_properties\
# + RS_series + RS_units + RS_barcodes + RS_marking_codes + RS_docs + RS_docs_barcodes\
# + RS_docs_table + RS_price_types + RS_prices + RS_countragents + RS_warehouses
return Rs
#print(database_shema())
#
# Rs.append(RS_constants)
# Rs.append(RS_classifier_units)
# Rs.append(RS_types_goods)
#
# Rs.append(RS_goods)
# Rs.append(RS_properties)
# Rs.append(RS_series)
# Rs.append(RS_units)
#
# Rs.append(RS_barcodes)
# Rs.append(RS_marking_codes)
#
# Rs.append(RS_docs)
# Rs.append(RS_docs_barcodes)
# Rs.append(RS_docs_table)
#
# Rs.append(RS_price_types)
# Rs.append(RS_prices)
#
# Rs.append(RS_countragents)
# Rs.append(RS_warehouses)
#ui_global.get_query_result(Rs)