one line by article id

This commit is contained in:
Ludovic Stephan 2016-12-13 01:13:16 -02:00
parent 9443f86298
commit 711ef7e97b

View file

@ -774,16 +774,27 @@ $(document).ready(function() {
} }
function addPurchase(id, nb) { function addPurchase(id, nb) {
var amount_euro = amountEuroPurchase(id, nb).toFixed(2); var existing = false;
var index = addPurchaseToFormset(article_data[1], nb, amount_euro); formset_container.find('[data-opeindex]').each(function () {
article_basket_html = $(item_basket_default_html); var opeindex = $(this).attr('data-opeindex');
article_basket_html var article_id = $(this).find('#id_form-'+opeindex+'-article').val();
.attr('data-opeindex', index) if (article_id == id) {
.find('.number').text(nb).end() existing = true ;
.find('.name').text(article_data[0]).end() addExistingPurchase(opeindex, nb);
.find('.amount').text(amountToUKF(amount_euro, account_data['is_cof'])); }
basket_container.prepend(article_basket_html); });
updateBasketRel(); 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) { function addDeposit(amount, is_checkout=1) {
@ -903,8 +914,8 @@ $(document).ready(function() {
function addExistingPurchase(opeindex, nb) { function addExistingPurchase(opeindex, nb) {
type = formset_container.find("#id_form-"+opeindex+"-type").val(); type = formset_container.find("#id_form-"+opeindex+"-type").val();
id = formset_container.find("#id_form-"+opeindex+"-article").val(); id = formset_container.find("#id_form-"+opeindex+"-article").val();
nb_before = parseInt(formset_container.find("#id_form-"+opeindex+"-article_nb").val()); nb_before = formset_container.find("#id_form-"+opeindex+"-article_nb").val();
nb_after = nb_before + nb; nb_after = parseInt(nb_before) + parseInt(nb);
if (type == 'purchase') { if (type == 'purchase') {
if (nb_after == 0) { if (nb_after == 0) {
deleteFromBasket(opeindex); deleteFromBasket(opeindex);