"Beta release"
This commit is contained in:
		
							부모
							
								
									208029f41d
								
							
						
					
					
						커밋
						9a61d14eb4
					
				
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -2,4 +2,5 @@ | |||||||
| *.swp | *.swp | ||||||
| *.pyc | *.pyc | ||||||
| config.tetalab.py | config.tetalab.py | ||||||
|  | pg_* | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										135
									
								
								data_migration.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										135
									
								
								data_migration.sh
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,135 @@ | |||||||
|  | #!/bin/bash | ||||||
|  | DB_SRC_HOST=marian.local.tetalab.org | ||||||
|  | DB_SRC=/var/www/stock.tetalab.org/stock | ||||||
|  | DB_DST=tetastock | ||||||
|  | DB_DST_USER=tetastock | ||||||
|  | DB_DST_HOST=sonny.local.tetalab.org | ||||||
|  | 
 | ||||||
|  | PSQL_OPTS="-t -U ${DB_DST_USER} -h ${DB_DST_HOST} -d ${DB_DST}" | ||||||
|  | 
 | ||||||
|  | function log { | ||||||
|  |   echo -e "\033[93m$@\033[0m" | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function red { | ||||||
|  |   echo -e "\033[91m$@\033[0m" | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function out { | ||||||
|  |   echo -e "\033[91m$@\033[0m" | ||||||
|  |   exit 1 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | log "[+] Suppression des données existantes" | ||||||
|  | psql -t ${PSQL_OPTS} -c "delete from stock_kit_compositions where id > 0;" | ||||||
|  | psql -t ${PSQL_OPTS} -c "delete from stock_componants where id > 0;" | ||||||
|  | psql -t ${PSQL_OPTS} -c "delete from stock_kits where id > 0;" | ||||||
|  | 
 | ||||||
|  | log "[+] Récupération des composants" | ||||||
|  | 
 | ||||||
|  | IFS_BAK=${IFS} | ||||||
|  | IFS=$'\n' | ||||||
|  | for LINE in $(ssh ${DB_SRC_HOST} sqlite3 ${DB_SRC} "'select distinct composants.id, composants.groupe, composants.type, composants.taille, composants.couleur, composants.valeur, composants.quantité , composants.emplacement from composants order by composants.groupe;'") | ||||||
|  | do | ||||||
|  |   IFS=${IFS_BAK} | ||||||
|  |   COMP_ID=$(echo ${LINE} | awk -F'|' '{print $1}') | ||||||
|  |   RAND=$(head -n40 /dev/urandom | md5sum | cut -d' ' -f1) | ||||||
|  |   REF=$(echo ${LINE} | awk -F'|' '{print $2}') | ||||||
|  |   REF=$(echo "${REF:0:3}-${RAND:0:5}" | tr [a-z] [A-Z] | sed 's/É/E/') | ||||||
|  |   GROUP=$(echo ${LINE} | awk -F'|' '{print $2}' | sed 's/^ *//;s/ *$//') | ||||||
|  |   TYPE=$(echo ${LINE} | awk -F'|' '{print $3}' | sed 's/^ *//;s/ *$//') | ||||||
|  |   SIZE=$(echo ${LINE} | awk -F'|' '{print $4}' | sed 's/^ *//;s/ *$//') | ||||||
|  |   COLOR=$(echo ${LINE} | awk -F'|' '{print $5}' | sed 's/^ *//;s/ *$//') | ||||||
|  |   if [ "${COLOR}" == "0" ]; then | ||||||
|  |     COLOR='' | ||||||
|  |   fi | ||||||
|  |   VALUE=$(echo ${LINE} | awk -F'|' '{print $6}' | sed 's/^ *//;s/ *$//') | ||||||
|  |   QUANTITY=$(echo ${LINE} | awk -F'|' '{print $7}' | sed 's/^ *//;s/ *$//') | ||||||
|  |   DESIGNATION=$(echo "${GROUP} ${TYPE} ${SIZE} ${COLOR} ${VALUE}" | sed 's/^ *//;s/ *$//;s/  +*/ /g;s/  */ /g') | ||||||
|  |   if [ ${#QUANTITY} -eq 0 ]; then | ||||||
|  |     QUANTITY=0 | ||||||
|  |   fi | ||||||
|  |   PLACE=$(echo ${LINE} | awk -F'|' '{print $8}') | ||||||
|  |   log "  [+] Vérification de l'existence d'un doublon avec ${DESIGNATION}" | ||||||
|  |   SQLREQ="select id from stock_componants where designation='${DESIGNATION}';" | ||||||
|  |   EXIST=$(psql ${PSQL_OPTS} -c "${SQLREQ}") | ||||||
|  |   if [ ! ${#EXIST} -eq 0 ]; then | ||||||
|  |     red "    => Composant ${EXIST} a déjà une désignation égale à ${DESIGNATION}" | ||||||
|  |     continue | ||||||
|  |   fi | ||||||
|  |   log "  [+] Enregistrement du nouveau composant: ${REF} / ${DESIGNATION}" | ||||||
|  |   SQLREQ="insert into stock_componants (reference, designation, place, quantity) values ('${REF}', '${DESIGNATION}', '${PLACE}', ${QUANTITY});" | ||||||
|  |   psql ${PSQL_OPTS} -c "${SQLREQ}" || out "${SQLREQ}" | ||||||
|  |   IFS=$'\n' | ||||||
|  | done | ||||||
|  | 
 | ||||||
|  | log "[+] Récupération des ID des kits" | ||||||
|  | for KIT_ID in $(ssh ${DB_SRC_HOST} sqlite3 ${DB_SRC} "'select distinct id from kit;'") | ||||||
|  | do | ||||||
|  |   IFS=${IFS_BAK} | ||||||
|  |   # On recupere le kit | ||||||
|  |   log "  [+] Récupération du nom pour KIT_ID: ${KIT_ID}" | ||||||
|  |   SQLREQ="select description from kit where ID=${KIT_ID};" | ||||||
|  |   NAME=$(ssh ${DB_SRC_HOST} sqlite3 ${DB_SRC} "'${SQLREQ}'") | ||||||
|  |   if [ ${#NAME} -lt 1 ]; then | ||||||
|  |     log "[-] Trace: ${SQLREQ}" | ||||||
|  |     out "Nom introuvable pour ${KIT_ID}" | ||||||
|  |   fi | ||||||
|  |   DESIGNATION=${NAME} | ||||||
|  |   # On cree le kit | ||||||
|  |   log "  [+] Enregistrement du kit ${NAME} / ${DESIGNATION}" | ||||||
|  |   SQLREQ="insert into stock_kits (name, designation) values ('${NAME}', '${DESIGNATION}');" | ||||||
|  |   psql ${PSQL_OPTS} -c "${SQLREQ}" || out "${SQLREQ}" | ||||||
|  |   log "  [+] Récupération du nouvel ID du kit" | ||||||
|  |   # On recupere l'ID du nouveau kit | ||||||
|  |   SQLREQ="select id from stock_kits where name='${NAME}' and designation='${DESIGNATION}';" | ||||||
|  |   NKIT_ID=$(psql ${PSQL_OPTS} -c "${SQLREQ}") | ||||||
|  |   if [ ${#NKIT_ID} -lt 1 ]; then | ||||||
|  |     log "[-] Trace: ${SQLREQ}" | ||||||
|  |     out "Pas de NKIT_ID pour ${NAME}" | ||||||
|  |   fi | ||||||
|  |   log "    => ${NKIT_ID}" | ||||||
|  |   # On recupere les composants du kit | ||||||
|  |   log "  [+] Récupération de la liste des composants du kit" | ||||||
|  |   SQLREQ="select id_composant, quantite from composants_kit where id_kit='${KIT_ID}';" | ||||||
|  |   RECS=$(ssh ${DB_SRC_HOST} sqlite3 ${DB_SRC} "'${SQLREQ}'") | ||||||
|  |   IFS=$'\n' | ||||||
|  |   for REC in ${RECS} | ||||||
|  |   do | ||||||
|  |     IFS=${IFS_BAK} | ||||||
|  |     COMP_ID=$(echo ${REC} | awk -F'|' '{print $1}') | ||||||
|  |     QUANTITY=$(echo ${REC} | awk -F'|' '{print $2}') | ||||||
|  |     IFS=${IFS_BAK} | ||||||
|  |     log "    [+] Récupération du composant: ${COMP_ID}" | ||||||
|  |     SQLREQ="select composants.id, composants.groupe, composants.type, composants.taille, composants.couleur, composants.valeur, composants.quantité , composants.emplacement from composants where id=${COMP_ID} order by composants.groupe;" | ||||||
|  |     COMP=$(ssh ${DB_SRC_HOST} sqlite3 ${DB_SRC} "'${SQLREQ}'") | ||||||
|  |     if [ ${#COMP} -lt 1 ]; then | ||||||
|  |       red "[-] Trace: ${SQLREQ}" | ||||||
|  |       red "Pas de composant avec ID ${COMP_ID}" | ||||||
|  |       continue | ||||||
|  |     fi | ||||||
|  |     GROUP=$(echo ${COMP} | awk -F'|' '{print $2}' | sed 's/^ *//;s/ *$//') | ||||||
|  |     TYPE=$(echo ${COMP} | awk -F'|' '{print $3}' | sed 's/^ *//;s/ *$//') | ||||||
|  |     SIZE=$(echo ${COMP} | awk -F'|' '{print $4}' | sed 's/^ *//;s/ *$//') | ||||||
|  |     COLOR=$(echo ${COMP} | awk -F'|' '{print $5}' | sed 's/^ *//;s/ *$//') | ||||||
|  |     if [ "${COLOR}" == "0" ]; then | ||||||
|  |       COLOR='' | ||||||
|  |     fi | ||||||
|  |     VALUE=$(echo ${COMP} | awk -F'|' '{print $6}' | sed 's/^ *//;s/ *$//') | ||||||
|  |     DESIGNATION=$(echo "${GROUP} ${TYPE} ${SIZE} ${COLOR} ${VALUE}" | sed 's/^ *//;s/ *$//;s/  +*/ /g;s/  */ /g') | ||||||
|  |     log "    [+] Récupération du nouvel ID du composant" | ||||||
|  |     SQLREQ="select ID from stock_componants where designation='${DESIGNATION}';" | ||||||
|  |     NCOMP_ID=$(psql ${PSQL_OPTS}  -c "${SQLREQ}") | ||||||
|  |     if [ ${#NCOMP_ID} -lt 1 ]; then | ||||||
|  |       log "[-] Trace: ${SQLREQ}" | ||||||
|  |       out "Pas de composant avec NCOMP_ID ${NCOMP_ID}" | ||||||
|  |     fi | ||||||
|  |     log "      [+] ${NCOMP_ID}" | ||||||
|  |     log "    [+] Enregistrement du composant ${NCOMP_ID} dans la composition du kit ${NKIT_ID} (q: ${QUANTITY})" | ||||||
|  |     SQLREQ="insert into stock_kit_compositions (kit_id, componant_id, quantity) values (${NKIT_ID}, ${NCOMP_ID}, ${QUANTITY})" | ||||||
|  |     psql ${PSQL_OPTS}  -c "${SQLREQ}" || out "${SQLREQ}" | ||||||
|  |     IFS=$'\n' | ||||||
|  |   done | ||||||
|  |   IFS=$'\n' | ||||||
|  | done | ||||||
|  | IFS=${IFS_BAK} | ||||||
| @ -67,6 +67,7 @@ function login() { | |||||||
| 
 | 
 | ||||||
| function logout() { | function logout() { | ||||||
|   setcookie('token', '', 30); |   setcookie('token', '', 30); | ||||||
|  |   setcookie('session', '', 30); | ||||||
|   document.location='/'; |   document.location='/'; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -140,7 +141,6 @@ function c_next_page(nexthop) { | |||||||
|   update_componants(); |   update_componants(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| // Search componants
 | // Search componants
 | ||||||
| function search_componants_by_reference(obj) { | function search_componants_by_reference(obj) { | ||||||
|   setcookie('c_reference', obj.value, 30); |   setcookie('c_reference', obj.value, 30); | ||||||
| @ -651,7 +651,7 @@ function add_kit_componant(kit_id, componant_id) { | |||||||
|     } |     } | ||||||
|   }; |   }; | ||||||
|    |    | ||||||
|   xhttp.open('POST', '/kits/add/'+kit_id+'/'+componant_id, true); |   xhttp.open('POST', '/kits/composition/add/'+kit_id, true); | ||||||
|   xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); |   xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | ||||||
|   xhttp.send(); |   xhttp.send(); | ||||||
| } | } | ||||||
|  | |||||||
| @ -162,7 +162,7 @@ div.error { | |||||||
|   background-repeat: no-repeat; |   background-repeat: no-repeat; | ||||||
|   background-position: center center; |   background-position: center center; | ||||||
|   background-color: #000000; |   background-color: #000000; | ||||||
|   height: 476px; |   height: 531px; | ||||||
|   padding: 10px; |   padding: 10px; | ||||||
|   text-align: center; |   text-align: center; | ||||||
|   font-size: 70px; |   font-size: 70px; | ||||||
| @ -175,7 +175,7 @@ div.wip { | |||||||
|   background-repeat: no-repeat; |   background-repeat: no-repeat; | ||||||
|   background-position: center center; |   background-position: center center; | ||||||
|   background-color: #000000; |   background-color: #000000; | ||||||
|   height: 476px; |   height: 531px; | ||||||
|   padding: 10px; |   padding: 10px; | ||||||
|   text-align: center; |   text-align: center; | ||||||
|   font-size: 70px; |   font-size: 70px; | ||||||
|  | |||||||
							
								
								
									
										77
									
								
								stock.sql
									
									
									
									
									
								
							
							
						
						
									
										77
									
								
								stock.sql
									
									
									
									
									
								
							| @ -34,7 +34,7 @@ CREATE TABLE stock_providers ( | |||||||
| CREATE TABLE stock_componants ( | CREATE TABLE stock_componants ( | ||||||
|   id serial primary key, |   id serial primary key, | ||||||
|   reference varchar(20) unique not NULL, |   reference varchar(20) unique not NULL, | ||||||
|   designation varchar(50) not NULL, |   designation varchar(100) not NULL, | ||||||
|   last_price NUMERIC not NULL default 0, |   last_price NUMERIC not NULL default 0, | ||||||
|   mean_price NUMERIC not NULL default 0, |   mean_price NUMERIC not NULL default 0, | ||||||
|   quantity NUMERIC not NULL default 0, |   quantity NUMERIC not NULL default 0, | ||||||
| @ -70,77 +70,4 @@ insert into stock_users (mail, password, name) values | |||||||
| ('doug.letough@free.fr', '$2a$08$578910202124252729313uTyggq4ANEjMljcClFriOqcsttB2fnAW', 'Doug Le Tough'); | ('doug.letough@free.fr', '$2a$08$578910202124252729313uTyggq4ANEjMljcClFriOqcsttB2fnAW', 'Doug Le Tough'); | ||||||
| insert into stock_users (mail, password, name) values | insert into stock_users (mail, password, name) values | ||||||
| ('doug@redatomik.org', '$2a$08$578910202124252729313uTyggq4ANEjMljcClFriOqcsttB2fnAW', 'Doug Le Tough'); | ('doug@redatomik.org', '$2a$08$578910202124252729313uTyggq4ANEjMljcClFriOqcsttB2fnAW', 'Doug Le Tough'); | ||||||
| 
 | insert into stock_users (mail, password, name) values ('test', '$2b$08$OkfihuGRyLdpftBpGhnpeeeUhUTQS0oXvR2NFByC.65XCKKvPBWHS'); | ||||||
| insert into stock_providers (name, address, mail, url, comment) |  | ||||||
|   values ('Tous', 'N/A', 'N/A', 'N/A', 'N/A'); |  | ||||||
| insert into stock_providers (name, address, mail, url, comment) |  | ||||||
|   values ('Aucun', 'N/A', 'N/A', 'N/A', 'N/A'); |  | ||||||
| insert into stock_providers (name, address, mail, url, comment) |  | ||||||
|   values ('China Elec Co', 'Beijing', 'sales@chinaelecco.cc', 'https://chinaelecco.cc', 'Pas cher mais délai excessif et composants pourris'); |  | ||||||
| 
 |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Res-01', 'Resistance 10KΩ', 13.34, 12.42, 73, 0, 'B 43', 3); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Lor-01', '1 Lorem ipsum dolor sit ametconsectetur adipiscing', 13.34, 12.42, 73, 0, 'B 43', 3); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Res-02', 'Resistance 11KΩ', 13.34, 12.42, 73, 0, 'B 43', 3); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Res-03', 'Resistance 12KΩ', 13.34, 12.42, 73, 0, 'B 43', 3); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Res-04', 'Resistance 13KΩ', 13.34, 12.42, 73, 0, 'B 43', 2); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Res-05', 'Resistance 14KΩ', 13.34, 12.42, 73, 0, 'B 43', 3); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Lor-02', '2 Lorem ipsum dolor sit ametconsectetur adipiscing', 13.34, 12.42, 73, 0, 'B 43', 3); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Res-06', 'Resistance 15KΩ', 13.34, 12.42, 73, 0, 'B 43', 3); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Res-07', 'Resistance 16KΩ', 13.34, 12.42, 73, 0, 'B 43', 3); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Res-08', 'Resistance 17KΩ', 13.34, 12.42, 73, 0, 'B 43', 3); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Res-09', 'Resistance 18KΩ', 13.34, 12.42, 73, 0, 'B 43', 3); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Lor-03', '3 Lorem ipsum dolor sit ametconsectetur adipiscing', 13.34, 12.42, 73, 0, 'B 43', 3); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Res-10', 'Resistance 19KΩ', 13.34, 12.42, 73, 0, 'B 43', 2); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Res-11', 'Resistance 20KΩ', 13.34, 12.42, 73, 0, 'B 43', 3); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Res-12', 'Resistance 21KΩ', 13.34, 12.42, 73, 0, 'B 43', 3); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Res-13', 'Resistance 22KΩ', 13.34, 12.42, 73, 0, 'B 43', 3); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Lor-04', '4 Lorem ipsum dolor sit ametconsectetur adipiscing', 13.34, 12.42, 73, 0, 'B 43', 3); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Res-14', 'Resistance 23KΩ', 13.34, 12.42, 73, 0, 'B 43', 3); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Res-15', 'Resistance 24KΩ', 13.34, 12.42, 73, 0, 'B 43', 3); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Res-16', 'Resistance 25KΩ', 13.34, 12.42, 73, 0, 'B 43', 3); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Res-17', 'Resistance 26KΩ', 13.34, 12.42, 73, 0, 'B 43', 2); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Lor-05', '5 Lorem ipsum dolor sit ametconsectetur adipiscing', 13.34, 12.42, 73, 0, 'B 43', 3); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Res-18', 'Resistance 27KΩ', 13.34, 12.42, 73, 0, 'B 43', 3); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Res-19', 'Resistance 28KΩ', 13.34, 12.42, 73, 0, 'B 43', 3); |  | ||||||
| insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id) |  | ||||||
|   values ('Res-20', 'Resistance 29KΩ', 13.34, 12.42, 73, 0, 'B 43', 3); |  | ||||||
| 
 |  | ||||||
| insert into stock_kits (name, designation) values ('Kit_test', 'Kit de test'); |  | ||||||
| insert into stock_kits (name, designation) values ('Kit2_test2', 'Kit de test 2'); |  | ||||||
| insert into stock_kits (name, designation) values ('MF_K', 'Mother fucking kit'); |  | ||||||
| 
 |  | ||||||
| insert into stock_kit_compositions (kit_id, componant_id, quantity) values (1, 5, 1); |  | ||||||
| insert into stock_kit_compositions (kit_id, componant_id, quantity) values (1, 8, 2); |  | ||||||
| insert into stock_kit_compositions (kit_id, componant_id, quantity) values (1, 10, 2); |  | ||||||
| insert into stock_kit_compositions (kit_id, componant_id, quantity) values (1, 12, 7); |  | ||||||
| 
 |  | ||||||
| insert into stock_kit_compositions (kit_id, componant_id, quantity) values (2, 5, 2); |  | ||||||
| insert into stock_kit_compositions (kit_id, componant_id, quantity) values (2, 4, 1); |  | ||||||
| insert into stock_kit_compositions (kit_id, componant_id, quantity) values (2, 9, 3); |  | ||||||
| insert into stock_kit_compositions (kit_id, componant_id, quantity) values (2, 22, 2); |  | ||||||
| insert into stock_kit_compositions (kit_id, componant_id, quantity) values (2, 1, 5); |  | ||||||
| insert into stock_kit_compositions (kit_id, componant_id, quantity) values (2, 14, 8); |  | ||||||
|  | |||||||
| @ -54,9 +54,9 @@ | |||||||
|                       id='designation' |                       id='designation' | ||||||
|                       type='text' |                       type='text' | ||||||
|                       onchange='javascript:update_componant(this, {{ componant.id }}, "text");' |                       onchange='javascript:update_componant(this, {{ componant.id }}, "text");' | ||||||
|                       maxlength='50' |                       maxlength='100' | ||||||
|                       title='Désignation (max. 50)' |                       title='Désignation (max. 100)' | ||||||
|                       placeholder='Désignation (max. 50)' |                       placeholder='Désignation (max. 100)' | ||||||
|                       value='{{ componant.designation }}' /> |                       value='{{ componant.designation }}' /> | ||||||
|               </div> |               </div> | ||||||
|               <div class='input_block'> |               <div class='input_block'> | ||||||
|  | |||||||
| @ -4,7 +4,7 @@ | |||||||
| {% endblock %} | {% endblock %} | ||||||
| {% block title %}Éditer un kit{% endblock %} | {% block title %}Éditer un kit{% endblock %} | ||||||
|         {% block top_menu %} |         {% block top_menu %} | ||||||
|         <span class='top_menu_item' onclick='javascript:document.location="/providers";'>Gérer les kits</span> |         <span class='top_menu_item' onclick='javascript:document.location="/kits";'>Gérer les kits</span> | ||||||
|         <span class='top_menu_item_selected' onclick='javascript:document.location="/kits/{{ kit.id }}";'>Éditer un kit</span> |         <span class='top_menu_item_selected' onclick='javascript:document.location="/kits/{{ kit.id }}";'>Éditer un kit</span> | ||||||
|         {% endblock %} |         {% endblock %} | ||||||
|           {% block left_menu %} |           {% block left_menu %} | ||||||
|  | |||||||
| @ -16,10 +16,10 @@ | |||||||
|               {% set row_class = cycler('odd', 'even') %} |               {% set row_class = cycler('odd', 'even') %} | ||||||
|               {% for componant in componants %} |               {% for componant in componants %} | ||||||
|               <div class='row_block {{ row_class.next() }}'> |               <div class='row_block {{ row_class.next() }}'> | ||||||
|                 <text style='width: 190px;'>{{ componant.reference }}</text> |                 <text style='width: 190px;' title='{{ componant.reference }}'>{{ componant.reference }}</text> | ||||||
|                 <text class='border_left' style='width: 439px;'>{{ componant.designation }}</text> |                 <text class='border_left' style='width: 439px;' title='{{ componant.designation }}'>{{ componant.designation }}</text> | ||||||
|                 <text class='num border_left' style='width: 89px;'>{{ componant.quantity }}</text> |                 <text class='num border_left' style='width: 89px;' title='{{ componant.quantity }}'>{{ componant.quantity }}</text> | ||||||
|                 <text class='num border_right border_left' style='width: 139px;'>{{ componant.place }}</text> |                 <text class='num border_right border_left' style='width: 139px;' title='{{ componant.place }}'>{{ componant.place }}</text> | ||||||
|                 <div class='action_bar_block border_left' style='width: 89px;'> |                 <div class='action_bar_block border_left' style='width: 89px;'> | ||||||
|                   <input |                   <input | ||||||
|                     type='image' |                     type='image' | ||||||
|  | |||||||
| @ -10,10 +10,10 @@ | |||||||
|               {% set row_class = cycler('odd', 'even') %} |               {% set row_class = cycler('odd', 'even') %} | ||||||
|               {% for componant in componants %} |               {% for componant in componants %} | ||||||
|               <div class='row_block {{ row_class.next() }}'> |               <div class='row_block {{ row_class.next() }}'> | ||||||
|                 <text style='width: 190px;'>{{ componant.reference }}</text> |                 <text style='width: 190px;' title='{{ componant.reference }}'>{{ componant.reference }}</text> | ||||||
|                 <text class='border_left' style='width: 439px;'>{{ componant.designation }}</text> |                 <text class='border_left' style='width: 439px;' title='{{ componant.designation }}'>{{ componant.designation }}</text> | ||||||
|                 <text class='num border_left' style='width: 89px;'>{{ componant.quantity }}</text> |                 <text class='num border_left' style='width: 89px;'>{{ componant.quantity }}</text> | ||||||
|                 <text class='num border_right border_left' style='width: 139px;'>{{ componant.place }}</text> |                 <text class='num border_right border_left' style='width: 139px;' title='{{ componant.place }}'>{{ componant.place }}</text> | ||||||
|                 <div class='action_bar_block border_left' style='width: 89px;'> |                 <div class='action_bar_block border_left' style='width: 89px;'> | ||||||
|                   <input |                   <input | ||||||
|                     type='image' |                     type='image' | ||||||
|  | |||||||
| @ -8,14 +8,20 @@ | |||||||
|               </text> |               </text> | ||||||
|               <div class='row_block border_bottom'> |               <div class='row_block border_bottom'> | ||||||
|                 <label style='width: 209px;' onclick='javascript:update_kits_by_name("{{ order }}");'>Nom</label> |                 <label style='width: 209px;' onclick='javascript:update_kits_by_name("{{ order }}");'>Nom</label> | ||||||
|                 <label class='border_left' style='width: 700px;' onclick='javascript:update_kits_by_designation("{{ order }}");'>Désignation</label> |                 <label class='border_left' style='width: 600px;' onclick='javascript:update_kits_by_designation("{{ order }}");'>Désignation</label> | ||||||
|  |                 <label class='border_left' style='width: 99px;' style='cursor: default;'>Max dispo</label> | ||||||
|                 <label class='border_left' style='width: 89px;' style='cursor: default;'>Action</label> |                 <label class='border_left' style='width: 89px;' style='cursor: default;'>Action</label> | ||||||
|               </div> |               </div> | ||||||
|               {% set row_class = cycler('odd', 'even') %} |               {% set row_class = cycler('odd', 'even') %} | ||||||
|               {% for kit in kits %} |               {% for kit in kits %} | ||||||
|               <div class='row_block {{ row_class.next() }}'> |               <div class='row_block {{ row_class.next() }}'> | ||||||
|                 <text style='width: 199px;'>{{ kit.name }}</text> |                 <text style='width: 199px;' title='{{ kit.name }}'>{{ kit.name }}</text> | ||||||
|                 <text class='border_left' style='width: 690px;'>{{ kit.designation }}</text> |                 <text class='border_left' style='width: 590px;' title='{{ kit.designation }}'>{{ kit.designation }}</text> | ||||||
|  |                 {% set sclass='red' %} | ||||||
|  |                 {% if kit. max_kit > 1 %} | ||||||
|  |                 {%    set sclass='' %} | ||||||
|  |                 {% endif %} | ||||||
|  |                 <text class='border_left num {{ sclass }}' style='width: 89px;' title='{{ kit.max_kit }}'>{{ kit.max_kit }}</text> | ||||||
|                 <div class='action_bar_block border_left' style='width: 89px;'> |                 <div class='action_bar_block border_left' style='width: 89px;'> | ||||||
|                   <input |                   <input | ||||||
|                     type='image' |                     type='image' | ||||||
|  | |||||||
| @ -17,9 +17,9 @@ | |||||||
|               {% for provider in providers %} |               {% for provider in providers %} | ||||||
|               <div class='row_block {{ row_class.next() }}'> |               <div class='row_block {{ row_class.next() }}'> | ||||||
|                 <text style='width: 199px;'>{{ provider.name }}</text> |                 <text style='width: 199px;'>{{ provider.name }}</text> | ||||||
|                 <text class='border_left' style='width: 189px;'>{{ provider.address }}</text> |                 <text class='border_left' style='width: 189px;' title='{{ provider.address }}'>{{ provider.address }}</text> | ||||||
|                 <text class='border_left' style='width: 189px;'>{{ provider.mail }}</text> |                 <text class='border_left' style='width: 189px;' title='{{ provider.mail }}'>{{ provider.mail }}</text> | ||||||
|                 <text class='border_left' style='width: 289px;'>{{ provider.url }}</text> |                 <text class='border_left' style='width: 289px;' title='{{ provider.url }}'>{{ provider.url }}</text> | ||||||
|                 <div class='action_bar_block border_left' style='width: 89px;'> |                 <div class='action_bar_block border_left' style='width: 89px;'> | ||||||
|                   <input |                   <input | ||||||
|                     type='image' |                     type='image' | ||||||
|  | |||||||
| @ -1,7 +1,7 @@ | |||||||
| <!DOCTYPE html>                                                                                                                                                            | <!DOCTYPE html>                                                                                                                                                            | ||||||
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr" dir="ltr"> | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr" dir="ltr"> | ||||||
|   <head> |   <head> | ||||||
|     <title>Référentiel Infrastructure Tetalab - {% block title %}How The Fuck{% endblock %}</title> |     <title>Tetastock</title> | ||||||
|     <meta name="viewport" content="initial-scale=1.0"> |     <meta name="viewport" content="initial-scale=1.0"> | ||||||
|     <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> |     <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> | ||||||
|     <link rel="stylesheet" type="text/css" href="/static/style/style.css" /> |     <link rel="stylesheet" type="text/css" href="/static/style/style.css" /> | ||||||
| @ -10,8 +10,8 @@ | |||||||
|   <body> |   <body> | ||||||
|     <div class='main_wrapper'> |     <div class='main_wrapper'> | ||||||
|       <div class='center'> |       <div class='center'> | ||||||
|         <div class='banner' title='Référentiel infrastrusture Tetalab'> |         <div class='banner' title='Tetastock'> | ||||||
|           Référentiel Infrastructure Tetalab |           Tetastock | ||||||
|         </div> |         </div> | ||||||
|         <div class='top_menu'> |         <div class='top_menu'> | ||||||
|           <span class='top_menu_item' onclick='javascript:document.location="/";'>Retour</span> |           <span class='top_menu_item' onclick='javascript:document.location="/";'>Retour</span> | ||||||
|  | |||||||
							
								
								
									
										75
									
								
								tetastock.py
									
									
									
									
									
								
							
							
						
						
									
										75
									
								
								tetastock.py
									
									
									
									
									
								
							| @ -77,6 +77,28 @@ class Stock_orders(db.Model): | |||||||
| ######################################################################## | ######################################################################## | ||||||
| # Here comes the fun | # Here comes the fun | ||||||
| ######################################################################## | ######################################################################## | ||||||
|  | def get_max_kit(kit_id): | ||||||
|  |   """ Get max available kit from kit.id """ | ||||||
|  |   default_max_kit = float("inf") | ||||||
|  |   max_kit = default_max_kit | ||||||
|  |   composition = Stock_kit_compositions.query.filter_by(kit_id=kit_id).with_entities( | ||||||
|  |                                                       Stock_kit_compositions.componant_id, | ||||||
|  |                                                       Stock_kit_compositions.quantity).all() | ||||||
|  |   for c_componant in composition: | ||||||
|  |     componant = Stock_componants.query.filter_by(id=c_componant.componant_id).first() | ||||||
|  |     if componant: | ||||||
|  |       try: | ||||||
|  |         mkit = int(componant.quantity) / int(c_componant.quantity) | ||||||
|  |       except ZeroDivisionError as e: | ||||||
|  |         print "[+] Error at get_max_kit:" | ||||||
|  |         print "------------------------------" | ||||||
|  |         print "%s" % e.message | ||||||
|  |         print "------------------------------"         | ||||||
|  |       if mkit < max_kit: | ||||||
|  |         max_kit = mkit | ||||||
|  |   if max_kit == default_max_kit: | ||||||
|  |     max_kit = 0 | ||||||
|  |   return max_kit | ||||||
| 
 | 
 | ||||||
| def sync_cookies(response, session): | def sync_cookies(response, session): | ||||||
|   """ Sync cookies with session """ |   """ Sync cookies with session """ | ||||||
| @ -85,7 +107,7 @@ def sync_cookies(response, session): | |||||||
|     if key != u'session': |     if key != u'session': | ||||||
|       print '[c]', key, session[key] |       print '[c]', key, session[key] | ||||||
| 
 | 
 | ||||||
| def sync_session(request, session, offset_reset): | def sync_session(request, session): | ||||||
|   """ Sync session with cookies""" |   """ Sync session with cookies""" | ||||||
|   for key in request.cookies: |   for key in request.cookies: | ||||||
|     try: |     try: | ||||||
| @ -101,10 +123,6 @@ def sync_session(request, session, offset_reset): | |||||||
|       except ValueError: |       except ValueError: | ||||||
|         # Value is not an int, will be treated as string |         # Value is not an int, will be treated as string | ||||||
|         session[key] = str(request.cookies[key].encode('utf8')) |         session[key] = str(request.cookies[key].encode('utf8')) | ||||||
|     if key in offset_reset and len(str(session[key])) > 0 and old != str(session[key]): |  | ||||||
|       session['c_offset'] = 0 |  | ||||||
|       session['p_offset'] = 0 |  | ||||||
|       session['k_offset'] = 0 |  | ||||||
|     if key != u'session': |     if key != u'session': | ||||||
|       print '[s]', key, request.cookies[key] |       print '[s]', key, request.cookies[key] | ||||||
| 
 | 
 | ||||||
| @ -133,7 +151,6 @@ def check_user(request, session): | |||||||
|     # Password mismatch |     # Password mismatch | ||||||
|     return False |     return False | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| def resume_session(func): | def resume_session(func): | ||||||
|   """ Resume pending session """ |   """ Resume pending session """ | ||||||
|   @wraps(func) |   @wraps(func) | ||||||
| @ -156,9 +173,6 @@ def resume_session(func): | |||||||
|     k_count = 0 |     k_count = 0 | ||||||
|     kc_quantity = 0 |     kc_quantity = 0 | ||||||
|     kc_limit = 3 |     kc_limit = 3 | ||||||
|     offset_reset = [u'c_reference', u'c_designation', u'c_place', |  | ||||||
|                     u'c_provider', u'p_name', u'p_address', u'p_mail', u'p_url', |  | ||||||
|                     u'k_name', u'k_designation'] |  | ||||||
|     if not u'token' in session: |     if not u'token' in session: | ||||||
|       session[u'token'] = empty |       session[u'token'] = empty | ||||||
|     if not u'password' in session: |     if not u'password' in session: | ||||||
| @ -260,8 +274,7 @@ def resume_session(func): | |||||||
|     if not u'kc_reference' in session: |     if not u'kc_reference' in session: | ||||||
|       session[u'kc_reference'] = empty |       session[u'kc_reference'] = empty | ||||||
|     # Cookies/session sync |     # Cookies/session sync | ||||||
|     sync_session(request, session, offset_reset) |     sync_session(request, session) | ||||||
| 
 |  | ||||||
|     # Switch sort order |     # Switch sort order | ||||||
|     refresh = {u'desc': u'asc', u'asc': u'desc'} |     refresh = {u'desc': u'asc', u'asc': u'desc'} | ||||||
|     if session[u'c_order_refresh'] == 1: |     if session[u'c_order_refresh'] == 1: | ||||||
| @ -273,7 +286,6 @@ def resume_session(func): | |||||||
|     if session[u'k_order_refresh'] == 1: |     if session[u'k_order_refresh'] == 1: | ||||||
|       session[u'k_order'] = refresh[session[u'k_order']] |       session[u'k_order'] = refresh[session[u'k_order']] | ||||||
|       session[u'k_order_refresh'] = 0 |       session[u'k_order_refresh'] = 0 | ||||||
| 
 |  | ||||||
|     # Check for valid session |     # Check for valid session | ||||||
|     if not check_user(request, session): |     if not check_user(request, session): | ||||||
|       # User is not logged in, send him back to login page |       # User is not logged in, send him back to login page | ||||||
| @ -315,7 +327,7 @@ def componants(): | |||||||
|                             place=session[u'c_place'].decode('utf8'), |                             place=session[u'c_place'].decode('utf8'), | ||||||
|                             provider_id=session[u'c_provider']) |                             provider_id=session[u'c_provider']) | ||||||
| 
 | 
 | ||||||
| @app.route('/componants/<componant_id>') | @app.route('/componants/<componant_id>', methods=['GET', 'POST']) | ||||||
| @resume_session | @resume_session | ||||||
| def get_componant(componant_id): | def get_componant(componant_id): | ||||||
|   """ Edit componant """ |   """ Edit componant """ | ||||||
| @ -348,7 +360,7 @@ def update_componant(componant_id): | |||||||
|       pass |       pass | ||||||
|   return 'KO' |   return 'KO' | ||||||
| 
 | 
 | ||||||
| @app.route('/componants/delete/<componant_id>') | @app.route('/componants/delete/<componant_id>', methods=['GET', 'POST']) | ||||||
| @resume_session | @resume_session | ||||||
| def delete_componant(componant_id): | def delete_componant(componant_id): | ||||||
|   """ Delete componant """ |   """ Delete componant """ | ||||||
| @ -392,20 +404,20 @@ def new_componant(): | |||||||
|     return 'KO' |     return 'KO' | ||||||
|   return 'OK' |   return 'OK' | ||||||
| 
 | 
 | ||||||
| @app.route('/componants/in/<componant_id>') | @app.route('/componants/in') | ||||||
| @resume_session | @resume_session | ||||||
| def in_componants(): | def in_componants(): | ||||||
|   """ Incoming order """ |   """ Incoming order """ | ||||||
|   return render_template('wip.html') |   return render_template('wip.html') | ||||||
| 
 | 
 | ||||||
| @app.route('/componants/out/<componant_id>') | @app.route('/componants/out') | ||||||
| @resume_session | @resume_session | ||||||
| def out_componants(): | def out_componants(): | ||||||
|   """ Outgoing order """ |   """ Outgoing order """ | ||||||
|   return render_template('wip.html') |   return render_template('wip.html') | ||||||
| 
 | 
 | ||||||
| ## Componants update result set | ## Componants update result set | ||||||
| @app.route('/componants/update', methods=['POST']) | @app.route('/componants/update', methods=['GET', 'POST']) | ||||||
| @resume_session | @resume_session | ||||||
| def update_componants(): | def update_componants(): | ||||||
|   """ Display componants list """ |   """ Display componants list """ | ||||||
| @ -719,6 +731,9 @@ def search_kits(): | |||||||
|   kits = kits.limit(session[u'k_limit']) |   kits = kits.limit(session[u'k_limit']) | ||||||
|   # Get result |   # Get result | ||||||
|   kits = kits.all() |   kits = kits.all() | ||||||
|  |   for kit in kits: | ||||||
|  |     max_kit = get_max_kit(kit.id) | ||||||
|  |     setattr(kit, 'max_kit', max_kit) | ||||||
|   response = app.make_response(render_template('result_kits.html', |   response = app.make_response(render_template('result_kits.html', | ||||||
|                             kits=kits, |                             kits=kits, | ||||||
|                             offset=session[u'k_offset'] , |                             offset=session[u'k_offset'] , | ||||||
| @ -738,9 +753,7 @@ def search_kits(): | |||||||
| @app.route('/kits/composition/<kit_id>', methods=['POST']) | @app.route('/kits/composition/<kit_id>', methods=['POST']) | ||||||
| @resume_session | @resume_session | ||||||
| def get_kit_composition(kit_id): | def get_kit_composition(kit_id): | ||||||
|   default_max_kit = 999999999999999 |  | ||||||
|   kit_composition = [] |   kit_composition = [] | ||||||
|   max_kit = default_max_kit |  | ||||||
|   composition = Stock_kit_compositions.query.filter_by(kit_id=kit_id).with_entities( |   composition = Stock_kit_compositions.query.filter_by(kit_id=kit_id).with_entities( | ||||||
|                                                       Stock_kit_compositions.componant_id, |                                                       Stock_kit_compositions.componant_id, | ||||||
|                                                       Stock_kit_compositions.quantity).all() |                                                       Stock_kit_compositions.quantity).all() | ||||||
| @ -756,20 +769,8 @@ def get_kit_composition(kit_id): | |||||||
|            u'needed': c_componant.quantity |            u'needed': c_componant.quantity | ||||||
|            } |            } | ||||||
|       kit_composition.append(c) |       kit_composition.append(c) | ||||||
|       try: |   max_kit = get_max_kit(kit_id) | ||||||
|         mkit = int(componant.quantity) / int(c_componant.quantity) |   return render_template('kit_composition.html', kit_composition=kit_composition, max_kit=max_kit, kit_id=kit_id) | ||||||
|       except ZeroDivisionError as e: |  | ||||||
|         print "[+] Error at get_kit_composition:" |  | ||||||
|         print "------------------------------" |  | ||||||
|         print "%s" % e.message |  | ||||||
|         print "------------------------------"         |  | ||||||
|       if mkit < max_kit: |  | ||||||
|         max_kit = mkit |  | ||||||
|   if max_kit == default_max_kit: |  | ||||||
|     max_kit = 0 |  | ||||||
|   if len(kit_composition) > 0: |  | ||||||
|     return render_template('kit_composition.html', kit_composition=kit_composition, max_kit=max_kit, kit_id=kit_id) |  | ||||||
|   return "Aucun composant" |  | ||||||
| 
 | 
 | ||||||
| @app.route('/kits/remove/<kit_id>/<componant_id>', methods=['GET']) | @app.route('/kits/remove/<kit_id>/<componant_id>', methods=['GET']) | ||||||
| @resume_session | @resume_session | ||||||
| @ -789,20 +790,20 @@ def remove_componant_from_kit(kit_id, componant_id): | |||||||
|     print "------------------------------" |     print "------------------------------" | ||||||
|   return get_kit(kit_id) |   return get_kit(kit_id) | ||||||
| 
 | 
 | ||||||
| @app.route('/kits/add/<kit_id>/<componant_id>', methods=['POST', 'GET']) | @app.route('/kits/composition/add/<kit_id>', methods=['POST', 'GET']) | ||||||
| @resume_session | @resume_session | ||||||
| def add_componant_to_kit(kit_id, componant_id): | def add_componant_to_kit(kit_id): | ||||||
|   """ Add componant to kit """ |   """ Add componant to kit """ | ||||||
|   try: |   try: | ||||||
|     kit_id = int(kit_id) |     kit_id = int(kit_id) | ||||||
|     count = Stock_kit_compositions.query.filter_by(kit_id=kit_id, componant_id=componant_id).count() |     count = Stock_kit_compositions.query.filter_by(kit_id=kit_id, componant_id=session[u'kc_componant_id']).count() | ||||||
|     if count > 0: |     if count > 0: | ||||||
|       # Componant already in kit composition |       # Componant already in kit composition | ||||||
|       # => Updating with new quantity |       # => Updating with new quantity | ||||||
|       return update_kit_composition(kit_id) |       return update_kit_composition(kit_id) | ||||||
| 
 | 
 | ||||||
|     composition = Stock_kit_compositions(kit_id=kit_id,  |     composition = Stock_kit_compositions(kit_id=kit_id,  | ||||||
|                                           componant_id=componant_id, |                                           componant_id=session[u'kc_componant_id'], | ||||||
|                                           quantity=session[u'kc_quantity']) |                                           quantity=session[u'kc_quantity']) | ||||||
|     db.session.add(composition) |     db.session.add(composition) | ||||||
|     commit =  db.session.commit() |     commit =  db.session.commit() | ||||||
|  | |||||||
		불러오는 중...
	
		Reference in New Issue
	
	Block a user