From 5492ecf534c6a8131ae5701b33328c56b0e7918b Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Tue, 13 Dec 2016 00:32:52 -0200 Subject: [PATCH 01/14] add ukf for price visibility --- kfet/templates/kfet/kpsul.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index 88f8f2f9..47feb71b 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -563,7 +563,7 @@ $(document).ready(function() { for (var elem in article) { article_html.find('.'+elem).text(article[elem]) } - article_html.find('.price').text(amountToUKF(article['price'], false)); + article_html.find('.price').text(amountToUKF(article['price'], false)+' UKF'); var category_html = articles_container .find('#data-category-'+article['category_id']); if (category_html.length == 0) { From 437233fd1071a9e44f9da8765367389d76ceaeb7 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Tue, 13 Dec 2016 00:33:25 -0200 Subject: [PATCH 02/14] functions to change purchase amount --- kfet/templates/kfet/kpsul.html | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index 47feb71b..4be8b48e 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -886,6 +886,26 @@ $(document).ready(function() { updateBasketRel(); } + function addExistingPurchase(opeindex, nb) { + type = formset_container.find("#id_form-"+opeindex+"-type").val(); + id = formset_container.find("#id_form-"+opeindex+"-article").val(); + nb_before = parseInt(formset_container.find("#id_form-"+opeindex+"-article_nb").val()); + nb_after = nb_before + nb; + if (type == 'purchase') { + if (nb_after == 0) { + deleteFromBasket(opeindex); + } else if (nb_after > 0 && nb_after <= 25) { + amountEuro_after = amountEuroPurchase(id, nb_after); + amountUKF_after = amountToUKF(amountEuro_after, account_data['is_cof']); + basket_container.find('[data-opeindex='+opeindex+']') + .find('.amount').text(amountUKF_after).end() + .find('.number').text(nb_after).end() ; + updateExistingFormset(opeindex, nb_after, amountEuro_after); + updateBasketRel(); + } + } + } + function resetBasket() { basket_container.find('tr').remove(); mngmt_total_forms = 1; @@ -1022,6 +1042,12 @@ $(document).ready(function() { formset_container.find('#id_form-'+opeindex+'-DELETE').prop('checked', true); } + function updateExistingFormset(opeindex, nb, amount) { + formset_container + .find('#id_form-'+opeindex+'-amount').val((parseFloat(amount)).toFixed(2)).end() + .find('#id_form-'+opeindex+'-article_nb').val(nb); + } + // ----- // History // ----- From 9443f86298e3316991c03d83c39c15b932c4f587 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Tue, 13 Dec 2016 01:11:35 -0200 Subject: [PATCH 03/14] use arrow keys to add/remove article --- kfet/templates/kfet/kpsul.html | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index 4be8b48e..1a177dcd 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -617,8 +617,8 @@ $(document).ready(function() { var articleSelect = $('#article_autocomplete'); var articleId = $('#article_id'); var articleNb = $('#article_number'); - // 8:Backspace|9:Tab|13:Enter|46:DEL|112-117:F1-6|119-123:F8-F12 - var normalKeys = /^(8|9|13|46|112|113|114|115|116|117|119|120|121|122|123)$/; + // 8:Backspace|9:Tab|13:Enter|38-40:Arrows|46:DEL|112-117:F1-6|119-123:F8-F12 + var normalKeys = /^(8|9|13|37|38|39|40|46|112|113|114|115|116|117|119|120|121|122|123)$/; var articlesList = []; function deleteNonMatching(array, str) { @@ -818,11 +818,25 @@ $(document).ready(function() { }); $(document).on('keydown', function (e) { - if (e.keyCode == 46) { - // DEL (Suppr) - basket_container.find('.ui-selected').each(function () { - deleteFromBasket($(this).data('opeindex')); - }); + switch(e.which) { + case 46: + // DEL (Suppr) + basket_container.find('.ui-selected').each(function () { + deleteFromBasket($(this).data('opeindex')); + }); + break; + case 38: + // Arrow up + basket_container.find('.ui-selected').each(function () { + addExistingPurchase($(this).data('opeindex'), 1); + }); + break; + case 40: + // Arrow down + basket_container.find('.ui-selected').each(function () { + addExistingPurchase($(this).data('opeindex'), -1); + }); + break; } }); From 711ef7e97bfc027dcfce7061d7d6d2369f3e1c4c Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Tue, 13 Dec 2016 01:13:16 -0200 Subject: [PATCH 04/14] one line by article id --- kfet/templates/kfet/kpsul.html | 35 ++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index 1a177dcd..a78028bf 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -774,16 +774,27 @@ $(document).ready(function() { } function addPurchase(id, nb) { - var amount_euro = amountEuroPurchase(id, nb).toFixed(2); - var index = addPurchaseToFormset(article_data[1], nb, amount_euro); - article_basket_html = $(item_basket_default_html); - article_basket_html - .attr('data-opeindex', index) - .find('.number').text(nb).end() - .find('.name').text(article_data[0]).end() - .find('.amount').text(amountToUKF(amount_euro, account_data['is_cof'])); - basket_container.prepend(article_basket_html); - updateBasketRel(); + var existing = false; + formset_container.find('[data-opeindex]').each(function () { + var opeindex = $(this).attr('data-opeindex'); + var article_id = $(this).find('#id_form-'+opeindex+'-article').val(); + if (article_id == id) { + existing = true ; + addExistingPurchase(opeindex, nb); + } + }); + if (!existing) { + var amount_euro = amountEuroPurchase(id, nb).toFixed(2); + var index = addPurchaseToFormset(article_data[1], nb, amount_euro); + article_basket_html = $(item_basket_default_html); + article_basket_html + .attr('data-opeindex', index) + .find('.number').text(nb).end() + .find('.name').text(article_data[0]).end() + .find('.amount').text(amountToUKF(amount_euro, account_data['is_cof'])); + basket_container.prepend(article_basket_html); + updateBasketRel(); + } } function addDeposit(amount, is_checkout=1) { @@ -903,8 +914,8 @@ $(document).ready(function() { function addExistingPurchase(opeindex, nb) { type = formset_container.find("#id_form-"+opeindex+"-type").val(); id = formset_container.find("#id_form-"+opeindex+"-article").val(); - nb_before = parseInt(formset_container.find("#id_form-"+opeindex+"-article_nb").val()); - nb_after = nb_before + nb; + nb_before = formset_container.find("#id_form-"+opeindex+"-article_nb").val(); + nb_after = parseInt(nb_before) + parseInt(nb); if (type == 'purchase') { if (nb_after == 0) { deleteFromBasket(opeindex); From 080ff0f8218d404db4d56171bdab7e0652ee654f Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Tue, 13 Dec 2016 01:41:59 -0200 Subject: [PATCH 05/14] warning if not enough stock --- kfet/static/kfet/css/kpsul.css | 5 +++++ kfet/templates/kfet/kpsul.html | 22 ++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/kfet/static/kfet/css/kpsul.css b/kfet/static/kfet/css/kpsul.css index 9fd53604..8e713651 100644 --- a/kfet/static/kfet/css/kpsul.css +++ b/kfet/static/kfet/css/kpsul.css @@ -383,6 +383,11 @@ input[type=number]::-webkit-outer-spin-button { color:#FFF; } +#basket tr.low-stock { + background-color:rgba(236,100,0,0.6); + color:#FFF; +} + /* History */ .kpsul_middle_right_col { diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index a78028bf..4177c16d 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -589,7 +589,7 @@ $(document).ready(function() { }); $after.after(article_html); // Pour l'autocomplétion - articlesList.push([article['name'],article['id'],article['category_id'],article['price']]); + articlesList.push([article['name'],article['id'],article['category_id'],article['price'], article['stock']]); } function getArticles() { @@ -792,11 +792,22 @@ $(document).ready(function() { .find('.number').text(nb).end() .find('.name').text(article_data[0]).end() .find('.amount').text(amountToUKF(amount_euro, account_data['is_cof'])); + if (is_low_stock(id, nb)) + article_basket_html.addClass('low-stock'); basket_container.prepend(article_basket_html); updateBasketRel(); } } + function is_low_stock(id, nb) { + var i = 0 ; + while (i= 0 && stock < nb) ; + } + function addDeposit(amount, is_checkout=1) { var deposit_basket_html = $(item_basket_default_html); var amount = parseFloat(amount).toFixed(2); @@ -922,9 +933,12 @@ $(document).ready(function() { } else if (nb_after > 0 && nb_after <= 25) { amountEuro_after = amountEuroPurchase(id, nb_after); amountUKF_after = amountToUKF(amountEuro_after, account_data['is_cof']); - basket_container.find('[data-opeindex='+opeindex+']') - .find('.amount').text(amountUKF_after).end() - .find('.number').text(nb_after).end() ; + var article_html = basket_container.find('[data-opeindex='+opeindex+']'); + article_html.find('.amount').text(amountUKF_after).end() + .find('.number').text(nb_after).end() ; + + if (is_low_stock(id, nb_after)) + article_html.addClass('low-stock'); updateExistingFormset(opeindex, nb_after, amountEuro_after); updateBasketRel(); } From 71fee9bf8a49386a7feb878fb46f40addeaddddc Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Tue, 13 Dec 2016 20:58:40 -0200 Subject: [PATCH 06/14] temporary low stock css --- kfet/static/kfet/css/kpsul.css | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/kfet/static/kfet/css/kpsul.css b/kfet/static/kfet/css/kpsul.css index 8e713651..86418d09 100644 --- a/kfet/static/kfet/css/kpsul.css +++ b/kfet/static/kfet/css/kpsul.css @@ -378,13 +378,12 @@ input[type=number]::-webkit-outer-spin-button { text-align:right; } -#basket tr.ui-selected, #basket tr.ui-selecting { - background-color:rgba(200,16,46,0.6); - color:#FFF; +#basket tr.low-stock { + background-color:rgba(236,100,0,0.4); } -#basket tr.low-stock { - background-color:rgba(236,100,0,0.6); +#basket tr.ui-selected, #basket tr.ui-selecting { + background-color:rgba(200,16,46,0.6); color:#FFF; } From b7ebf4ee1c58a99ed10cdbad3fa6883a0f54a6cf Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Tue, 13 Dec 2016 22:31:52 -0200 Subject: [PATCH 07/14] add stock to article selection --- kfet/static/kfet/css/kpsul.css | 26 ++++++++++++++++++++------ kfet/templates/kfet/kpsul.html | 7 +++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/kfet/static/kfet/css/kpsul.css b/kfet/static/kfet/css/kpsul.css index 86418d09..9e2679f9 100644 --- a/kfet/static/kfet/css/kpsul.css +++ b/kfet/static/kfet/css/kpsul.css @@ -8,7 +8,7 @@ input[type=number]::-webkit-outer-spin-button { margin: 0; } -#account, #checkout, input, #history, #basket, #basket_rel, #articles_data { +#account, #checkout, #article_selection, #history, #basket, #basket_rel, #articles_data { background:#fff; } @@ -252,7 +252,7 @@ input[type=number]::-webkit-outer-spin-button { width:100%; } -#article_selection input { +#article_selection input, #article_selection span { height:100%; float:left; border:0; @@ -263,12 +263,12 @@ input[type=number]::-webkit-outer-spin-button { font-weight:bold; } -#article_selection input+input { +#article_selection input+input #article_selection input+span { border-right:0; } #article_autocomplete { - width:90%; + width:80%; padding-left:10px; } @@ -277,14 +277,24 @@ input[type=number]::-webkit-outer-spin-button { text-align:center; } +#article_stock { + width:10%; + line-height:38px; + text-align:center; +} + @media (min-width:1200px) { #article_autocomplete { - width:92% + width:84% } #article_number { width:8%; } + + #article_stock { + width:8%; + } } /* Article data */ @@ -319,6 +329,10 @@ input[type=number]::-webkit-outer-spin-button { padding-left:20px; } +#articles_data .article.low-stock { + background:rgba(236,100,0,0.3); +} + #articles_data .article:hover { background:rgba(200,16,46,0.3); cursor:pointer; @@ -379,7 +393,7 @@ input[type=number]::-webkit-outer-spin-button { } #basket tr.low-stock { - background-color:rgba(236,100,0,0.4); + background-color:rgba(236,100,0,0.3); } #basket tr.ui-selected, #basket tr.ui-selecting { diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index 4177c16d..0d7cb39c 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -122,6 +122,7 @@
+
@@ -563,6 +564,9 @@ $(document).ready(function() { for (var elem in article) { article_html.find('.'+elem).text(article[elem]) } + if (-5 <= article['stock'] && article['stock'] <= 5) { + article_html.addClass('low-stock'); + } article_html.find('.price').text(amountToUKF(article['price'], false)+' UKF'); var category_html = articles_container .find('#data-category-'+article['category_id']); @@ -617,6 +621,7 @@ $(document).ready(function() { var articleSelect = $('#article_autocomplete'); var articleId = $('#article_id'); var articleNb = $('#article_number'); + var articleStock = $('#article_stock'); // 8:Backspace|9:Tab|13:Enter|38-40:Arrows|46:DEL|112-117:F1-6|119-123:F8-F12 var normalKeys = /^(8|9|13|37|38|39|40|46|112|113|114|115|116|117|119|120|121|122|123)$/; var articlesList = []; @@ -674,6 +679,7 @@ $(document).ready(function() { if (commit) { articleId.val(articlesMatch[0][1]); articleSelect.val(articlesMatch[0][0]); + articleStock.text('/'+articlesMatch[0][4]); displayMatchedArticles(articlesList); return true; } @@ -954,6 +960,7 @@ $(document).ready(function() { articleId.val(0); articleSelect.val(''); articleNb.val(''); + articleStock.text(''); displayMatchedArticles(articlesList); } From 75be9fd2a62fbeb7a617a6e556a646ac6bdc1322 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Wed, 14 Dec 2016 23:40:23 -0200 Subject: [PATCH 08/14] display stock with mouse selection --- kfet/templates/kfet/kpsul.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index 0d7cb39c..93b42b39 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -726,10 +726,15 @@ $(document).ready(function() { return $article.find('.name').text(); } + function getArticleStock($article) { + return $article.find('.stock').text(); + } + // Sélection des articles à la souris/tactile articles_container.on('click', '.article', function() { articleId.val(getArticleId($(this))); articleSelect.val(getArticleName($(this))); + articleStock.text('/'+getArticleStock($(this))); displayMatchedArticles(articlesList); goToArticleNb(); }); From 4db55efb67fc50ae64799b14d677c913b20e81cb Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Wed, 14 Dec 2016 23:40:42 -0200 Subject: [PATCH 09/14] change stock warning threshold --- kfet/templates/kfet/kpsul.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index 93b42b39..f18994b4 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -816,7 +816,7 @@ $(document).ready(function() { article_data = articlesList[i]; stock = article_data[4] ; - return (stock >= 0 && stock < nb) ; + return (-5 <= stock - nb && stock - nb <= 5); } function addDeposit(amount, is_checkout=1) { From 5784b4d20a4355dd4b4afdc28330220ec0001167 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Tue, 20 Dec 2016 01:09:22 -0200 Subject: [PATCH 10/14] change stock warning CSS for basket --- kfet/static/kfet/css/kpsul.css | 6 ++++-- kfet/templates/kfet/kpsul.html | 16 +++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/kfet/static/kfet/css/kpsul.css b/kfet/static/kfet/css/kpsul.css index 9e2679f9..09c54845 100644 --- a/kfet/static/kfet/css/kpsul.css +++ b/kfet/static/kfet/css/kpsul.css @@ -392,8 +392,10 @@ input[type=number]::-webkit-outer-spin-button { text-align:right; } -#basket tr.low-stock { - background-color:rgba(236,100,0,0.3); +#basket tr .lowstock { + visibility:hidden; + width:20px; + padding-right:15px; } #basket tr.ui-selected, #basket tr.ui-selecting { diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index f18994b4..ca2b2436 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -767,7 +767,7 @@ $(document).ready(function() { // Basket // ----- - var item_basket_default_html = ''; + var item_basket_default_html = ''; var basket_container = $('#basket table'); var arrowKeys = /^(37|38|39|40)$/; @@ -800,11 +800,12 @@ $(document).ready(function() { article_basket_html = $(item_basket_default_html); article_basket_html .attr('data-opeindex', index) - .find('.number').text(nb).end() + .find('.number').text('('+nb+'/'+article_data[4]+')').end() .find('.name').text(article_data[0]).end() .find('.amount').text(amountToUKF(amount_euro, account_data['is_cof'])); if (is_low_stock(id, nb)) - article_basket_html.addClass('low-stock'); + article_basket_html.find('.lowstock') + .css('visibility', 'visible'); basket_container.prepend(article_basket_html); updateBasketRel(); } @@ -946,10 +947,15 @@ $(document).ready(function() { amountUKF_after = amountToUKF(amountEuro_after, account_data['is_cof']); var article_html = basket_container.find('[data-opeindex='+opeindex+']'); article_html.find('.amount').text(amountUKF_after).end() - .find('.number').text(nb_after).end() ; + .find('.number').text(nb_after+'/'+article_data[4]).end() ; if (is_low_stock(id, nb_after)) - article_html.addClass('low-stock'); + article_html.find('.lowstock') + .css('visibility', 'visible'); + else + article_html.find('.lowstock') + .css('visibility', 'hidden'); + updateExistingFormset(opeindex, nb_after, amountEuro_after); updateBasketRel(); } From e981cad4054ff37c020a2b8a9fe0b47759314f5e Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Tue, 20 Dec 2016 16:48:09 -0200 Subject: [PATCH 11/14] css tweaks --- kfet/static/kfet/css/kpsul.css | 3 +-- kfet/templates/kfet/kpsul.html | 9 +++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/kfet/static/kfet/css/kpsul.css b/kfet/static/kfet/css/kpsul.css index 09c54845..c30afd72 100644 --- a/kfet/static/kfet/css/kpsul.css +++ b/kfet/static/kfet/css/kpsul.css @@ -393,8 +393,7 @@ input[type=number]::-webkit-outer-spin-button { } #basket tr .lowstock { - visibility:hidden; - width:20px; + display:none; padding-right:15px; } diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index ca2b2436..18c92ea0 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -748,6 +748,7 @@ $(document).ready(function() { addPurchase(articleId.val(), articleNb.val()); articleSelect.val(''); articleNb.val(''); + articleStock.text(''); articleSelect.focus(); displayMatchedArticles(articlesList); return false; @@ -767,7 +768,7 @@ $(document).ready(function() { // Basket // ----- - var item_basket_default_html = ''; + var item_basket_default_html = ''; var basket_container = $('#basket table'); var arrowKeys = /^(37|38|39|40)$/; @@ -805,7 +806,7 @@ $(document).ready(function() { .find('.amount').text(amountToUKF(amount_euro, account_data['is_cof'])); if (is_low_stock(id, nb)) article_basket_html.find('.lowstock') - .css('visibility', 'visible'); + .show(); basket_container.prepend(article_basket_html); updateBasketRel(); } @@ -951,10 +952,10 @@ $(document).ready(function() { if (is_low_stock(id, nb_after)) article_html.find('.lowstock') - .css('visibility', 'visible'); + .show(); else article_html.find('.lowstock') - .css('visibility', 'hidden'); + .hide(); updateExistingFormset(opeindex, nb_after, amountEuro_after); updateBasketRel(); From 2394a5e5d2e7ecb9457d52cefe4eeb3db69fe70a Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Sun, 5 Feb 2017 21:38:13 -0200 Subject: [PATCH 12/14] add low stock css to WS --- kfet/templates/kfet/kpsul.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index 3fba824d..103dcc62 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -1335,6 +1335,8 @@ $(document).ready(function() { } for (var i=0; i Date: Sun, 12 Feb 2017 11:02:54 -0200 Subject: [PATCH 13/14] bugfix --- kfet/templates/kfet/kpsul.html | 47 ++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index 103dcc62..636a755d 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -989,27 +989,39 @@ $(document).ready(function() { } function addExistingPurchase(opeindex, nb) { - type = formset_container.find("#id_form-"+opeindex+"-type").val(); - id = formset_container.find("#id_form-"+opeindex+"-article").val(); - nb_before = formset_container.find("#id_form-"+opeindex+"-article_nb").val(); - nb_after = parseInt(nb_before) + parseInt(nb); + var type = formset_container.find("#id_form-"+opeindex+"-type").val(); + var id = formset_container.find("#id_form-"+opeindex+"-article").val(); + var nb_before = formset_container.find("#id_form-"+opeindex+"-article_nb").val(); + var nb_after = parseInt(nb_before) + parseInt(nb); + var amountEuro_after = amountEuroPurchase(id, nb_after); + var amountUKF_after = amountToUKF(amountEuro_after, account_data['is_cof']); + if (type == 'purchase') { if (nb_after == 0) { deleteFromBasket(opeindex); } else if (nb_after > 0 && nb_after <= 25) { - amountEuro_after = amountEuroPurchase(id, nb_after); - amountUKF_after = amountToUKF(amountEuro_after, account_data['is_cof']); - var article_html = basket_container.find('[data-opeindex='+opeindex+']'); - article_html.find('.amount').text(amountUKF_after).end() - .find('.number').text(nb_after+'/'+article_data[4]).end() ; + if (nb_before > 0) { + var article_html = basket_container.find('[data-opeindex='+opeindex+']'); + article_html.find('.amount').text(amountUKF_after).end() + .find('.number').text(nb_after+'/'+article_data[4]).end() ; - if (is_low_stock(id, nb_after)) - article_html.find('.lowstock') - .show(); - else - article_html.find('.lowstock') - .hide(); + } else { + article_html = $(item_basket_default_html); + article_html + .attr('data-opeindex', opeindex) + .find('.number').text('('+nb_after+'/'+article_data[4]+')').end() + .find('.name').text(article_data[0]).end() + .find('.amount').text(amountUKF_after); + basket_container.prepend(article_basket_html); + } + + if (is_low_stock(id, nb_after)) + article_html.find('.lowstock') + .show(); + else + article_html.find('.lowstock') + .hide(); updateExistingFormset(opeindex, nb_after, amountEuro_after); updateBasketRel(); } @@ -1150,13 +1162,14 @@ $(document).ready(function() { } function deleteFromFormset(opeindex) { - formset_container.find('#id_form-'+opeindex+'-DELETE').prop('checked', true); + updateExistingFormset(opeindex, 0, '0.00'); } function updateExistingFormset(opeindex, nb, amount) { formset_container .find('#id_form-'+opeindex+'-amount').val((parseFloat(amount)).toFixed(2)).end() - .find('#id_form-'+opeindex+'-article_nb').val(nb); + .find('#id_form-'+opeindex+'-article_nb').val(nb).end() + .find('#id_form-'+opeindex+'-DELETE').prop('checked', !nb); } // ----- From 031b992fa3b8dd0c899830ff75eee50e9476be3b Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Sun, 12 Feb 2017 11:09:03 -0200 Subject: [PATCH 14/14] fix brackets & lowstock indication --- kfet/templates/kfet/kpsul.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index 636a755d..d5ca2810 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -857,10 +857,10 @@ $(document).ready(function() { .find('.number').text('('+nb+'/'+article_data[4]+')').end() .find('.name').text(article_data[0]).end() .find('.amount').text(amountToUKF(amount_euro, account_data['is_cof'])); + basket_container.prepend(article_basket_html); if (is_low_stock(id, nb)) article_basket_html.find('.lowstock') .show(); - basket_container.prepend(article_basket_html); updateBasketRel(); } } @@ -1003,7 +1003,7 @@ $(document).ready(function() { if (nb_before > 0) { var article_html = basket_container.find('[data-opeindex='+opeindex+']'); article_html.find('.amount').text(amountUKF_after).end() - .find('.number').text(nb_after+'/'+article_data[4]).end() ; + .find('.number').text('('+nb_after+'/'+article_data[4]+')').end() ; } else { article_html = $(item_basket_default_html);