"Added: Add componant feature"

This commit is contained in:
Doug Le Tough 2017-10-24 21:42:57 +02:00
parent 6cf5daf2a1
commit 1e1ead5888
9 changed files with 313 additions and 117 deletions

BIN
static/images/save.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 357 B

View File

@ -15,6 +15,33 @@ function setcookie(cname, cvalue, exdays) {
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getcookie(cname) {
var value = "; " + document.cookie;
var parts = value.split("; " + cname + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
///////////////////////////////////////////
// Eye candies
///////////////////////////////////////////
function invalid_input(obj) {
obj.style.backgroundColor = light_red;
setTimeout( function() {
obj.style.backgroundColor = base_bg;
}
, 2000);
}
function valid_input(obj) {
obj.style.backgroundColor = light_green;
obj.style.borderColor = base_border;
setTimeout( function() {
obj.style.backgroundColor = base_bg;
}
, 2000);
}
///////////////////////////////////////////
// Update result
///////////////////////////////////////////
@ -26,18 +53,16 @@ function update_componants() {
};
xhttp.onload = function(){
if (xhttp.status == 200) {
var response = xhttp.responseText;
obj.innerHTML = response;
return;
if (xhttp.status != 200) {
obj.innerHTML = "Erreur lors de la mise à jour de la liste (2)"
}
obj.innerHTML = "Erreur lors de la mise à jour de la liste (2)"
};
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
var response = xhttp.responseText;
obj.innerHTML = response;
return true;
}
};
xhttp.open('POST', '/componants/update', true);
@ -117,51 +142,86 @@ function confirm_delete() {
return confirm(msg)
}
///////////////////////////////////////////
// New componant
///////////////////////////////////////////
function new_componant() {
var err = false;
var obj = {};
if (getcookie('c_count') > 0){
var errr = true;
obj[0] = document.getElementById('reference');
}
if (getcookie('c_designation').length < 1){
var err = true;
obj[1] = document.getElementById('designation');
}
if (getcookie('c_place').length < 1){
var err = true;
obj[2] = document.getElementById('place');
}
if (err == true) {
for (i in obj){
invalid_input(obj[i]);
}
return;
}
create_componant();
update_componants();
}
function create_componant() {
var MSG='Erreur lors de la creation de la référence.';
var xhttp = new XMLHttpRequest();
xhttp.onerror = function(){
alert(MSG);
return false;
};
xhttp.onload = function(){
if (xhttp.readyState == 4 && xhttp.status == 200) {
var response = xhttp.responseText;
if (response == 'OK'){
return true;
}
alert(MSG);
return false;
}
};
xhttp.open('POST', '/componants/new', true);
xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhttp.send();
}
///////////////////////////////////////////
// Update componant
///////////////////////////////////////////
function update_componant(obj, componant_id, type) {
if (type == 'numeric') {
if (isNaN(obj.value)) {
alert('Valeur numérique uniquement');
alert('Valeur numérique uniquement: '+obj.value);
return;
}
}
var xhttp = new XMLHttpRequest();
xhttp.onerror = function(){
obj.style.backgroundColor = light_red;
setTimeout( function() {
obj.style.backgroundColor = base_bg;
}
, 2000);
invalid_input(obj);
};
xhttp.onload = function(){
var bg_color = light_red;
var border_color = red;
if (xhttp.status == 200) {
if (xhttp.readyState == 4 && xhttp.status == 200) {
var response = xhttp.responseText;
if (response == 'OK'){
bg_color = light_green;
border_color = base_border;
}
}
obj.style.backgroundColor = bg_color;
obj.style.borderColor = border_color;
setTimeout( function() {
obj.style.backgroundColor = base_bg;
valid_input(obj);
return;
}
, 2000);
obj.style.borderColor = red;
invalid_input(obj);
}
};
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
var reponse = xhttp.responseText;
if (xhttp.responseText != 'OK')
obj.style.backgroundColor = light_red;
}
};
xhttp.open('POST', '/componants/update/'+componant_id, true);
xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhttp.send('field='+obj.id+'&value='+obj.value);

View File

@ -139,16 +139,9 @@ div.content {
text-align: justify;
}
div.git_desc, pre {
border-style: solid;
border-color: #FF5D00;
border-width: 1px;
background-color: #FFFFFF;
padding: 5px;
}
div.git_desc {
text-align: justify;
div.note {
font-size: 12px;
line-height: 12px;
}
div.error {
@ -206,13 +199,17 @@ div.result_container {
border-right-style: solid;
}
div.block {
div.block, div.noborder {
overflow: hidden;
border-top-style: solid;
border-top-width: 1px;
height: 20px;
}
div.noborder {
border-style: none;
}
div.inner{
overflow: hidden;
float: center;
@ -260,10 +257,19 @@ div.block text.refresh {
div.block text.search {
background: url(../images/search.png);
margin-left: 275px;
margin-left: 255px;
}
div.inner text.edit:hover, div.inner text.trash:hover, div.block text.refresh:hover, div.block text.search:hover{
div.block text.save {
background: url(../images/save.png);
margin-left: 32px;
}
div.inner text.edit:hover,
div.inner text.trash:hover,
div.block text.refresh:hover,
div.block text.search:hover,
div.block text.save:hover{
background-color: #FFB387;
cursor: pointer;
}
@ -277,7 +283,11 @@ div.inner text.edit {
background-repeat: no-repeat;
}
div.inner text.trash, div.inner text.edit, div.block text.refresh, div.block text.search {
div.inner text.trash,
div.inner text.edit,
div.block text.refresh,
div.block text.search,
div.block text.save {
width: 8px;
float:left;
height: 16px;
@ -286,11 +296,11 @@ div.inner text.trash, div.inner text.edit, div.block text.refresh, div.block tex
}
div.even {
background-color: #FFFFFF;
background-color: #E5E5E5;
}
div.odd {
background-color: #E5E5E5;
background-color: #FFFFFF;
}
div.block label {

View File

@ -1,3 +1,5 @@
\c postgres;
drop database tetalab_stock;
create database tetalab_stock;
@ -29,10 +31,10 @@ CREATE TABLE stock_componants (
id serial primary key,
reference varchar(20) unique not NULL,
designation varchar(50) not NULL,
last_price NUMERIC not NULL,
mean_price NUMERIC not NULL,
quantity NUMERIC not NULL,
min_quantity NUMERIC not NULL,
last_price NUMERIC not NULL default 0,
mean_price NUMERIC not NULL default 0,
quantity NUMERIC not NULL default 0,
min_quantity NUMERIC not NULL default 0,
place varchar(15) not NULL,
provider_id integer REFERENCES stock_providers(id)
);
@ -51,59 +53,60 @@ alter table stock_componants owner to tetalab_user;
alter table stock_kit_compositions owner to tetalab_user;
alter database tetalab_stock owner to tetalab_user;
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', 'Pas cher, mais...');
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', 1);
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', 1);
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', 1);
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', 1);
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', 1);
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', 1);
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', 1);
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', 1);
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', 1);
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', 1);
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', 1);
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', 1);
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', 1);
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', 1);
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', 1);
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', 1);
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', 1);
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', 1);
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', 1);
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', 1);
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', 1);
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', 1);
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', 1);
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', 1);
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', 1);
\c postgres;
values ('Res-20', 'Resistance 29KΩ', 13.34, 12.42, 73, 0, 'B 43', 3);

View File

@ -25,12 +25,14 @@
{% block content %}
<h3>Note:</h3>
<p>Cette page vous permet de modifier directement un composant.</p>
<p>À moins de vouloir corriger une erreur de saisie, ou de saisir un inventaire vous ne devez
<strong>PAS</strong> modifier directement
les quantités d'un composant.</p>
<p>Cliquez sur les liens suivants pour saisir des <a href='/componant/in/{{ componant.id }}'>entrées</a>
ou <a href='/componant/out/{{ componant.id }}'>sorties</a> de stock.</p>
<div class='note'>
<p>Cette page vous permet de modifier directement un composant.</p>
<p>À moins de vouloir corriger une erreur de saisie, ou de saisir un inventaire vous ne devez
<strong>PAS</strong> modifier directement
les quantités d'un composant.</p>
<p>Cliquez sur les liens suivants pour saisir des <a href='/componant/in/{{ componant.id }}'>entrées</a>
ou <a href='/componant/out/{{ componant.id }}'>sorties</a> de stock.</p>
</div>
<h3>Composant:</h3>
<div class='block margin_bottom no_border'>
<label class='editable'>Référence (unique)</label>
@ -125,7 +127,7 @@
{% if prov.id == provider.id %}
{% set option_selected = 'selected="selected"' %}
{% endif %}
<option {{ option_selected }} value='prov.id'>{{ prov.name }}</option>
<option {{ option_selected }} value='{{ prov.id }}'>{{ prov.name }}</option>
{% endfor %}
</select>
</div>

View File

@ -1,4 +1,7 @@
{% extends "index.html" %}
{% block bodyheader %}
<body onload="javascript:update_componants();">
{% endblock %}
{% block title %}Liste des composants{% endblock %}
{% block top_menu %}
<span class='top_menu_item_selected' onclick='javascript:document.location="/componants/search";'>Rechercher un composant</span>
@ -69,7 +72,6 @@
id='provider_id'
onchange='javascript:search_componants_by_provider(this, "numeric");'
title='Fournisseur'>
<option value='0' selected>Tous</option>
{% for prov in providers %}
{% set selected = '' %}
{% if prov.id == provider_id %}
@ -81,6 +83,7 @@
</div>
<div class='block margin_bottom no_border center'>
<text title='Rechercher' class='search' onclick='javascript:update_componants("reference");'></text>
<text title='Enregistrer' class='save' onclick='javascript:new_componant();'></text>
</div>
<!-- ----------------------------------------------------
Resultat

View File

@ -7,7 +7,9 @@
<link rel="stylesheet" type="text/css" href="/static/style/style.css" />
<script type="text/javascript" src="/static/scripts/tetalab.js"></script>
</head>
{% block bodyheader %}
<body>
{% endblock %}
<div class='main_wrapper'>
<div class='center'>
<div class='banner' title='Stock Tetalab'>
@ -34,15 +36,17 @@
</div>
<div class='content'>
{% block content %}
<h1>Gestion du stock</h1>
<p>Ceci est l'outil de gestion de stock du <a href='https://www.tetalab.org'>Tetalab</a>.</p>
<p>Cet outil vous permet:
<ul>
<li>De gérer la liste des composants électroniques en possession du Tetalab</li>
<li>De gérer la liste des fournisseurs de composants</li>
<li>De gérer la liste des kits de montage</li>
</ul>
</p>
<h1>Tetastock</h1>
<div class='note'>
<p>Ceci est l'outil de gestion de stock du <a href='https://www.tetalab.org'>Tetalab</a>.</p>
<p>Cet outil vous permet:
<ul>
<li>De gérer la liste des composants électroniques en possession du Tetalab</li>
<li>De gérer la liste des fournisseurs de composants</li>
<li>De gérer la liste des kits de montage</li>
</ul>
</p>
</div>
{% endblock %}
</div>
</div>

View File

@ -0,0 +1,87 @@
{% extends "index.html" %}
{% block bodyheader %}
<body onload="javascript:update_componants();">
{% endblock %}
{% block title %}Nouveau composant{% endblock %}
{% block top_menu %}
<span class='top_menu_item' onclick='javascript:document.location="/componants";'>Rechercher un composant</span>
<span class='top_menu_item_selected' onclick='javascript:document.location="/componants/new";'>Nouveau composant</span>
<span class='top_menu_item' onclick='javascript:document.location="/componants/in";'>Entrée de stock</span>
<span class='top_menu_item' onclick='javascript:document.location="/componants/out";'>Sortie de stock</span>
{% endblock %}
{% block left_menu %}
<div class='left_menu_item' onclick='javascript:document.location="/";'>
Accueil
</div>
<div class='left_menu_item_selected' onclick='javascript:document.location="/componants";'>
Composants
</div>
<div class='left_menu_item' onclick='javascript:document.location="/kits";'>
Kits
</div>
<div class='left_menu_item' onclick='javascript:document.location="/providers";'>
Fournisseurs
</div>
{% endblock %}
{% block content %}
<!-- ----------------------------------------------------
Recherche
----------------------------------------------------- -->
<h3>Recherche:</h3>
<div class='block margin_bottom no_border'>
<label class='editable'>Référence (unique)</label>
<input
id='reference'
type='text'
class='editable'
onkeyup='javascript:search_reference(this);'
maxlength='20'
title='Référence interne unique (max. 20)'
placeholder='Référence interne unique (max. 20)'
value='' />
</div>
<div class='block margin_bottom no_border'>
<label class='editable'>Désignation</label>
<input
id='designation'
type='text'
class='editable'
maxlength='50'
title='Désignation (max. 50)'
placeholder='Désignation (max. 50)'
value='' />
</div>
<div class='block margin_bottom no_border'>
<label class='editable'>Emplacement</label>
<input
id='place'
type='text'
class='editable'
maxlength='15'
title='Emplacement (max. 15)'
placeholder='Emplacement (max. 15)'
value='' />
</div>
<div class='block margin_bottom no_border'>
<label class='editable'>Fournisseur</label>
<select
id='provider_id'
title='Fournisseur'>
<option value='0' selected>Tous</option>
{% for prov in providers %}
<option value='{{ prov.id }}'>{{ prov.name }}</option>
{% endfor %}
</select>
</div>
<div class='block margin_bottom no_border center'>
<text title='Enregistrer' class='save' onclick='javascript:new_componant();'></text>
</div>
<!-- ----------------------------------------------------
Resultat
----------------------------------------------------- -->
<div id='result_container' class='result_container'>
</div>
{% endblock %}

View File

@ -2,10 +2,12 @@
# -*- coding: utf-8
import math
import psycopg2
from flask import Flask, request, session, g, redirect, url_for, abort, render_template, flash
from flask_sqlalchemy import SQLAlchemy
from functools import wraps
########################################################################
# App settings
########################################################################
@ -66,8 +68,11 @@ def resume_session(func):
order = 'asc'
order_refresh = 0
c_empty = ''
c_provider = 1
c_provider = 0
c_count = 0
offset_reset = ['c_reference', 'c_designation', 'c_place', 'c_provider']
if not 'session' in session:
session['session'] = ''
if not 'c_limit' in session:
session['c_limit'] = limit
if not 'c_offest' in session:
@ -90,6 +95,8 @@ def resume_session(func):
session['c_place'] = c_empty
if not 'c_provider' in session:
session['c_provider'] = c_provider
if not 'c_count' in session:
session['c_count'] = c_count
# Cookies/session sync
for key in request.cookies:
old = str(session[key])
@ -129,11 +136,11 @@ def authenticate():
# Componants
########################################################################
## Main ##
@app.route('/componants', methods=['GET', 'POST'])
@resume_session
def get_componants():
providers = Stock_providers.query.order_by(Stock_providers.name).all()
def componants():
""" Main page """
providers = Stock_providers.query.order_by(Stock_providers.id).all()
return render_template('componants.html',
providers=providers,
reference=session['c_reference'],
@ -141,9 +148,9 @@ def get_componants():
place=session['c_place'],
provider_id=session['c_provider'])
## Componant edition ##
@app.route('/componants/<componant_id>')
def get_componant(componant_id):
""" Edit componant """
try:
componant_id = int(componant_id)
except ValueError as e:
@ -156,50 +163,70 @@ def get_componant(componant_id):
return render_template('componant.html', componant=componant, providers=providers, provider=provider)
return render_template('error.html'), 404
## Componant update ##
@app.route('/componants/update/<componant_id>', methods=['POST'])
def update_componant(componant_id):
""" Update componant field"""
field = request.form['field']
value = request.form['value']
if field and value:
try:
componant = Stock_componants.query.filter_by(id=componant_id).first()
setattr(componant, field, value)
db.session.commit()
commit = db.session.commit()
if commit == None:
return 'OK'
except Exception as e:
return 'KO'
return 'OK'
pass
return 'KO'
## Componant deletion ##
@app.route('/componants/delete/<componant_id>')
def delete_componant(componant_id):
""" Delete componant """
try:
componant_id = int(componant_id)
except ValueError as e:
return render_template('error.html'), 404
Stock_componants.query.filter_by(id=componant_id).delete()
db.session.commit()
return get_componants()
return componants()
## Componant creation ##
@app.route('/componants/new/<componant_id>')
def add_componant(componant_id):
return render_template('wip.html')
@app.route('/componants/new', methods=['POST'])
@resume_session
def new_componant():
""" Add componant """
componant = Stock_componants(reference=session['c_reference'],
designation=session['c_designation'],
last_price=0,
mean_price=0,
quantity=0,
min_quantity=0,
place=session['c_place'],
provider_id=session['c_provider'])
try:
db.session.add(componant)
commit = db.session.commit()
except Exception as e:
print e
return 'KO'
if commit != None:
return 'KO'
return 'OK'
## Componants stock in ##
@app.route('/componants/in/<componant_id>')
def in_componants():
""" Incoming order """
return render_template('wip.html')
## Componants stock out ##
@app.route('/componants/out/<componant_id>')
def out_componants():
""" Outgoing order """
return render_template('wip.html')
## Componants update result set
@app.route('/componants/update', methods=['POST'])
@resume_session
def update_componants():
""" Display componants list """
# search by reference
like = '%s%s%s' % ('%', str(session['c_reference']), '%')
componants = Stock_componants.query.filter(Stock_componants.reference.like(like))
@ -210,18 +237,18 @@ def update_componants():
like = '%s%s%s' % ('%', str(session['c_place']),'%')
componants = componants.filter(Stock_componants.place.like(like))
# search by provider
if session['c_provider'] > 0:
if session['c_provider'] > 1:
componants = componants.filter_by(provider_id=session['c_provider'])
# Pages calculation
row_count = componants.count()
session['c_pagecount'] = int(math.ceil(row_count / float(session['c_limit'])))
session['c_count'] = componants.count()
session['c_pagecount'] = int(math.ceil(session['c_count'] / float(session['c_limit'])))
session['c_page'] = int(math.ceil(float(float(session['c_offset']) + 1) / float(session['c_limit'])))
if session['c_page'] > session['c_pagecount']:
session['c_page'] = session['c_pagecount']
session['c_offset'] = 0
print "*****", componants.count(), session['c_pagecount'], session['c_page']
session['c_nexthop'] = session['c_offset'] + session['c_limit']
if session['c_nexthop'] > row_count - 1:
if session['c_nexthop'] > session['c_count'] - 1:
session['c_nexthop'] = int(session['c_offset'])
session['c_prevhop'] = int(session['c_offset']) - session['c_limit']
if session['c_prevhop'] < 0:
@ -247,7 +274,7 @@ def update_componants():
page=session['c_page'],
sort=session['c_sort'],
order=session['c_order'],
row_count=row_count))
row_count=session['c_count']))
for key in session:
response.set_cookie(key, value=str(session[key]))
if key != 'session':