only allow to add articles not already present in receive
This commit is contained in:
parent
beabe22a01
commit
2d99141229
2 changed files with 21 additions and 6 deletions
|
@ -1,8 +1,11 @@
|
||||||
# :encoding:utf-8:
|
# :encoding:utf-8:
|
||||||
module Finance::ReceiveHelper
|
module Finance::ReceiveHelper
|
||||||
# TODO currently duplicate a bit of DeliveriesHelper.articles_for_select2
|
# TODO currently duplicate a bit of DeliveriesHelper.articles_for_select2
|
||||||
def articles_for_select2(supplier)
|
# except is an array of article id's to omit
|
||||||
supplier.articles.undeleted.reorder('articles.name ASC').map do |a|
|
def articles_for_select2(supplier, except = [])
|
||||||
|
articles = supplier.articles.reorder('articles.name ASC')
|
||||||
|
articles.reject! {|a| not except.index(a.id).nil? } if except
|
||||||
|
articles.map do |a|
|
||||||
{:id => a.id, :text => "#{a.name} (#{a.unit_quantity}⨯#{a.unit})"}
|
{:id => a.id, :text => "#{a.name} (#{a.unit_quantity}⨯#{a.unit})"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
- content_for :javascript do
|
- content_for :javascript do
|
||||||
:javascript
|
:javascript
|
||||||
|
|
||||||
|
var new_article_data = #{articles_for_select2(@order, @order_articles.map(&:article_id)).to_json};
|
||||||
|
|
||||||
function update_delta(input) {
|
function update_delta(input) {
|
||||||
var units = $(input).val();
|
var units = $(input).val();
|
||||||
var expected = $(input).data('units-expected');
|
var expected = $(input).data('units-expected');
|
||||||
|
@ -32,9 +34,13 @@
|
||||||
update_delta(this);
|
update_delta(this);
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#add_article').removeAttr('disabled').select2({
|
init_add_article('#add_article');
|
||||||
|
});
|
||||||
|
|
||||||
|
function init_add_article(sel) {
|
||||||
|
$(sel).removeAttr('disabled').select2({
|
||||||
placeholder: '#{t '.add_article'}',
|
placeholder: '#{t '.add_article'}',
|
||||||
data: #{articles_for_select2(@order).to_json},
|
data: new_article_data,
|
||||||
// TODO implement adding a new article, like in deliveries
|
// TODO implement adding a new article, like in deliveries
|
||||||
}).on('change', function(e) {
|
}).on('change', function(e) {
|
||||||
var selectedArticle = $(e.currentTarget).select2('data');
|
var selectedArticle = $(e.currentTarget).select2('data');
|
||||||
|
@ -48,11 +54,17 @@
|
||||||
data: {article_id: selectedArticle.id},
|
data: {article_id: selectedArticle.id},
|
||||||
contentType: 'application/json; charset=UTF-8'
|
contentType: 'application/json; charset=UTF-8'
|
||||||
});
|
});
|
||||||
|
// clear selection
|
||||||
$('#add_article').select2('data', null);
|
$('#add_article').select2('data', null);
|
||||||
|
// remove newly added item from list of items
|
||||||
|
new_article_data = $.grep(new_article_data, function(el, i) {
|
||||||
|
return el.id != selectedArticle.id;
|
||||||
|
});
|
||||||
|
init_add_article(sel)
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
%table.ordered-articles.table.table-striped.stupidtable
|
%table.ordered-articles.table.table-striped.stupidtable
|
||||||
|
|
Loading…
Reference in a new issue