Browse Source

"Beta release"

Doug Le Tough 3 years ago
parent
commit
9a61d14eb4

+ 1
- 0
.gitignore View File

@@ -2,4 +2,5 @@
2 2
 *.swp
3 3
 *.pyc
4 4
 config.tetalab.py
5
+pg_*
5 6
 

+ 135
- 0
data_migration.sh View File

@@ -0,0 +1,135 @@
1
+#!/bin/bash
2
+DB_SRC_HOST=marian.local.tetalab.org
3
+DB_SRC=/var/www/stock.tetalab.org/stock
4
+DB_DST=tetastock
5
+DB_DST_USER=tetastock
6
+DB_DST_HOST=sonny.local.tetalab.org
7
+
8
+PSQL_OPTS="-t -U ${DB_DST_USER} -h ${DB_DST_HOST} -d ${DB_DST}"
9
+
10
+function log {
11
+  echo -e "\033[93m$@\033[0m"
12
+}
13
+
14
+function red {
15
+  echo -e "\033[91m$@\033[0m"
16
+}
17
+
18
+function out {
19
+  echo -e "\033[91m$@\033[0m"
20
+  exit 1
21
+}
22
+
23
+log "[+] Suppression des données existantes"
24
+psql -t ${PSQL_OPTS} -c "delete from stock_kit_compositions where id > 0;"
25
+psql -t ${PSQL_OPTS} -c "delete from stock_componants where id > 0;"
26
+psql -t ${PSQL_OPTS} -c "delete from stock_kits where id > 0;"
27
+
28
+log "[+] Récupération des composants"
29
+
30
+IFS_BAK=${IFS}
31
+IFS=$'\n'
32
+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;'")
33
+do
34
+  IFS=${IFS_BAK}
35
+  COMP_ID=$(echo ${LINE} | awk -F'|' '{print $1}')
36
+  RAND=$(head -n40 /dev/urandom | md5sum | cut -d' ' -f1)
37
+  REF=$(echo ${LINE} | awk -F'|' '{print $2}')
38
+  REF=$(echo "${REF:0:3}-${RAND:0:5}" | tr [a-z] [A-Z] | sed 's/É/E/')
39
+  GROUP=$(echo ${LINE} | awk -F'|' '{print $2}' | sed 's/^ *//;s/ *$//')
40
+  TYPE=$(echo ${LINE} | awk -F'|' '{print $3}' | sed 's/^ *//;s/ *$//')
41
+  SIZE=$(echo ${LINE} | awk -F'|' '{print $4}' | sed 's/^ *//;s/ *$//')
42
+  COLOR=$(echo ${LINE} | awk -F'|' '{print $5}' | sed 's/^ *//;s/ *$//')
43
+  if [ "${COLOR}" == "0" ]; then
44
+    COLOR=''
45
+  fi
46
+  VALUE=$(echo ${LINE} | awk -F'|' '{print $6}' | sed 's/^ *//;s/ *$//')
47
+  QUANTITY=$(echo ${LINE} | awk -F'|' '{print $7}' | sed 's/^ *//;s/ *$//')
48
+  DESIGNATION=$(echo "${GROUP} ${TYPE} ${SIZE} ${COLOR} ${VALUE}" | sed 's/^ *//;s/ *$//;s/  +*/ /g;s/  */ /g')
49
+  if [ ${#QUANTITY} -eq 0 ]; then
50
+    QUANTITY=0
51
+  fi
52
+  PLACE=$(echo ${LINE} | awk -F'|' '{print $8}')
53
+  log "  [+] Vérification de l'existence d'un doublon avec ${DESIGNATION}"
54
+  SQLREQ="select id from stock_componants where designation='${DESIGNATION}';"
55
+  EXIST=$(psql ${PSQL_OPTS} -c "${SQLREQ}")
56
+  if [ ! ${#EXIST} -eq 0 ]; then
57
+    red "    => Composant ${EXIST} a déjà une désignation égale à ${DESIGNATION}"
58
+    continue
59
+  fi
60
+  log "  [+] Enregistrement du nouveau composant: ${REF} / ${DESIGNATION}"
61
+  SQLREQ="insert into stock_componants (reference, designation, place, quantity) values ('${REF}', '${DESIGNATION}', '${PLACE}', ${QUANTITY});"
62
+  psql ${PSQL_OPTS} -c "${SQLREQ}" || out "${SQLREQ}"
63
+  IFS=$'\n'
64
+done
65
+
66
+log "[+] Récupération des ID des kits"
67
+for KIT_ID in $(ssh ${DB_SRC_HOST} sqlite3 ${DB_SRC} "'select distinct id from kit;'")
68
+do
69
+  IFS=${IFS_BAK}
70
+  # On recupere le kit
71
+  log "  [+] Récupération du nom pour KIT_ID: ${KIT_ID}"
72
+  SQLREQ="select description from kit where ID=${KIT_ID};"
73
+  NAME=$(ssh ${DB_SRC_HOST} sqlite3 ${DB_SRC} "'${SQLREQ}'")
74
+  if [ ${#NAME} -lt 1 ]; then
75
+    log "[-] Trace: ${SQLREQ}"
76
+    out "Nom introuvable pour ${KIT_ID}"
77
+  fi
78
+  DESIGNATION=${NAME}
79
+  # On cree le kit
80
+  log "  [+] Enregistrement du kit ${NAME} / ${DESIGNATION}"
81
+  SQLREQ="insert into stock_kits (name, designation) values ('${NAME}', '${DESIGNATION}');"
82
+  psql ${PSQL_OPTS} -c "${SQLREQ}" || out "${SQLREQ}"
83
+  log "  [+] Récupération du nouvel ID du kit"
84
+  # On recupere l'ID du nouveau kit
85
+  SQLREQ="select id from stock_kits where name='${NAME}' and designation='${DESIGNATION}';"
86
+  NKIT_ID=$(psql ${PSQL_OPTS} -c "${SQLREQ}")
87
+  if [ ${#NKIT_ID} -lt 1 ]; then
88
+    log "[-] Trace: ${SQLREQ}"
89
+    out "Pas de NKIT_ID pour ${NAME}"
90
+  fi
91
+  log "    => ${NKIT_ID}"
92
+  # On recupere les composants du kit
93
+  log "  [+] Récupération de la liste des composants du kit"
94
+  SQLREQ="select id_composant, quantite from composants_kit where id_kit='${KIT_ID}';"
95
+  RECS=$(ssh ${DB_SRC_HOST} sqlite3 ${DB_SRC} "'${SQLREQ}'")
96
+  IFS=$'\n'
97
+  for REC in ${RECS}
98
+  do
99
+    IFS=${IFS_BAK}
100
+    COMP_ID=$(echo ${REC} | awk -F'|' '{print $1}')
101
+    QUANTITY=$(echo ${REC} | awk -F'|' '{print $2}')
102
+    IFS=${IFS_BAK}
103
+    log "    [+] Récupération du composant: ${COMP_ID}"
104
+    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;"
105
+    COMP=$(ssh ${DB_SRC_HOST} sqlite3 ${DB_SRC} "'${SQLREQ}'")
106
+    if [ ${#COMP} -lt 1 ]; then
107
+      red "[-] Trace: ${SQLREQ}"
108
+      red "Pas de composant avec ID ${COMP_ID}"
109
+      continue
110
+    fi
111
+    GROUP=$(echo ${COMP} | awk -F'|' '{print $2}' | sed 's/^ *//;s/ *$//')
112
+    TYPE=$(echo ${COMP} | awk -F'|' '{print $3}' | sed 's/^ *//;s/ *$//')
113
+    SIZE=$(echo ${COMP} | awk -F'|' '{print $4}' | sed 's/^ *//;s/ *$//')
114
+    COLOR=$(echo ${COMP} | awk -F'|' '{print $5}' | sed 's/^ *//;s/ *$//')
115
+    if [ "${COLOR}" == "0" ]; then
116
+      COLOR=''
117
+    fi
118
+    VALUE=$(echo ${COMP} | awk -F'|' '{print $6}' | sed 's/^ *//;s/ *$//')
119
+    DESIGNATION=$(echo "${GROUP} ${TYPE} ${SIZE} ${COLOR} ${VALUE}" | sed 's/^ *//;s/ *$//;s/  +*/ /g;s/  */ /g')
120
+    log "    [+] Récupération du nouvel ID du composant"
121
+    SQLREQ="select ID from stock_componants where designation='${DESIGNATION}';"
122
+    NCOMP_ID=$(psql ${PSQL_OPTS}  -c "${SQLREQ}")
123
+    if [ ${#NCOMP_ID} -lt 1 ]; then
124
+      log "[-] Trace: ${SQLREQ}"
125
+      out "Pas de composant avec NCOMP_ID ${NCOMP_ID}"
126
+    fi
127
+    log "      [+] ${NCOMP_ID}"
128
+    log "    [+] Enregistrement du composant ${NCOMP_ID} dans la composition du kit ${NKIT_ID} (q: ${QUANTITY})"
129
+    SQLREQ="insert into stock_kit_compositions (kit_id, componant_id, quantity) values (${NKIT_ID}, ${NCOMP_ID}, ${QUANTITY})"
130
+    psql ${PSQL_OPTS}  -c "${SQLREQ}" || out "${SQLREQ}"
131
+    IFS=$'\n'
132
+  done
133
+  IFS=$'\n'
134
+done
135
+IFS=${IFS_BAK}

+ 2
- 2
static/scripts/tetalab.js View File

@@ -67,6 +67,7 @@ function login() {
67 67
 
68 68
 function logout() {
69 69
   setcookie('token', '', 30);
70
+  setcookie('session', '', 30);
70 71
   document.location='/';
71 72
 }
72 73
 
@@ -140,7 +141,6 @@ function c_next_page(nexthop) {
140 141
   update_componants();
141 142
 }
142 143
 
143
-
144 144
 // Search componants
145 145
 function search_componants_by_reference(obj) {
146 146
   setcookie('c_reference', obj.value, 30);
@@ -651,7 +651,7 @@ function add_kit_componant(kit_id, componant_id) {
651 651
     }
652 652
   };
653 653
   
654
-  xhttp.open('POST', '/kits/add/'+kit_id+'/'+componant_id, true);
654
+  xhttp.open('POST', '/kits/composition/add/'+kit_id, true);
655 655
   xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
656 656
   xhttp.send();
657 657
 }

+ 2
- 2
static/style/style.css View File

@@ -162,7 +162,7 @@ div.error {
162 162
   background-repeat: no-repeat;
163 163
   background-position: center center;
164 164
   background-color: #000000;
165
-  height: 476px;
165
+  height: 531px;
166 166
   padding: 10px;
167 167
   text-align: center;
168 168
   font-size: 70px;
@@ -175,7 +175,7 @@ div.wip {
175 175
   background-repeat: no-repeat;
176 176
   background-position: center center;
177 177
   background-color: #000000;
178
-  height: 476px;
178
+  height: 531px;
179 179
   padding: 10px;
180 180
   text-align: center;
181 181
   font-size: 70px;

+ 2
- 75
stock.sql View File

@@ -34,7 +34,7 @@ CREATE TABLE stock_providers (
34 34
 CREATE TABLE stock_componants (
35 35
   id serial primary key,
36 36
   reference varchar(20) unique not NULL,
37
-  designation varchar(50) not NULL,
37
+  designation varchar(100) not NULL,
38 38
   last_price NUMERIC not NULL default 0,
39 39
   mean_price NUMERIC not NULL default 0,
40 40
   quantity NUMERIC not NULL default 0,
@@ -70,77 +70,4 @@ insert into stock_users (mail, password, name) values
70 70
 ('doug.letough@free.fr', '$2a$08$578910202124252729313uTyggq4ANEjMljcClFriOqcsttB2fnAW', 'Doug Le Tough');
71 71
 insert into stock_users (mail, password, name) values
72 72
 ('doug@redatomik.org', '$2a$08$578910202124252729313uTyggq4ANEjMljcClFriOqcsttB2fnAW', 'Doug Le Tough');
73
-
74
-insert into stock_providers (name, address, mail, url, comment)
75
-  values ('Tous', 'N/A', 'N/A', 'N/A', 'N/A');
76
-insert into stock_providers (name, address, mail, url, comment)
77
-  values ('Aucun', 'N/A', 'N/A', 'N/A', 'N/A');
78
-insert into stock_providers (name, address, mail, url, comment)
79
-  values ('China Elec Co', 'Beijing', 'sales@chinaelecco.cc', 'https://chinaelecco.cc', 'Pas cher mais délai excessif et composants pourris');
80
-
81
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
82
-  values ('Res-01', 'Resistance 10KΩ', 13.34, 12.42, 73, 0, 'B 43', 3);
83
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
84
-  values ('Lor-01', '1 Lorem ipsum dolor sit ametconsectetur adipiscing', 13.34, 12.42, 73, 0, 'B 43', 3);
85
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
86
-  values ('Res-02', 'Resistance 11KΩ', 13.34, 12.42, 73, 0, 'B 43', 3);
87
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
88
-  values ('Res-03', 'Resistance 12KΩ', 13.34, 12.42, 73, 0, 'B 43', 3);
89
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
90
-  values ('Res-04', 'Resistance 13KΩ', 13.34, 12.42, 73, 0, 'B 43', 2);
91
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
92
-  values ('Res-05', 'Resistance 14KΩ', 13.34, 12.42, 73, 0, 'B 43', 3);
93
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
94
-  values ('Lor-02', '2 Lorem ipsum dolor sit ametconsectetur adipiscing', 13.34, 12.42, 73, 0, 'B 43', 3);
95
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
96
-  values ('Res-06', 'Resistance 15KΩ', 13.34, 12.42, 73, 0, 'B 43', 3);
97
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
98
-  values ('Res-07', 'Resistance 16KΩ', 13.34, 12.42, 73, 0, 'B 43', 3);
99
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
100
-  values ('Res-08', 'Resistance 17KΩ', 13.34, 12.42, 73, 0, 'B 43', 3);
101
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
102
-  values ('Res-09', 'Resistance 18KΩ', 13.34, 12.42, 73, 0, 'B 43', 3);
103
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
104
-  values ('Lor-03', '3 Lorem ipsum dolor sit ametconsectetur adipiscing', 13.34, 12.42, 73, 0, 'B 43', 3);
105
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
106
-  values ('Res-10', 'Resistance 19KΩ', 13.34, 12.42, 73, 0, 'B 43', 2);
107
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
108
-  values ('Res-11', 'Resistance 20KΩ', 13.34, 12.42, 73, 0, 'B 43', 3);
109
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
110
-  values ('Res-12', 'Resistance 21KΩ', 13.34, 12.42, 73, 0, 'B 43', 3);
111
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
112
-  values ('Res-13', 'Resistance 22KΩ', 13.34, 12.42, 73, 0, 'B 43', 3);
113
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
114
-  values ('Lor-04', '4 Lorem ipsum dolor sit ametconsectetur adipiscing', 13.34, 12.42, 73, 0, 'B 43', 3);
115
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
116
-  values ('Res-14', 'Resistance 23KΩ', 13.34, 12.42, 73, 0, 'B 43', 3);
117
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
118
-  values ('Res-15', 'Resistance 24KΩ', 13.34, 12.42, 73, 0, 'B 43', 3);
119
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
120
-  values ('Res-16', 'Resistance 25KΩ', 13.34, 12.42, 73, 0, 'B 43', 3);
121
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
122
-  values ('Res-17', 'Resistance 26KΩ', 13.34, 12.42, 73, 0, 'B 43', 2);
123
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
124
-  values ('Lor-05', '5 Lorem ipsum dolor sit ametconsectetur adipiscing', 13.34, 12.42, 73, 0, 'B 43', 3);
125
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
126
-  values ('Res-18', 'Resistance 27KΩ', 13.34, 12.42, 73, 0, 'B 43', 3);
127
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
128
-  values ('Res-19', 'Resistance 28KΩ', 13.34, 12.42, 73, 0, 'B 43', 3);
129
-insert into stock_componants (reference, designation, last_price, mean_price, quantity, min_quantity, place, provider_id)
130
-  values ('Res-20', 'Resistance 29KΩ', 13.34, 12.42, 73, 0, 'B 43', 3);
131
-
132
-insert into stock_kits (name, designation) values ('Kit_test', 'Kit de test');
133
-insert into stock_kits (name, designation) values ('Kit2_test2', 'Kit de test 2');
134
-insert into stock_kits (name, designation) values ('MF_K', 'Mother fucking kit');
135
-
136
-insert into stock_kit_compositions (kit_id, componant_id, quantity) values (1, 5, 1);
137
-insert into stock_kit_compositions (kit_id, componant_id, quantity) values (1, 8, 2);
138
-insert into stock_kit_compositions (kit_id, componant_id, quantity) values (1, 10, 2);
139
-insert into stock_kit_compositions (kit_id, componant_id, quantity) values (1, 12, 7);
140
-
141
-insert into stock_kit_compositions (kit_id, componant_id, quantity) values (2, 5, 2);
142
-insert into stock_kit_compositions (kit_id, componant_id, quantity) values (2, 4, 1);
143
-insert into stock_kit_compositions (kit_id, componant_id, quantity) values (2, 9, 3);
144
-insert into stock_kit_compositions (kit_id, componant_id, quantity) values (2, 22, 2);
145
-insert into stock_kit_compositions (kit_id, componant_id, quantity) values (2, 1, 5);
146
-insert into stock_kit_compositions (kit_id, componant_id, quantity) values (2, 14, 8);
73
+insert into stock_users (mail, password, name) values ('test', '$2b$08$OkfihuGRyLdpftBpGhnpeeeUhUTQS0oXvR2NFByC.65XCKKvPBWHS');

+ 3
- 3
templates/componant.html View File

@@ -54,9 +54,9 @@
54 54
                       id='designation'
55 55
                       type='text'
56 56
                       onchange='javascript:update_componant(this, {{ componant.id }}, "text");'
57
-                      maxlength='50'
58
-                      title='Désignation (max. 50)'
59
-                      placeholder='Désignation (max. 50)'
57
+                      maxlength='100'
58
+                      title='Désignation (max. 100)'
59
+                      placeholder='Désignation (max. 100)'
60 60
                       value='{{ componant.designation }}' />
61 61
               </div>
62 62
               <div class='input_block'>

+ 1
- 1
templates/kit.html View File

@@ -4,7 +4,7 @@
4 4
 {% endblock %}
5 5
 {% block title %}Éditer un kit{% endblock %}
6 6
         {% block top_menu %}
7
-        <span class='top_menu_item' onclick='javascript:document.location="/providers";'>Gérer les kits</span>
7
+        <span class='top_menu_item' onclick='javascript:document.location="/kits";'>Gérer les kits</span>
8 8
         <span class='top_menu_item_selected' onclick='javascript:document.location="/kits/{{ kit.id }}";'>Éditer un kit</span>
9 9
         {% endblock %}
10 10
           {% block left_menu %}

+ 4
- 4
templates/result_componants.html View File

@@ -16,10 +16,10 @@
16 16
               {% set row_class = cycler('odd', 'even') %}
17 17
               {% for componant in componants %}
18 18
               <div class='row_block {{ row_class.next() }}'>
19
-                <text style='width: 190px;'>{{ componant.reference }}</text>
20
-                <text class='border_left' style='width: 439px;'>{{ componant.designation }}</text>
21
-                <text class='num border_left' style='width: 89px;'>{{ componant.quantity }}</text>
22
-                <text class='num border_right border_left' style='width: 139px;'>{{ componant.place }}</text>
19
+                <text style='width: 190px;' title='{{ componant.reference }}'>{{ componant.reference }}</text>
20
+                <text class='border_left' style='width: 439px;' title='{{ componant.designation }}'>{{ componant.designation }}</text>
21
+                <text class='num border_left' style='width: 89px;' title='{{ componant.quantity }}'>{{ componant.quantity }}</text>
22
+                <text class='num border_right border_left' style='width: 139px;' title='{{ componant.place }}'>{{ componant.place }}</text>
23 23
                 <div class='action_bar_block border_left' style='width: 89px;'>
24 24
                   <input
25 25
                     type='image'

+ 3
- 3
templates/result_kit_componants.html View File

@@ -10,10 +10,10 @@
10 10
               {% set row_class = cycler('odd', 'even') %}
11 11
               {% for componant in componants %}
12 12
               <div class='row_block {{ row_class.next() }}'>
13
-                <text style='width: 190px;'>{{ componant.reference }}</text>
14
-                <text class='border_left' style='width: 439px;'>{{ componant.designation }}</text>
13
+                <text style='width: 190px;' title='{{ componant.reference }}'>{{ componant.reference }}</text>
14
+                <text class='border_left' style='width: 439px;' title='{{ componant.designation }}'>{{ componant.designation }}</text>
15 15
                 <text class='num border_left' style='width: 89px;'>{{ componant.quantity }}</text>
16
-                <text class='num border_right border_left' style='width: 139px;'>{{ componant.place }}</text>
16
+                <text class='num border_right border_left' style='width: 139px;' title='{{ componant.place }}'>{{ componant.place }}</text>
17 17
                 <div class='action_bar_block border_left' style='width: 89px;'>
18 18
                   <input
19 19
                     type='image'

+ 9
- 3
templates/result_kits.html View File

@@ -8,14 +8,20 @@
8 8
               </text>
9 9
               <div class='row_block border_bottom'>
10 10
                 <label style='width: 209px;' onclick='javascript:update_kits_by_name("{{ order }}");'>Nom</label>
11
-                <label class='border_left' style='width: 700px;' onclick='javascript:update_kits_by_designation("{{ order }}");'>Désignation</label>
11
+                <label class='border_left' style='width: 600px;' onclick='javascript:update_kits_by_designation("{{ order }}");'>Désignation</label>
12
+                <label class='border_left' style='width: 99px;' style='cursor: default;'>Max dispo</label>
12 13
                 <label class='border_left' style='width: 89px;' style='cursor: default;'>Action</label>
13 14
               </div>
14 15
               {% set row_class = cycler('odd', 'even') %}
15 16
               {% for kit in kits %}
16 17
               <div class='row_block {{ row_class.next() }}'>
17
-                <text style='width: 199px;'>{{ kit.name }}</text>
18
-                <text class='border_left' style='width: 690px;'>{{ kit.designation }}</text>
18
+                <text style='width: 199px;' title='{{ kit.name }}'>{{ kit.name }}</text>
19
+                <text class='border_left' style='width: 590px;' title='{{ kit.designation }}'>{{ kit.designation }}</text>
20
+                {% set sclass='red' %}
21
+                {% if kit. max_kit > 1 %}
22
+                {%    set sclass='' %}
23
+                {% endif %}
24
+                <text class='border_left num {{ sclass }}' style='width: 89px;' title='{{ kit.max_kit }}'>{{ kit.max_kit }}</text>
19 25
                 <div class='action_bar_block border_left' style='width: 89px;'>
20 26
                   <input
21 27
                     type='image'

+ 3
- 3
templates/result_providers.html View File

@@ -17,9 +17,9 @@
17 17
               {% for provider in providers %}
18 18
               <div class='row_block {{ row_class.next() }}'>
19 19
                 <text style='width: 199px;'>{{ provider.name }}</text>
20
-                <text class='border_left' style='width: 189px;'>{{ provider.address }}</text>
21
-                <text class='border_left' style='width: 189px;'>{{ provider.mail }}</text>
22
-                <text class='border_left' style='width: 289px;'>{{ provider.url }}</text>
20
+                <text class='border_left' style='width: 189px;' title='{{ provider.address }}'>{{ provider.address }}</text>
21
+                <text class='border_left' style='width: 189px;' title='{{ provider.mail }}'>{{ provider.mail }}</text>
22
+                <text class='border_left' style='width: 289px;' title='{{ provider.url }}'>{{ provider.url }}</text>
23 23
                 <div class='action_bar_block border_left' style='width: 89px;'>
24 24
                   <input
25 25
                     type='image'

+ 3
- 3
templates/wip.html View File

@@ -1,7 +1,7 @@
1 1
 <!DOCTYPE html>                                                                                                                                                           
2 2
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr" dir="ltr">
3 3
   <head>
4
-    <title>Référentiel Infrastructure Tetalab - {% block title %}How The Fuck{% endblock %}</title>
4
+    <title>Tetastock</title>
5 5
     <meta name="viewport" content="initial-scale=1.0">
6 6
     <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
7 7
     <link rel="stylesheet" type="text/css" href="/static/style/style.css" />
@@ -10,8 +10,8 @@
10 10
   <body>
11 11
     <div class='main_wrapper'>
12 12
       <div class='center'>
13
-        <div class='banner' title='Référentiel infrastrusture Tetalab'>
14
-          Référentiel Infrastructure Tetalab
13
+        <div class='banner' title='Tetastock'>
14
+          Tetastock
15 15
         </div>
16 16
         <div class='top_menu'>
17 17
           <span class='top_menu_item' onclick='javascript:document.location="/";'>Retour</span>

+ 38
- 37
tetastock.py View File

@@ -77,6 +77,28 @@ class Stock_orders(db.Model):
77 77
 ########################################################################
78 78
 # Here comes the fun
79 79
 ########################################################################
80
+def get_max_kit(kit_id):
81
+  """ Get max available kit from kit.id """
82
+  default_max_kit = float("inf")
83
+  max_kit = default_max_kit
84
+  composition = Stock_kit_compositions.query.filter_by(kit_id=kit_id).with_entities(
85
+                                                      Stock_kit_compositions.componant_id,
86
+                                                      Stock_kit_compositions.quantity).all()
87
+  for c_componant in composition:
88
+    componant = Stock_componants.query.filter_by(id=c_componant.componant_id).first()
89
+    if componant:
90
+      try:
91
+        mkit = int(componant.quantity) / int(c_componant.quantity)
92
+      except ZeroDivisionError as e:
93
+        print "[+] Error at get_max_kit:"
94
+        print "------------------------------"
95
+        print "%s" % e.message
96
+        print "------------------------------"        
97
+      if mkit < max_kit:
98
+        max_kit = mkit
99
+  if max_kit == default_max_kit:
100
+    max_kit = 0
101
+  return max_kit
80 102
 
81 103
 def sync_cookies(response, session):
82 104
   """ Sync cookies with session """
@@ -85,7 +107,7 @@ def sync_cookies(response, session):
85 107
     if key != u'session':
86 108
       print '[c]', key, session[key]
87 109
 
88
-def sync_session(request, session, offset_reset):
110
+def sync_session(request, session):
89 111
   """ Sync session with cookies"""
90 112
   for key in request.cookies:
91 113
     try:
@@ -101,10 +123,6 @@ def sync_session(request, session, offset_reset):
101 123
       except ValueError:
102 124
         # Value is not an int, will be treated as string
103 125
         session[key] = str(request.cookies[key].encode('utf8'))
104
-    if key in offset_reset and len(str(session[key])) > 0 and old != str(session[key]):
105
-      session['c_offset'] = 0
106
-      session['p_offset'] = 0
107
-      session['k_offset'] = 0
108 126
     if key != u'session':
109 127
       print '[s]', key, request.cookies[key]
110 128
 
@@ -132,7 +150,6 @@ def check_user(request, session):
132 150
         return True
133 151
     # Password mismatch
134 152
     return False
135
-  
136 153
 
137 154
 def resume_session(func):
138 155
   """ Resume pending session """
@@ -156,9 +173,6 @@ def resume_session(func):
156 173
     k_count = 0
157 174
     kc_quantity = 0
158 175
     kc_limit = 3
159
-    offset_reset = [u'c_reference', u'c_designation', u'c_place',
160
-                    u'c_provider', u'p_name', u'p_address', u'p_mail', u'p_url',
161
-                    u'k_name', u'k_designation']
162 176
     if not u'token' in session:
163 177
       session[u'token'] = empty
164 178
     if not u'password' in session:
@@ -260,8 +274,7 @@ def resume_session(func):
260 274
     if not u'kc_reference' in session:
261 275
       session[u'kc_reference'] = empty
262 276
     # Cookies/session sync
263
-    sync_session(request, session, offset_reset)
264
-
277
+    sync_session(request, session)
265 278
     # Switch sort order
266 279
     refresh = {u'desc': u'asc', u'asc': u'desc'}
267 280
     if session[u'c_order_refresh'] == 1:
@@ -273,7 +286,6 @@ def resume_session(func):
273 286
     if session[u'k_order_refresh'] == 1:
274 287
       session[u'k_order'] = refresh[session[u'k_order']]
275 288
       session[u'k_order_refresh'] = 0
276
-
277 289
     # Check for valid session
278 290
     if not check_user(request, session):
279 291
       # User is not logged in, send him back to login page
@@ -315,7 +327,7 @@ def componants():
315 327
                             place=session[u'c_place'].decode('utf8'),
316 328
                             provider_id=session[u'c_provider'])
317 329
 
318
-@app.route('/componants/<componant_id>')
330
+@app.route('/componants/<componant_id>', methods=['GET', 'POST'])
319 331
 @resume_session
320 332
 def get_componant(componant_id):
321 333
   """ Edit componant """
@@ -348,7 +360,7 @@ def update_componant(componant_id):
348 360
       pass
349 361
   return 'KO'
350 362
 
351
-@app.route('/componants/delete/<componant_id>')
363
+@app.route('/componants/delete/<componant_id>', methods=['GET', 'POST'])
352 364
 @resume_session
353 365
 def delete_componant(componant_id):
354 366
   """ Delete componant """
@@ -392,20 +404,20 @@ def new_componant():
392 404
     return 'KO'
393 405
   return 'OK'
394 406
 
395
-@app.route('/componants/in/<componant_id>')
407
+@app.route('/componants/in')
396 408
 @resume_session
397 409
 def in_componants():
398 410
   """ Incoming order """
399 411
   return render_template('wip.html')
400 412
 
401
-@app.route('/componants/out/<componant_id>')
413
+@app.route('/componants/out')
402 414
 @resume_session
403 415
 def out_componants():
404 416
   """ Outgoing order """
405 417
   return render_template('wip.html')
406 418
 
407 419
 ## Componants update result set
408
-@app.route('/componants/update', methods=['POST'])
420
+@app.route('/componants/update', methods=['GET', 'POST'])
409 421
 @resume_session
410 422
 def update_componants():
411 423
   """ Display componants list """
@@ -719,6 +731,9 @@ def search_kits():
719 731
   kits = kits.limit(session[u'k_limit'])
720 732
   # Get result
721 733
   kits = kits.all()
734
+  for kit in kits:
735
+    max_kit = get_max_kit(kit.id)
736
+    setattr(kit, 'max_kit', max_kit)
722 737
   response = app.make_response(render_template('result_kits.html',
723 738
                             kits=kits,
724 739
                             offset=session[u'k_offset'] ,
@@ -738,9 +753,7 @@ def search_kits():
738 753
 @app.route('/kits/composition/<kit_id>', methods=['POST'])
739 754
 @resume_session
740 755
 def get_kit_composition(kit_id):
741
-  default_max_kit = 999999999999999
742 756
   kit_composition = []
743
-  max_kit = default_max_kit
744 757
   composition = Stock_kit_compositions.query.filter_by(kit_id=kit_id).with_entities(
745 758
                                                       Stock_kit_compositions.componant_id,
746 759
                                                       Stock_kit_compositions.quantity).all()
@@ -756,20 +769,8 @@ def get_kit_composition(kit_id):
756 769
            u'needed': c_componant.quantity
757 770
            }
758 771
       kit_composition.append(c)
759
-      try:
760
-        mkit = int(componant.quantity) / int(c_componant.quantity)
761
-      except ZeroDivisionError as e:
762
-        print "[+] Error at get_kit_composition:"
763
-        print "------------------------------"
764
-        print "%s" % e.message
765
-        print "------------------------------"        
766
-      if mkit < max_kit:
767
-        max_kit = mkit
768
-  if max_kit == default_max_kit:
769
-    max_kit = 0
770
-  if len(kit_composition) > 0:
771
-    return render_template('kit_composition.html', kit_composition=kit_composition, max_kit=max_kit, kit_id=kit_id)
772
-  return "Aucun composant"
772
+  max_kit = get_max_kit(kit_id)
773
+  return render_template('kit_composition.html', kit_composition=kit_composition, max_kit=max_kit, kit_id=kit_id)
773 774
 
774 775
 @app.route('/kits/remove/<kit_id>/<componant_id>', methods=['GET'])
775 776
 @resume_session
@@ -789,20 +790,20 @@ def remove_componant_from_kit(kit_id, componant_id):
789 790
     print "------------------------------"
790 791
   return get_kit(kit_id)
791 792
 
792
-@app.route('/kits/add/<kit_id>/<componant_id>', methods=['POST', 'GET'])
793
+@app.route('/kits/composition/add/<kit_id>', methods=['POST', 'GET'])
793 794
 @resume_session
794
-def add_componant_to_kit(kit_id, componant_id):
795
+def add_componant_to_kit(kit_id):
795 796
   """ Add componant to kit """
796 797
   try:
797 798
     kit_id = int(kit_id)
798
-    count = Stock_kit_compositions.query.filter_by(kit_id=kit_id, componant_id=componant_id).count()
799
+    count = Stock_kit_compositions.query.filter_by(kit_id=kit_id, componant_id=session[u'kc_componant_id']).count()
799 800
     if count > 0:
800 801
       # Componant already in kit composition
801 802
       # => Updating with new quantity
802 803
       return update_kit_composition(kit_id)
803 804
 
804 805
     composition = Stock_kit_compositions(kit_id=kit_id, 
805
-                                          componant_id=componant_id,
806
+                                          componant_id=session[u'kc_componant_id'],
806 807
                                           quantity=session[u'kc_quantity'])
807 808
     db.session.add(composition)
808 809
     commit =  db.session.commit()

Loading…
Cancel
Save