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) {
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);