Refactoring of delivery-workflow. Added ability to add stock_changes after creating a delivery.

This commit is contained in:
Benjamin Meichsner 2009-05-17 16:11:39 +02:00
parent 43fc7b06f8
commit a8e35bd421
7 changed files with 66 additions and 101 deletions

View file

@ -22,7 +22,7 @@ class DeliveriesController < ApplicationController
def new
@delivery = @supplier.deliveries.build
@supplier.stock_articles.each { |article| @delivery.stock_changes.build(:stock_article => article) }
@delivery.stock_changes.build(:stock_article => @supplier.stock_articles.first)
respond_to do |format|
format.html # new.html.erb
@ -79,8 +79,8 @@ class DeliveriesController < ApplicationController
render :update do |page|
if article.save
logger.debug "new StockArticle: #{article.id}"
page.insert_html :top, 'stock_changes', :partial => 'stock_change',
:locals => {:stock_change => article.stock_changes.build}
page.insert_html :bottom, 'stock_changes', :partial => 'stock_change',
:locals => {:stock_change => article.stock_changes.build, :supplier => @supplier}
page.replace_html 'new_stock_article', :partial => 'stock_article_form',
:locals => {:stock_article => @supplier.stock_articles.build}
@ -91,12 +91,11 @@ class DeliveriesController < ApplicationController
end
end
def drop_stock_change
stock_change = StockChange.find(params[:stock_change_id])
stock_change.destroy
def add_stock_change
render :update do |page|
page.visual_effect :DropOut, "stock_change_#{stock_change.id}"
page.insert_html :bottom, 'stock_changes', :partial => 'stock_change',
:locals => {:stock_change => StockChange.new, :supplier => @supplier}
end
end
@ -109,13 +108,4 @@ class DeliveriesController < ApplicationController
render :partial => 'stock_article_form', :locals => {:stock_article => stock_article}
end
def in_place_edit_for_stock_quantity
stock_change = StockChange.find(params[:editorId])
if stock_change.update_attributes(:quantity => params[:value])
render :inline => params[:value]
else
render :inline => "Ein Fehler ist aufgetreten."
end
end
end

View file

@ -9,4 +9,8 @@ module DeliveriesHelper
end
end
def stock_articles_for_select(supplier)
supplier.stock_articles.collect {|a| ["#{a.name} (#{number_to_currency a.price}/#{a.unit})", a.id] }
end
end

View file

@ -19,7 +19,9 @@ class Delivery < ActiveRecord::Base
validates_presence_of :supplier_id
def stock_change_attributes=(stock_change_attributes)
accepts_nested_attributes_for :stock_changes, :allow_destroy => :true
def new_stock_changes=(stock_change_attributes)
for attributes in stock_change_attributes
stock_changes.build(attributes) unless attributes[:quantity].to_i == 0
end

View file

@ -0,0 +1,48 @@
.left_column
- form_for([@supplier,@delivery]) do |f|
.box_title
%h2 Lieferung anlegen
.column_content
= f.error_messages
= f.hidden_field :supplier_id
%p
%b= f.label :delivered_on
= f.date_select :delivered_on
%h2 Lagerartikel des Lieferanten
#stock_changes
- f.fields_for :stock_changes do |stock_change_form|
%p
= stock_change_form.select :stock_article_id, stock_articles_for_select(@supplier)
Menge
= stock_change_form.text_field :quantity, :size => 5, :autocomplete => 'off'
Entfernen
= stock_change_form.check_box :_delete
%p
= remote_link_to "Lagerartikel hinzufügen", :url => {:action => 'add_stock_change', :supplier_id => @supplier.id}
%p
= f.submit "Lieferung speichern"
.right_column{:style => "width:35em;"}
.box_title
%h2 Neuen Lagerartikel anlegen
.column_content
%p
:javascript
function fillNewStockArticle(text, li) {
new Ajax.Updater('stock_article_form', '/deliveries/fill_new_stock_article_form', {
method: 'get',
parameters: {article_id: li.id}
});
}
Suche nach Artikeln aus dem
%i= @supplier.name
Katalog:
= text_field_with_auto_complete :article, :name, {}, |
{:url => {:controller => 'stockit', :action => 'auto_complete_for_article_name', :supplier_id => @supplier.id}, |
:after_update_element => 'fillNewStockArticle', :method => :get} |
%hr/
#stock_article_form
= render :partial => 'stock_article_form', :locals => {:stock_article => @supplier.stock_articles.build}
%p{:style => "clear:both"}
= link_to 'Zurück', supplier_deliveries_path(@supplier)

