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
|
||||
$('.sorter-bar.default-sort-asc button:nth-child(1)').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
|
||||
|
|
|
@ -42,6 +42,12 @@ body {
|
|||
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;
|
||||
|
||||
.logo {
|
||||
|
|
|
@ -50,10 +50,15 @@ class DeliveriesController < ApplicationController
|
|||
end
|
||||
|
||||
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?
|
||||
@stock_article = @old_stock_article.dup
|
||||
unless old_article.nil?
|
||||
@stock_article = old_article.dup
|
||||
else
|
||||
@stock_article = @supplier.stock_articles.build
|
||||
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] }
|
||||
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)
|
||||
supplier.stock_articles.undeleted.reorder('articles.name COLLATE NOCASE ASC')
|
||||
end
|
||||
|
|
|
@ -16,7 +16,22 @@
|
|||
unmark_article_unavailable_for_delivery( stock_change.data('id') );
|
||||
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) {
|
||||
var articleTr = $('#stock_article_' + stock_article_id);
|
||||
articleTr.addClass('unavailable');
|
||||
|
@ -39,11 +54,12 @@
|
|||
.row-fluid
|
||||
|
||||
.span6
|
||||
%h2 #{t '.title_select_stock_articles'}
|
||||
%h2= t '.title_select_stock_articles'
|
||||
.well.well-small
|
||||
.btn-toolbar
|
||||
.btn-group
|
||||
= 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
|
||||
%thead
|
||||
%tr
|
||||
|
@ -62,7 +78,7 @@
|
|||
= render :partial => 'stock_article_for_adding', :locals => {:article => article}
|
||||
|
||||
.span6
|
||||
%h2 #{t '.title_fill_quantities'}
|
||||
%h2= t '.title_fill_quantities'
|
||||
%table.table.table-condensed#stock_changes
|
||||
%thead
|
||||
%tr
|
||||
|
@ -88,7 +104,7 @@
|
|||
= stock_change_form.hidden_field :_destroy
|
||||
= 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 :note, input_html: {size: '35x4'}
|
||||
.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) )
|
||||
= 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
|
||||
- unless stock_article.new_record?
|
||||
= f.hidden_field :id
|
||||
|
|
Loading…
Reference in a new issue