Allow to create stock_article as copy of article in delivery form
This commit is contained in:
parent
cc5574f8b5
commit
cc1a839246
6 changed files with 41 additions and 7 deletions
|
@ -142,6 +142,9 @@ $(function() {
|
||||||
// Sort tables with a default sort
|
// Sort tables with a default sort
|
||||||
$('.sorter-bar.default-sort-asc button:nth-child(1)').trigger('click');
|
$('.sorter-bar.default-sort-asc button:nth-child(1)').trigger('click');
|
||||||
$('.sorter-bar.default-sort-desc button:nth-child(2)').trigger('click');
|
$('.sorter-bar.default-sort-desc button:nth-child(2)').trigger('click');
|
||||||
|
|
||||||
|
// Translate Select2 messages - could be done in another place, right?
|
||||||
|
$.fn.select2.defaults.formatNoMatches = function () { return "-"; };
|
||||||
});
|
});
|
||||||
|
|
||||||
// compare two elements interpreted as text
|
// compare two elements interpreted as text
|
||||||
|
|
|
@ -42,6 +42,12 @@ body {
|
||||||
dd { .clearfix(); }
|
dd { .clearfix(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fix nested content in btn-toolbar and btn-group, see https://github.com/twitter/bootstrap/issues/5497#issuecomment-10038711
|
||||||
|
.btn-toolbar > *,
|
||||||
|
.btn-group > * {
|
||||||
|
font-size: @baseFontSize;
|
||||||
|
}
|
||||||
|
|
||||||
@mainRedColor: #ED0606;
|
@mainRedColor: #ED0606;
|
||||||
|
|
||||||
.logo {
|
.logo {
|
||||||
|
|
|
@ -50,10 +50,15 @@ class DeliveriesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_stock_article
|
def new_stock_article
|
||||||
@old_stock_article = StockArticle.find_by_id(params[:old_stock_article_id])
|
if params[:old_stock_article_id]
|
||||||
|
old_article = StockArticle.find_by_id(params[:old_stock_article_id])
|
||||||
|
elsif params[:old_article_id]
|
||||||
|
old_article = Article.find_by_id(params[:old_article_id])
|
||||||
|
old_article = old_article.becomes(StockArticle) unless old_article.nil?
|
||||||
|
end
|
||||||
|
|
||||||
unless @old_stock_article.nil?
|
unless old_article.nil?
|
||||||
@stock_article = @old_stock_article.dup
|
@stock_article = old_article.dup
|
||||||
else
|
else
|
||||||
@stock_article = @supplier.stock_articles.build
|
@stock_article = @supplier.stock_articles.build
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,6 +14,10 @@ module DeliveriesHelper
|
||||||
supplier.stock_articles.undeleted.reorder('articles.name ASC').map {|a| ["#{a.name} (#{number_to_currency a.price}/#{a.unit})", a.id] }
|
supplier.stock_articles.undeleted.reorder('articles.name ASC').map {|a| ["#{a.name} (#{number_to_currency a.price}/#{a.unit})", a.id] }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def articles_for_select(supplier)
|
||||||
|
supplier.articles.undeleted.reorder('articles.name ASC').map {|a| ["#{a.name} (#{number_to_currency a.price}/#{a.unit})", a.id] }.unshift(['', nil])
|
||||||
|
end
|
||||||
|
|
||||||
def stock_articles_for_table(supplier)
|
def stock_articles_for_table(supplier)
|
||||||
supplier.stock_articles.undeleted.reorder('articles.name COLLATE NOCASE ASC')
|
supplier.stock_articles.undeleted.reorder('articles.name COLLATE NOCASE ASC')
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,7 +16,22 @@
|
||||||
unmark_article_unavailable_for_delivery( stock_change.data('id') );
|
unmark_article_unavailable_for_delivery( stock_change.data('id') );
|
||||||
return false;
|
return false;
|
||||||
})
|
})
|
||||||
|
$('#copy_from_article').select2({
|
||||||
|
placeholder: "Kopiere Bestellartikel",
|
||||||
|
allowClear: true
|
||||||
|
}).on('change', function(e) {
|
||||||
|
if(e.val != '') {
|
||||||
|
$.ajax({
|
||||||
|
url: '#{new_stock_article_supplier_deliveries_path(@supplier)}',
|
||||||
|
type: 'get',
|
||||||
|
data: {old_article_id: e.val},
|
||||||
|
contentType: 'application/json; charset=UTF-8'
|
||||||
|
});
|
||||||
|
$('#copy_from_article').select2('data', null);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function mark_article_unavailable_for_delivery(stock_article_id) {
|
function mark_article_unavailable_for_delivery(stock_article_id) {
|
||||||
var articleTr = $('#stock_article_' + stock_article_id);
|
var articleTr = $('#stock_article_' + stock_article_id);
|
||||||
articleTr.addClass('unavailable');
|
articleTr.addClass('unavailable');
|
||||||
|
@ -39,11 +54,12 @@
|
||||||
.row-fluid
|
.row-fluid
|
||||||
|
|
||||||
.span6
|
.span6
|
||||||
%h2 #{t '.title_select_stock_articles'}
|
%h2= t '.title_select_stock_articles'
|
||||||
.well.well-small
|
.well.well-small
|
||||||
.btn-toolbar
|
.btn-toolbar
|
||||||
.btn-group
|
.btn-group
|
||||||
= link_to t('.new_stock_article'), new_stock_article_supplier_deliveries_path(@supplier), remote: true, class: 'btn'
|
= link_to t('.new_stock_article'), new_stock_article_supplier_deliveries_path(@supplier), remote: true, class: 'btn'
|
||||||
|
= select_tag(:copy_from_article, options_for_select(articles_for_select(@supplier)))
|
||||||
%table.table.table-condensed.table-hover#stock_articles_for_adding
|
%table.table.table-condensed.table-hover#stock_articles_for_adding
|
||||||
%thead
|
%thead
|
||||||
%tr
|
%tr
|
||||||
|
@ -62,7 +78,7 @@
|
||||||
= render :partial => 'stock_article_for_adding', :locals => {:article => article}
|
= render :partial => 'stock_article_for_adding', :locals => {:article => article}
|
||||||
|
|
||||||
.span6
|
.span6
|
||||||
%h2 #{t '.title_fill_quantities'}
|
%h2= t '.title_fill_quantities'
|
||||||
%table.table.table-condensed#stock_changes
|
%table.table.table-condensed#stock_changes
|
||||||
%thead
|
%thead
|
||||||
%tr
|
%tr
|
||||||
|
@ -88,7 +104,7 @@
|
||||||
= stock_change_form.hidden_field :_destroy
|
= stock_change_form.hidden_field :_destroy
|
||||||
= link_to t('.remove_article'), "#", :class => 'destroy_stock_change btn btn-small'
|
= link_to t('.remove_article'), "#", :class => 'destroy_stock_change btn btn-small'
|
||||||
|
|
||||||
%h2 #{t '.title_finish_delivery'}
|
%h2= t '.title_finish_delivery'
|
||||||
= f.input :delivered_on, as: :date_picker
|
= f.input :delivered_on, as: :date_picker
|
||||||
= f.input :note, input_html: {size: '35x4'}
|
= f.input :note, input_html: {size: '35x4'}
|
||||||
.form-actions
|
.form-actions
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
- url = ( stock_article.new_record? ) ? ( add_stock_article_supplier_deliveries_path(@supplier) ) : ( update_stock_article_supplier_deliveries_path(@supplier) )
|
- url = ( stock_article.new_record? ) ? ( add_stock_article_supplier_deliveries_path(@supplier) ) : ( update_stock_article_supplier_deliveries_path(@supplier) )
|
||||||
= simple_form_for stock_article, url: url, remote: true, validate: true do |f|
|
= simple_form_for stock_article, url: url, remote: true do |f|
|
||||||
= f.hidden_field :supplier_id
|
= f.hidden_field :supplier_id
|
||||||
- unless stock_article.new_record?
|
- unless stock_article.new_record?
|
||||||
= f.hidden_field :id
|
= f.hidden_field :id
|
||||||
|
|
Loading…
Reference in a new issue