View file

@ -1,8 +1,6 @@
%p
- fields_for "delivery[stock_change_attributes][]", stock_change do |form|
= form.hidden_field :stock_article_id
- fields_for "delivery[new_stock_changes][]", stock_change do |form|
= form.select :stock_article_id, stock_articles_for_select(supplier)
Menge
= form.text_field :quantity, :size => 5, :autocomplete => 'off'
- article = stock_change.stock_article
%b= article.name
= "(#{number_to_currency(article.price)} / #{article.unit})"
= link_to_function "entfernen", "$(this).up('p').remove()"

View file

@ -1,41 +1,3 @@
- title "Lieferung bearbeiten"
%p
%b Lieferantin:
= @supplier.name
%p
%b Rechnungsbetrag:
= link_to_invoice(@delivery)
- form_for([@supplier,@delivery]) do |f|
= f.error_messages
= f.hidden_field :supplier_id
%p
%b Geliefert am:
= f.date_select :delivered_on
%h2 Artikel
%i Um die Mengen anzupassen einfach auf die Anzahl klicken.
#stock_changes
%table.list{:style => "width:40em"}
%tr
%th Name
%th Menge
%th
- for stock_change in @delivery.stock_changes
%tr[stock_change]
%td= stock_change.stock_article.name
%td
%span.click-me{:id => stock_change.id, :style => "width:5em"}= stock_change.quantity
= javascript_tag "new Ajax.InPlaceEditor('#{stock_change.id}', |
'/deliveries/in_place_edit_for_stock_quantity', |
{size: 5});" |
%td
= link_to_remote "Artikel entfernen", |
:url => drop_stock_change_supplier_delivery_path(@supplier, @delivery, :stock_change_id => stock_change), |
:method => :post |
%p
= f.submit "Speichern"
= link_to 'Zurück', supplier_deliveries_path(@supplier)
= render :partial => 'form'

View file

@ -1,42 +1,3 @@
- title "Neue Lieferung von #{@supplier.name}"
.left_column
- form_for([@supplier,@delivery]) do |f|
.box_title
%h2 Lieferung anlegen
.column_content
= f.error_messages
= f.hidden_field :supplier_id
%p
%b= f.label :delivered_on
= f.date_select :delivered_on
%h2 Lagerartikel des Lieferanten
#stock_changes
= render :partial => 'stock_change', :collection => @delivery.stock_changes
%p
= f.submit "Lieferung anlegen"
.right_column{:style => "width:35em;"}
.box_title
%h2 Neuen Lagerartikel anlegen
.column_content
%p
:javascript
function fillNewStockArticle(text, li) {
new Ajax.Updater('stock_article_form', '/deliveries/fill_new_stock_article_form', {
method: 'get',
parameters: {article_id: li.id}
});
}
Suche nach Artikeln aus dem
%i= @supplier.name
Katalog:
= text_field_with_auto_complete :article, :name, {}, |
{:url => {:controller => 'stockit', :action => 'auto_complete_for_article_name', :supplier_id => @supplier.id}, |
:after_update_element => 'fillNewStockArticle', :method => :get} |
%hr/
#stock_article_form
= render :partial => 'stock_article_form', :locals => {:stock_article => @supplier.stock_articles.build}
%p{:style => "clear:both"}
= link_to 'Zurück', supplier_deliveries_path(@supplier)
= render :partial => 'form'