Add stock_article_selection (deleting multiple stock articles at once)
This commit is contained in:
parent
ecb7ce7cd3
commit
099e2b9b06
13 changed files with 217 additions and 34 deletions
|
@ -3,6 +3,7 @@ class StockitController < ApplicationController
|
||||||
def index
|
def index
|
||||||
@stock_articles = StockArticle.includes(:supplier, :article_category).
|
@stock_articles = StockArticle.includes(:supplier, :article_category).
|
||||||
order('suppliers.name, article_categories.name, articles.name')
|
order('suppliers.name, article_categories.name, articles.name')
|
||||||
|
@stock_article_selection = StockArticleSelection.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
|
56
app/controllers/stockit_selections_controller.rb
Normal file
56
app/controllers/stockit_selections_controller.rb
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
class StockitSelectionsController < ApplicationController
|
||||||
|
|
||||||
|
def index
|
||||||
|
@stock_article_selections = StockArticleSelection.all
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
@stock_article_selection = StockArticleSelection.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@stock_article_selection = StockArticleSelection.new(params[:stock_article_selection])
|
||||||
|
@stock_article_selection.created_by = current_user
|
||||||
|
|
||||||
|
if @stock_article_selection.save
|
||||||
|
redirect_to(@stock_article_selection, :notice => 'Löschvorschlag für gewählte Artikel wurde erstellt.')
|
||||||
|
else
|
||||||
|
@stock_articles = StockArticle.includes(:supplier, :article_category).
|
||||||
|
order('suppliers.name, article_categories.name, articles.name')
|
||||||
|
render 'stockit/index'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy # destroy (open or finished) selection without deleting articles
|
||||||
|
stock_article_selection = StockArticleSelection.find(params[:id])
|
||||||
|
stock_article_selection.destroy
|
||||||
|
|
||||||
|
redirect_to stock_article_selections_path, :notice => 'Löschvorschlag wurde verworfen.'
|
||||||
|
end
|
||||||
|
|
||||||
|
def articles # destroy articles, finish selection
|
||||||
|
stock_article_selection = StockArticleSelection.find(params[:id])
|
||||||
|
|
||||||
|
destroyed_articles_count = 0
|
||||||
|
failed_articles_count = 0
|
||||||
|
stock_article_selection.stock_articles.each do |article|
|
||||||
|
begin
|
||||||
|
article.destroy # article.delete would save some effort, but validations are important
|
||||||
|
destroyed_articles_count += 1
|
||||||
|
rescue => error # recover if article.destroy fails and continue with next article
|
||||||
|
failed_articles_count += 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if destroyed_articles_count>0 # note that 1 successful article.destroy is enough to destroy selection
|
||||||
|
stock_article_selection.destroy
|
||||||
|
flash[:notice] = "#{destroyed_articles_count} gewählte Artikel sind nun gelöscht."
|
||||||
|
flash[:error] = "#{failed_articles_count} Artikel konnten nicht gelöscht werden." unless 0==failed_articles_count
|
||||||
|
else
|
||||||
|
flash[:error] = "Löschvorgang fehlgeschlagen. Es wurden keine Artikel gelöscht."
|
||||||
|
end
|
||||||
|
|
||||||
|
redirect_to stock_articles_path
|
||||||
|
end
|
||||||
|
end
|
|
@ -142,7 +142,7 @@ module ApplicationHelper
|
||||||
# offers a link for writing message to user
|
# offers a link for writing message to user
|
||||||
# checks for nil (useful for relations)
|
# checks for nil (useful for relations)
|
||||||
def link_to_user_message_if_valid(user)
|
def link_to_user_message_if_valid(user)
|
||||||
user.nil? ? '??' : ( link_to user.nick, user_message_path(user), :title => 'Nachricht schreiben' )
|
user.nil? ? '??' : ( link_to user.nick, new_message_path(:message => {:mail_to => user.id}), :title => 'Nachricht schreiben' )
|
||||||
end
|
end
|
||||||
|
|
||||||
def bootstrap_flash
|
def bootstrap_flash
|
||||||
|
|
2
app/helpers/stock_article_selections_helper.rb
Normal file
2
app/helpers/stock_article_selections_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
module StockArticleSelectionsHelper
|
||||||
|
end
|
|
@ -1,7 +1,18 @@
|
||||||
|
# encoding: utf-8
|
||||||
module StockitHelper
|
module StockitHelper
|
||||||
def stock_article_classes(article)
|
def stock_article_classes(article)
|
||||||
class_names = []
|
class_names = []
|
||||||
class_names << "unavailable" if article.quantity_available <= 0
|
class_names << "unavailable" if article.quantity_available <= 0
|
||||||
class_names.join(" ")
|
class_names.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def stock_article_delete_checkbox(article)
|
||||||
|
if article.quantity_available <= 0
|
||||||
|
check_box_tag "stock_article_selection[stock_article_ids][]", article.id, false,
|
||||||
|
{ :id => "checkbox_#{article.id}", :title => 'Zum löschen markieren' }
|
||||||
|
else
|
||||||
|
check_box_tag 'checkall', '1', false,
|
||||||
|
{ :disabled => true, :title => 'Verfügbare Artikel können nicht gelöscht werden.', :class => 'unavailable' }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
24
app/models/stock_article_selection.rb
Normal file
24
app/models/stock_article_selection.rb
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
class StockArticleSelection < ActiveRecord::Base
|
||||||
|
|
||||||
|
# Associations
|
||||||
|
has_and_belongs_to_many :stock_articles
|
||||||
|
belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id'
|
||||||
|
belongs_to :finished_by, :class_name => 'User', :foreign_key => 'finished_by_user_id'
|
||||||
|
|
||||||
|
# Validations
|
||||||
|
validate :include_stock_articles
|
||||||
|
|
||||||
|
def all_articles
|
||||||
|
all_articles = stock_article_ids
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def include_stock_articles
|
||||||
|
errors.add(:stock_articles, "Es muss mindestens ein Lagerartikel ausgewählt sein.") if stock_articles.empty?
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
end
|
|
@ -2,7 +2,7 @@
|
||||||
- content_for :javascript do
|
- content_for :javascript do
|
||||||
:javascript
|
:javascript
|
||||||
$(function() {
|
$(function() {
|
||||||
$('tr.unavailable').hide();
|
$('tr.unavailable,input.unavailable').hide();
|
||||||
})
|
})
|
||||||
|
|
||||||
.well.well-small
|
.well.well-small
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
Ansichtsoptionen
|
Ansichtsoptionen
|
||||||
%span.caret
|
%span.caret
|
||||||
%ul.dropdown-menu
|
%ul.dropdown-menu
|
||||||
%li= link_to "Nicht verfügbare Artikel zeigen/verstecken", "#", 'data-toggle-this' => 'tr.unavailable', tabindex: -1
|
%li= link_to "Nicht verfügbare Artikel zeigen/verstecken", "#", 'data-toggle-this' => 'tr.unavailable,input.unavailable', tabindex: -1
|
||||||
|
|
||||||
.btn-group
|
.btn-group
|
||||||
= link_to "Neuen Lagerartikel anlegen", new_stock_article_path, class: 'btn btn-primary'
|
= link_to "Neuen Lagerartikel anlegen", new_stock_article_path, class: 'btn btn-primary'
|
||||||
|
@ -20,6 +20,7 @@
|
||||||
class: 'btn'
|
class: 'btn'
|
||||||
= link_to "Inventur anlegen", new_stock_taking_path, class: 'btn'
|
= link_to "Inventur anlegen", new_stock_taking_path, class: 'btn'
|
||||||
= link_to "Inventurübersicht", stock_takings_path, class: 'btn'
|
= link_to "Inventurübersicht", stock_takings_path, class: 'btn'
|
||||||
|
= link_to 'Löschvorschläge', stock_article_selections_path, class: 'btn'
|
||||||
|
|
||||||
.btn-group
|
.btn-group
|
||||||
= link_to '#', data: {toggle: 'dropdown'}, class: 'btn dropdown-toggle' do
|
= link_to '#', data: {toggle: 'dropdown'}, class: 'btn dropdown-toggle' do
|
||||||
|
@ -29,10 +30,15 @@
|
||||||
- Supplier.all.each do |supplier|
|
- Supplier.all.each do |supplier|
|
||||||
%li= link_to supplier.name, new_supplier_delivery_path(supplier), tabindex: -1
|
%li= link_to supplier.name, new_supplier_delivery_path(supplier), tabindex: -1
|
||||||
|
|
||||||
|
= form_for @stock_article_selection do |form|
|
||||||
|
- if @stock_article_selection.errors.has_key?(:stock_articles)
|
||||||
|
.alert.alert-error
|
||||||
|
= @stock_article_selection.errors.get(:stock_articles).join(" ")
|
||||||
%table.table.table-hover#articles
|
%table.table.table-hover#articles
|
||||||
%thead
|
%thead
|
||||||
%tr
|
%tr
|
||||||
|
%th= check_box_tag 'checkall', '1', false,
|
||||||
|
{ 'data-check-all' => 'table#articles tr.unavailable', :title => 'Alle löschbaren Artikel', :class => 'unavailable' }
|
||||||
%th Artikel
|
%th Artikel
|
||||||
%th im Lager
|
%th im Lager
|
||||||
%th davon bestellt
|
%th davon bestellt
|
||||||
|
@ -46,6 +52,7 @@
|
||||||
%tbody
|
%tbody
|
||||||
- for article in @stock_articles
|
- for article in @stock_articles
|
||||||
%tr{:class => stock_article_classes(article)}
|
%tr{:class => stock_article_classes(article)}
|
||||||
|
%td= stock_article_delete_checkbox(article)
|
||||||
%td=h article.name
|
%td=h article.name
|
||||||
%td= article.quantity
|
%td= article.quantity
|
||||||
%td= article.quantity - article.quantity_available
|
%td= article.quantity - article.quantity_available
|
||||||
|
@ -59,6 +66,7 @@
|
||||||
= link_to "Bearbeiten", edit_stock_article_path(article), class: 'btn btn-mini'
|
= link_to "Bearbeiten", edit_stock_article_path(article), class: 'btn btn-mini'
|
||||||
= link_to "Löschen", article, :method => :delete, :confirm => "Bist Du sicher?",
|
= link_to "Löschen", article, :method => :delete, :confirm => "Bist Du sicher?",
|
||||||
class: 'btn btn-mini btn-danger'
|
class: 'btn btn-mini btn-danger'
|
||||||
|
%p= submit_tag "Artikel zum Löschen vormerken", { :class => 'unavailable btn' }
|
||||||
%p
|
%p
|
||||||
Aktueller Lagerwert:
|
Aktueller Lagerwert:
|
||||||
= number_to_currency StockArticle.stock_value
|
= number_to_currency StockArticle.stock_value
|
||||||
|
|
19
app/views/stockit_selections/_overview.html.haml
Normal file
19
app/views/stockit_selections/_overview.html.haml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
|
||||||
|
%table.table.table-hover
|
||||||
|
%tr
|
||||||
|
%th Artikel
|
||||||
|
%th Erstellt am
|
||||||
|
%th Erstellt von
|
||||||
|
%th Optionen
|
||||||
|
|
||||||
|
- stock_article_selections.each do |stock_article_selection|
|
||||||
|
%tr
|
||||||
|
%td=h truncate stock_article_selection.stock_articles.map{ |article| article.name}.join(', ')
|
||||||
|
%td=h stock_article_selection.created_at
|
||||||
|
%td=h link_to_user_message_if_valid stock_article_selection.created_by
|
||||||
|
%td
|
||||||
|
= link_to 'Anzeigen', stock_article_selection, class: 'btn btn-small'
|
||||||
|
= link_to "Artikel löschen", articles_stock_article_selection_path(stock_article_selection), :method => :delete,
|
||||||
|
:confirm => 'Diesen Löschvorschlag wirklich ausführen und markierte Artikel löschen?', class: 'btn btn-small btn-danger'
|
||||||
|
= link_to "Verwerfen", stock_article_selection, :method => :delete,
|
||||||
|
:confirm => 'Diesen Löschvorschlag wirklich verwerfen?', class: 'btn btn-small'
|
7
app/views/stockit_selections/index.html.haml
Normal file
7
app/views/stockit_selections/index.html.haml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
- title "Löschvorschläge für Lagerartikel"
|
||||||
|
- if @stock_article_selections.empty?
|
||||||
|
%p Es gibt keine ausstehenden Löschvorschläge.
|
||||||
|
%ul
|
||||||
|
%li= link_to "Löschvorschlag erstellen", stock_articles_path
|
||||||
|
- else
|
||||||
|
= render :partial => 'overview', :locals => {:stock_article_selections => @stock_article_selections}
|
18
app/views/stockit_selections/show.html.haml
Normal file
18
app/views/stockit_selections/show.html.haml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
- title "Löschvorschlag für #{@stock_article_selection.stock_articles.count} Lagerartikel"
|
||||||
|
|
||||||
|
%dl
|
||||||
|
%dt Löschvorschlag vom:
|
||||||
|
%dd=h @stock_article_selection.created_at
|
||||||
|
%dt Erstellt durch:
|
||||||
|
%dd=h link_to_user_message_if_valid(@stock_article_selection.created_by)
|
||||||
|
%dt Zu löschende Artikel
|
||||||
|
- for article in @stock_article_selection.stock_articles
|
||||||
|
%dd=h article.name
|
||||||
|
|
||||||
|
|
||||||
|
%p
|
||||||
|
= link_to 'Artikel löschen', articles_stock_article_selection_path(@stock_article_selection), :method => :delete,
|
||||||
|
:confirm => 'Diesen Löschvorschlag wirklich ausführen und markierte Artikel löschen?', class: 'btn btn-danger'
|
||||||
|
= link_to 'Verwerfen', @stock_article_selection, :method => :delete,
|
||||||
|
:confirm => 'Diesen Löschvorschlag wirklich verwerfen?', class: 'btn'
|
||||||
|
= link_to 'Alle Löschvorschläge zeigen', stock_article_selections_path, class: 'btn'
|
|
@ -90,6 +90,14 @@ Foodsoft::Application.routes.draw do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
resources :stock_article_selections, :controller => 'stockit_selections',
|
||||||
|
:only => [ :create, :show, :index, :destroy ], :path => "/stock_articles/selections" do
|
||||||
|
member do
|
||||||
|
delete 'articles'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
resources :stock_articles, :to => 'stockit' do
|
resources :stock_articles, :to => 'stockit' do
|
||||||
collection do
|
collection do
|
||||||
get :articles_search
|
get :articles_search
|
||||||
|
|
18
db/migrate/20130112121840_create_stock_article_selections.rb
Normal file
18
db/migrate/20130112121840_create_stock_article_selections.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
class CreateStockArticleSelections < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
create_table :stock_article_selections do |t|
|
||||||
|
t.integer :created_by_user_id
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table :stock_article_selections_stock_articles, :id => false do |t|
|
||||||
|
t.integer :stock_article_id
|
||||||
|
t.integer :stock_article_selection_id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
drop_table :stock_article_selections
|
||||||
|
drop_table :stock_article_selections_stock_articles
|
||||||
|
end
|
||||||
|
end
|
13
db/schema.rb
13
db/schema.rb
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20121230142516) do
|
ActiveRecord::Schema.define(:version => 20130112121840) do
|
||||||
|
|
||||||
create_table "article_categories", :force => true do |t|
|
create_table "article_categories", :force => true do |t|
|
||||||
t.string "name", :default => "", :null => false
|
t.string "name", :default => "", :null => false
|
||||||
|
@ -268,6 +268,17 @@ ActiveRecord::Schema.define(:version => 20121230142516) do
|
||||||
add_index "pages", ["permalink"], :name => "index_pages_on_permalink"
|
add_index "pages", ["permalink"], :name => "index_pages_on_permalink"
|
||||||
add_index "pages", ["title"], :name => "index_pages_on_title"
|
add_index "pages", ["title"], :name => "index_pages_on_title"
|
||||||
|
|
||||||
|
create_table "stock_article_selections", :force => true do |t|
|
||||||
|
t.integer "created_by_user_id"
|
||||||
|
t.datetime "created_at", :null => false
|
||||||
|
t.datetime "updated_at", :null => false
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "stock_article_selections_stock_articles", :id => false, :force => true do |t|
|
||||||
|
t.integer "stock_article_id"
|
||||||
|
t.integer "stock_article_selection_id"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "stock_changes", :force => true do |t|
|
create_table "stock_changes", :force => true do |t|
|
||||||
t.integer "delivery_id"
|
t.integer "delivery_id"
|
||||||
t.integer "order_id"
|
t.integer "order_id"
|
||||||
|
|
Loading…
Reference in a new issue