diff --git a/app/views/deliveries/_form.html.haml b/app/views/deliveries/_form.html.haml
index 533f44c3..a0f1594a 100644
--- a/app/views/deliveries/_form.html.haml
+++ b/app/views/deliveries/_form.html.haml
@@ -44,7 +44,7 @@
$.ajax({
url: '#{new_stock_article_path}',
type: 'get',
- data: {stock_article: {name: selectedArticle.text}},
+ data: {stock_article: {name: selectedArticle.text, supplier_id: #{@supplier.id}}},
contentType: 'application/json; charset=UTF-8'
});
$('#new_stock_article').select2('data', null);
diff --git a/app/views/deliveries/form_on_stock_article_create.js.erb b/app/views/deliveries/form_on_stock_article_create.js.erb
index 25360761..fd1b2d0f 100644
--- a/app/views/deliveries/form_on_stock_article_create.js.erb
+++ b/app/views/deliveries/form_on_stock_article_create.js.erb
@@ -1,12 +1,31 @@
// Handle more advanced DOM update after AJAX database manipulation.
// See publish/subscribe design pattern in /doc.
-(function() {
+(function(w) {
+
$('#stock_articles_for_adding tr').removeClass('success');
+ if(<%= @supplier.id != @stock_article.supplier.id %>) {
+ // the stock_article does _NOT_ belong to the current supplier
+ var try_again = w.confirm('<%= j(
+ t('deliveries.form.confirm_foreign_supplier_reedit', :name => @stock_article.name)
+ ) %>');
+
+ if(try_again) {
+ $.ajax({
+ url: '<%= j edit_stock_article_path(@stock_article) %>',
+ type: 'get',
+ contentType: 'application/json; charset=UTF-8'
+ });
+ }
+
+ return false;
+ }
+
+ // the stock_article _DOES_ belong to the current supplier
var stock_article_for_adding = $(
'<%= j(render(:partial => 'stock_article_for_adding', :locals => {:article => @stock_article})) %>'
).addClass('success');
$('#stock_articles_for_adding tbody').append(stock_article_for_adding);
updateSort('#stock_articles_for_adding');
-})();
+})(window);
diff --git a/app/views/deliveries/form_on_stock_article_update.js.erb b/app/views/deliveries/form_on_stock_article_update.js.erb
index a5a90d94..3d78eb0d 100644
--- a/app/views/deliveries/form_on_stock_article_update.js.erb
+++ b/app/views/deliveries/form_on_stock_article_update.js.erb
@@ -1,16 +1,35 @@
// Handle more advanced DOM update after AJAX database manipulation.
// See publish/subscribe design pattern in /doc.
-(function() {
+(function(w) {
// update entry in stock_article table
$('#stock_articles_for_adding tr').removeClass('success');
- var stock_article_for_adding = $(
- '<%= j(render(:partial => 'stock_article_for_adding', :locals => {:article => @stock_article})) %>'
- ).addClass('success');
+ $('#stock_article_<%= @stock_article.id %>').remove();
- $('#stock_article_<%= @stock_article.id %>').replaceWith(stock_article_for_adding);
- updateSort('#stock_articles_for_adding');
+ if(<%= @supplier.id != @stock_article.supplier.id %>) {
+ // the stock_article does _NOT_ belong to the current supplier
+ var try_again = w.confirm('<%= j(
+ t('deliveries.form.confirm_foreign_supplier_reedit', :name => @stock_article.name)
+ ) %>');
+
+ if(try_again) {
+ $.ajax({
+ url: '<%= j edit_stock_article_path(@stock_article) %>',
+ type: 'get',
+ contentType: 'application/json; charset=UTF-8'
+ });
+ }
+ }
+ else {
+ // the stock_article _DOES_ belong to the current supplier
+ var stock_article_for_adding = $(
+ '<%= j(render(:partial => 'stock_article_for_adding', :locals => {:article => @stock_article})) %>'
+ ).addClass('success');
+
+ $('#stock_articles_for_adding tbody').append(stock_article_for_adding);
+ updateSort('#stock_articles_for_adding');
+ }
mark_article_for_delivery(<%= @stock_article.id %>);
@@ -25,4 +44,4 @@
stock_change_entry.addClass('success');
updateSort('#stock_changes');
-})();
+})(window);
diff --git a/config/locales/de.yml b/config/locales/de.yml
index 2e5e11a3..d33f5266 100644
--- a/config/locales/de.yml
+++ b/config/locales/de.yml
@@ -413,6 +413,7 @@ de:
actions: Optionen
article: Artikel
category: Kategorie
+ confirm_foreign_supplier_reedit: Der Lagerartikel »%{name}« wurde erfolgreich gespeichert. Er gehört jedoch nicht zu dem Lieferanten dieser Lieferung. Möchtest Du diesen Lagerartikel erneut bearbeiten?
create_from_blank: Ohne Vorlage anlegen
create_stock_article: Lagerartikel anlegen
price: Nettopreis
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 9d7849f6..bf0127b5 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -415,6 +415,7 @@ en:
actions: Tasks
article: Article
category: Category
+ confirm_foreign_supplier_reedit: The stock article %{name} was successfully saved. However, it belongs to a different supplier than this delivery. Would you like to edit the stock article again?
create_from_blank: Create new article
create_stock_article: Create stock article
price: Netprice