Update addExistingPurchase
This commit is contained in:
parent
3ce4dc5c85
commit
05156f37c6
2 changed files with 14 additions and 14 deletions
|
@ -417,16 +417,19 @@ class ArticleManager {
|
|||
this.list.fromAPI({}, this.display_list.bind(this), $.noop) ;
|
||||
}
|
||||
|
||||
//TODO: filter articles before ?
|
||||
get_article(id) {
|
||||
return this.list.find('article', id).content;
|
||||
}
|
||||
|
||||
update_data(data) {
|
||||
for (let article_dict of data.articles) {
|
||||
var article = this.list.find('article', article_dict['id']);
|
||||
var article = this.get_article(article_dict.id);
|
||||
|
||||
// For now, article additions are disregarded
|
||||
if (article) {
|
||||
article.stock = article_dict['stock'];
|
||||
this._$container.find('#article-'+article_dict['id']+' .stock')
|
||||
.text(article_dict['stock']);
|
||||
article.stock = article_dict.stock;
|
||||
this._$container.find('#article-'+article.id+' .stock')
|
||||
.text(article.stock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -464,15 +464,12 @@ $(document).ready(function() {
|
|||
function addExistingPurchase(opeindex, nb) {
|
||||
var type = formset_container.find("#id_form-"+opeindex+"-type").val();
|
||||
var id = formset_container.find("#id_form-"+opeindex+"-article").val();
|
||||
var article = kpsul.article_manager.get_article(parseInt(id));
|
||||
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 amountEuro_after = amountEuroPurchase(article, nb_after);
|
||||
var amountUKF_after = amountToUKF(amountEuro_after, kpsul.account_manager.account.is_cof, false);
|
||||
|
||||
var i = 0;
|
||||
while (i<articlesList.length && id != articlesList[i][1]) i++;
|
||||
var article_data = articlesList[i];
|
||||
|
||||
if (type == 'purchase') {
|
||||
if (nb_after == 0) {
|
||||
deleteFromBasket(opeindex);
|
||||
|
@ -480,20 +477,20 @@ $(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.stock+')').end() ;
|
||||
|
||||
} 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('.number').text('('+nb_after+'/'+article.stock+')').end()
|
||||
.find('.name').text(article.name).end()
|
||||
.find('.amount').text(amountUKF_after);
|
||||
basket_container.prepend(article_basket_html);
|
||||
|
||||
}
|
||||
|
||||
if (is_low_stock(id, nb_after))
|
||||
if (is_low_stock(article, nb_after))
|
||||
article_html.find('.lowstock')
|
||||
.show();
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue