Introduced StockChange. Implemented first part of stockit-logic with updating article's quantity.
This commit is contained in:
parent
7ff0467b16
commit
b38025869a
27 changed files with 233 additions and 123 deletions
|
@ -2,8 +2,6 @@ class DeliveriesController < ApplicationController
|
|||
|
||||
before_filter :find_supplier
|
||||
|
||||
# GET /deliveries
|
||||
# GET /deliveries.xml
|
||||
def index
|
||||
@deliveries = @supplier.deliveries.find(:all)
|
||||
|
||||
|
@ -13,8 +11,6 @@ class DeliveriesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# GET /deliveries/1
|
||||
# GET /deliveries/1.xml
|
||||
def show
|
||||
@delivery = Delivery.find(params[:id])
|
||||
|
||||
|
@ -24,24 +20,19 @@ class DeliveriesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# GET /deliveries/new
|
||||
# GET /deliveries/new.xml
|
||||
def new
|
||||
@delivery = @supplier.deliveries.build
|
||||
|
||||
3.times { @delivery.stock_changes.build }
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.xml { render :xml => @delivery }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /deliveries/1/edit
|
||||
def edit
|
||||
@delivery = Delivery.find(params[:id])
|
||||
end
|
||||
|
||||
# POST /deliveries
|
||||
# POST /deliveries.xml
|
||||
def create
|
||||
@delivery = Delivery.new(params[:delivery])
|
||||
|
||||
|
@ -74,8 +65,6 @@ class DeliveriesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# DELETE /deliveries/1
|
||||
# DELETE /deliveries/1.xml
|
||||
def destroy
|
||||
@delivery = Delivery.find(params[:id])
|
||||
@delivery.destroy
|
||||
|
@ -86,6 +75,15 @@ class DeliveriesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def drop_stock_change
|
||||
stock_change = StockChange.find(params[:stock_change_id])
|
||||
stock_change.destroy
|
||||
|
||||
render :update do |page|
|
||||
page.visual_effect(:DropOut, "stock_change_#{stock_change.id}")
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def find_supplier
|
||||
|
|
12
app/helpers/deliveries_helper.rb
Normal file
12
app/helpers/deliveries_helper.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
module DeliveriesHelper
|
||||
def articles_for_select(supplier)
|
||||
supplier.articles.find(:all, :limit => 10).collect { |a| [truncate(a.name), a.id] }
|
||||
end
|
||||
|
||||
def add_article_link
|
||||
link_to_function "Artikel hinzufügen", nil, { :accesskey => 'n', :title => "ALT + SHIFT + N" } do |page|
|
||||
page.insert_html :bottom, :stock_changes, :partial => 'stock_change', :object => StockChange.new
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
# == Schema Information
|
||||
# Schema version: 20090113111624
|
||||
# Schema version: 20090115232435
|
||||
#
|
||||
# Table name: articles
|
||||
#
|
||||
|
@ -21,32 +21,9 @@
|
|||
# order_number :string(255)
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# quantity :decimal(6, 2) default(0.0)
|
||||
#
|
||||
|
||||
# == Schema Information
|
||||
# Schema version: 20090102171850
|
||||
#
|
||||
# Table name: articles
|
||||
#
|
||||
# id :integer(4) not null, primary key
|
||||
# name :string(255) default(""), not null
|
||||
# supplier_id :integer(4) default(0), not null
|
||||
# article_category_id :integer(4) default(0), not null
|
||||
# unit :string(255) default(""), not null
|
||||
# note :string(255)
|
||||
# availability :boolean(1) default(TRUE), not null
|
||||
# manufacturer :string(255)
|
||||
# origin :string(255)
|
||||
# shared_updated_on :datetime
|
||||
# net_price :decimal(8, 2)
|
||||
# gross_price :decimal(8, 2) default(0.0), not null
|
||||
# tax :float
|
||||
# deposit :decimal(8, 2) default(0.0)
|
||||
# unit_quantity :integer(4) default(1), not null
|
||||
# order_number :string(255)
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
#
|
||||
class Article < ActiveRecord::Base
|
||||
belongs_to :supplier
|
||||
belongs_to :article_category
|
||||
|
@ -230,4 +207,9 @@ class Article < ActiveRecord::Base
|
|||
# it could be so easy ... but that doesn't work for empty category-ids...
|
||||
# articles.group_by {|a| a.article_category}.sort {|a, b| a[0].name <=> b[0].name}
|
||||
end
|
||||
|
||||
def update_quantity(amount)
|
||||
update_attribute :quantity, quantity + amount
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -12,6 +12,14 @@
|
|||
class Delivery < ActiveRecord::Base
|
||||
|
||||
belongs_to :supplier
|
||||
has_many :stock_changes
|
||||
|
||||
validates_presence_of :supplier_id
|
||||
|
||||
def stock_change_attributes=(stock_change_attributes)
|
||||
for attributes in stock_change_attributes
|
||||
stock_changes.build(attributes) unless attributes[:quantity] == 0.0 or attributes[:quantity].blank?
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -21,10 +21,10 @@ class Mailer < ActionMailer::Base
|
|||
from (message.system_message? ? "FoodSoft <#{APP_CONFIG[:email_sender]}>" : "#{message.sender.nick} <#{message.sender.email}>")
|
||||
body :body => message.body, :sender => (message.system_message? ? 'Foodsoft' : message.sender.nick),
|
||||
:recipients => message.recipients,
|
||||
:reply => url_for(:host => request.host, reply_message_path(message),
|
||||
:profile => url_for(:host => request.host, my_profile_path),
|
||||
:link => url_for(:host => request.host, message_path(message),
|
||||
:foodsoftUrl => url_for(:host => request.host, :controller => "index")
|
||||
:reply => url_for(:host => request.host, :controller => "messages", :action => "reply", :id => message),
|
||||
:profile => url_for(:host => request.host, :controller => "home", :action => "profile"),
|
||||
:link => url_for(:host => request.host, :controller => "messages", :action => "show", :id => message),
|
||||
:foodsoftUrl => url_for(:host => request.host, :controller => "/")
|
||||
end
|
||||
|
||||
# Sends an invite email.
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
# == Schema Information
|
||||
# Schema version: 20090115123421
|
||||
# Schema version: 20090115232435
|
||||
#
|
||||
# Table name: messages
|
||||
#
|
||||
# id :integer(4) not null, primary key
|
||||
# sender_id :integer(4)
|
||||
# recipients_ids :text default(""), not null
|
||||
# recipients_ids :text
|
||||
# subject :string(255) not null
|
||||
# body :text
|
||||
# email_state :integer(4) default(0), not null
|
||||
|
|
34
app/models/stock_change.rb
Normal file
34
app/models/stock_change.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
# == Schema Information
|
||||
# Schema version: 20090115232435
|
||||
#
|
||||
# Table name: stock_changes
|
||||
#
|
||||
# id :integer(4) not null, primary key
|
||||
# delivery_id :integer(4)
|
||||
# order_id :integer(4)
|
||||
# article_id :integer(4)
|
||||
# quantity :decimal(6, 2) default(0.0)
|
||||
# created_at :datetime
|
||||
#
|
||||
|
||||
class StockChange < ActiveRecord::Base
|
||||
belongs_to :delivery
|
||||
belongs_to :order
|
||||
belongs_to :article
|
||||
|
||||
validates_presence_of :article_id, :quantity
|
||||
validates_numericality_of :quantity
|
||||
|
||||
after_save :update_article_quantity
|
||||
after_destroy :remove_added_quantity
|
||||
|
||||
protected
|
||||
|
||||
def update_article_quantity
|
||||
article.update_quantity(quantity)
|
||||
end
|
||||
|
||||
def remove_added_quantity
|
||||
article.update_quantity(quantity * -1)
|
||||
end
|
||||
end
|
16
app/views/deliveries/_form.html.haml
Normal file
16
app/views/deliveries/_form.html.haml
Normal file
|
@ -0,0 +1,16 @@
|
|||
- form_for([@supplier,@delivery]) do |f|
|
||||
= f.error_messages
|
||||
= f.hidden_field :supplier_id
|
||||
%p
|
||||
%b= f.label :delivered_on
|
||||
= f.date_select :delivered_on
|
||||
|
||||
%h2 Artikel
|
||||
#stock_changes
|
||||
= yield
|
||||
%br/
|
||||
= add_article_link
|
||||
%p
|
||||
= f.submit "Speichern"
|
||||
|
||||
= link_to 'Zurück', supplier_deliveries_path(@supplier)
|
6
app/views/deliveries/_stock_change.html.haml
Normal file
6
app/views/deliveries/_stock_change.html.haml
Normal file
|
@ -0,0 +1,6 @@
|
|||
%p
|
||||
- fields_for "delivery[stock_change_attributes][]", stock_change do |form|
|
||||
= form.select :article_id, articles_for_select(@supplier), :prompt => " -- Artikel auswählen -- "
|
||||
Menge
|
||||
= form.text_field :quantity, :size => 5, :autocomplete => 'off'
|
||||
= link_to_function "Löschen", "$(this).up('p').remove()"
|
|
@ -1,17 +0,0 @@
|
|||
<h1>Editing delivery</h1>
|
||||
|
||||
<% form_for([@supplier,@delivery]) do |f| %>
|
||||
<%= f.error_messages %>
|
||||
<%= f.hidden_field :supplier_id %>
|
||||
|
||||
<p>
|
||||
<%= f.label :delivered_on %><br />
|
||||
<%= f.date_select :delivered_on %>
|
||||
</p>
|
||||
<p>
|
||||
<%= f.submit "Update" %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<%= link_to 'Show', [@supplier,@delivery] %> |
|
||||
<%= link_to 'Back', supplier_deliveries_path(@supplier) %>
|
16
app/views/deliveries/edit.html.haml
Normal file
16
app/views/deliveries/edit.html.haml
Normal file
|
@ -0,0 +1,16 @@
|
|||
- title "Lieferung bearbeiten"
|
||||
|
||||
%p
|
||||
%b Lieferant:
|
||||
= @supplier.name
|
||||
|
||||
- render :layout => 'form' do
|
||||
%table{:style => "width:40em"}
|
||||
- for stock_change in @delivery.stock_changes
|
||||
%tr[stock_change]
|
||||
%td= stock_change.article.name
|
||||
%td= stock_change.quantity
|
||||
%td
|
||||
= link_to_remote "Artikel entfernen", |
|
||||
:url => drop_stock_change_supplier_delivery_path(@supplier, @delivery, :stock_change_id => stock_change), |
|
||||
:method => :post |
|
|
@ -1,22 +0,0 @@
|
|||
<% title "#{@supplier.name}/deliveries" %>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>Delivered on</th>
|
||||
<th>Invoice</th>
|
||||
</tr>
|
||||
|
||||
<% for delivery in @deliveries %>
|
||||
<tr>
|
||||
<td><%=h delivery.delivered_on %></td>
|
||||
<td><%=h "invoice ..." %></td>
|
||||
<td><%= link_to 'Show', [@supplier, delivery] %></td>
|
||||
<td><%= link_to 'Edit', edit_supplier_delivery_path(@supplier,delivery) %></td>
|
||||
<td><%= link_to 'Destroy', [@supplier,delivery], :confirm => 'Are you sure?', :method => :delete %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<br />
|
||||
|
||||
<%= link_to 'New delivery', new_supplier_delivery_path(@supplier) %>
|
16
app/views/deliveries/index.html.haml
Normal file
16
app/views/deliveries/index.html.haml
Normal file
|
@ -0,0 +1,16 @@
|
|||
- title "#{@supplier.name}/deliveries"
|
||||
|
||||
%table{:style => "width:50em"}
|
||||
%tr
|
||||
%th Delivered on
|
||||
%th Invoice
|
||||
- for delivery in @deliveries
|
||||
%tr
|
||||
%td=h delivery.delivered_on
|
||||
%td=h "invoice ..."
|
||||
%td= link_to 'Show', [@supplier, delivery]
|
||||
%td= link_to 'Edit', edit_supplier_delivery_path(@supplier,delivery)
|
||||
%td= link_to 'Destroy', [@supplier,delivery], :confirm => 'Are you sure?', :method => :delete
|
||||
|
||||
%br/
|
||||
= link_to 'New delivery', new_supplier_delivery_path(@supplier)
|
|
@ -1,16 +0,0 @@
|
|||
<h1>New delivery</h1>
|
||||
|
||||
<% form_for([@supplier,@delivery]) do |f| %>
|
||||
<%= f.error_messages %>
|
||||
<%= f.hidden_field :supplier_id %>
|
||||
|
||||
<p>
|
||||
<%= f.label :delivered_on %><br />
|
||||
<%= f.date_select :delivered_on %>
|
||||
</p>
|
||||
<p>
|
||||
<%= f.submit "Create" %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<%= link_to 'Back', supplier_deliveries_path(@supplier) %>
|
4
app/views/deliveries/new.html.haml
Normal file
4
app/views/deliveries/new.html.haml
Normal file
|
@ -0,0 +1,4 @@
|
|||
- title "Neue Lieferung von #{@supplier.name}"
|
||||
|
||||
- render :layout => 'form' do
|
||||
= render :partial => 'stock_change', :collection => @delivery.stock_changes
|
|
@ -1,13 +0,0 @@
|
|||
<p>
|
||||
<b>Supplier:</b>
|
||||
<%=h @delivery.supplier_id %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Delivered on:</b>
|
||||
<%=h @delivery.delivered_on %>
|
||||
</p>
|
||||
|
||||
|
||||
<%= link_to 'Edit', edit_supplier_delivery_path(@supplier,@delivery) %> |
|
||||
<%= link_to 'Back', supplier_deliveries_path(@supplier) %>
|
25
app/views/deliveries/show.html.haml
Normal file
25
app/views/deliveries/show.html.haml
Normal file
|
@ -0,0 +1,25 @@
|
|||
- title "Lieferung anzeigen"
|
||||
|
||||
%p
|
||||
%b Lieferant:
|
||||
=h @delivery.supplier.name
|
||||
%p
|
||||
%b Delivered on:
|
||||
=h @delivery.delivered_on
|
||||
|
||||
%h2 Artikel
|
||||
%table.list{:style => "width:30em"}
|
||||
%tr
|
||||
%th Artikel
|
||||
%th Einheit
|
||||
%th Menge
|
||||
- for stock_change in @delivery.stock_changes.find :all, :include => :article
|
||||
%tr
|
||||
%td= stock_change.article.name
|
||||
%td= stock_change.article.unit
|
||||
%td= stock_change.quantity
|
||||
|
||||
%br/
|
||||
= link_to 'Edit', edit_supplier_delivery_path(@supplier,@delivery)
|
||||
|
|
||||
= link_to 'Back', supplier_deliveries_path(@supplier)
|
|
@ -23,7 +23,7 @@
|
|||
{ :name => "Manage orders", :url => "/orders", :access? => (u.role_orders?) }
|
||||
]
|
||||
},
|
||||
{ :name => "Articles", :url => "/articles", :active => ["articles", "suppliers"],
|
||||
{ :name => "Articles", :url => "/articles", :active => ["articles", "suppliers", "deliveries"],
|
||||
:access? => (u.role_article_meta? || u.role_suppliers?),
|
||||
:subnav => [
|
||||
{ :name => "Show articles", :url => "/articles/list" },
|
||||
|
|
|
@ -3,9 +3,8 @@
|
|||
%tbody
|
||||
- for message in @messages
|
||||
%tr{:class => cycle('even','odd', :name => 'messages')}
|
||||
%td
|
||||
%b= h(message.sender_name)
|
||||
%td= format_subject(message, subject_length)
|
||||
%td= h(message.sender_name)
|
||||
%td= format_time(message.created_at)
|
||||
%td= link_to('Antworten', reply_message_path(message))
|
||||
|
|
@ -17,9 +17,9 @@ ActionController::Routing::Routes.draw do |map|
|
|||
finance.connect 'balancing/:action/:id', :controller => 'balancing'
|
||||
end
|
||||
|
||||
map.resources :suppliers,
|
||||
:has_many => [:deliveries],
|
||||
:collection => { :shared_suppliers => :get }
|
||||
map.resources :suppliers, :collection => { :shared_suppliers => :get } do |suppliers|
|
||||
suppliers.resources :deliveries, :member => { :drop_stock_change => :post }
|
||||
end
|
||||
|
||||
map.root :controller => 'home', :action => 'index'
|
||||
|
||||
|
|
17
db/migrate/20090115232435_create_stock_changes.rb
Normal file
17
db/migrate/20090115232435_create_stock_changes.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
class CreateStockChanges < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :stock_changes do |t|
|
||||
t.references :delivery
|
||||
t.references :order
|
||||
t.references :article
|
||||
t.decimal :quantity, :precision => 6, :scale => 2, :default => 0.0
|
||||
t.datetime :created_at
|
||||
end
|
||||
|
||||
add_column :articles, :quantity, :decimal, :precision => 6, :scale => 2, :default => 0.0
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :stock_changes
|
||||
end
|
||||
end
|
13
db/schema.rb
13
db/schema.rb
|
@ -9,7 +9,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20090114101610) do
|
||||
ActiveRecord::Schema.define(:version => 20090115232435) do
|
||||
|
||||
create_table "article_categories", :force => true do |t|
|
||||
t.string "name", :default => "", :null => false
|
||||
|
@ -36,6 +36,7 @@ ActiveRecord::Schema.define(:version => 20090114101610) do
|
|||
t.string "order_number"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.decimal "quantity", :precision => 6, :scale => 2, :default => 0.0
|
||||
end
|
||||
|
||||
add_index "articles", ["name", "supplier_id"], :name => "index_articles_on_name_and_supplier_id"
|
||||
|
@ -184,7 +185,7 @@ ActiveRecord::Schema.define(:version => 20090114101610) do
|
|||
|
||||
create_table "messages", :force => true do |t|
|
||||
t.integer "sender_id"
|
||||
t.text "recipients_ids", :null => false
|
||||
t.text "recipients_ids"
|
||||
t.string "subject", :null => false
|
||||
t.text "body"
|
||||
t.integer "email_state", :default => 0, :null => false
|
||||
|
@ -241,6 +242,14 @@ ActiveRecord::Schema.define(:version => 20090114101610) do
|
|||
add_index "orders", ["finished"], :name => "index_orders_on_finished"
|
||||
add_index "orders", ["starts"], :name => "index_orders_on_starts"
|
||||
|
||||
create_table "stock_changes", :force => true do |t|
|
||||
t.integer "delivery_id"
|
||||
t.integer "order_id"
|
||||
t.integer "article_id"
|
||||
t.decimal "quantity", :precision => 6, :scale => 2, :default => 0.0
|
||||
t.datetime "created_at"
|
||||
end
|
||||
|
||||
create_table "suppliers", :force => true do |t|
|
||||
t.string "name", :default => "", :null => false
|
||||
t.string "address", :default => "", :null => false
|
||||
|
|
2
test/fixtures/articles.yml
vendored
2
test/fixtures/articles.yml
vendored
|
@ -1,5 +1,5 @@
|
|||
# == Schema Information
|
||||
# Schema version: 20090115123421
|
||||
# Schema version: 20090115232435
|
||||
#
|
||||
# Table name: articles
|
||||
#
|
||||
|
|
4
test/fixtures/messages.yml
vendored
4
test/fixtures/messages.yml
vendored
|
@ -1,11 +1,11 @@
|
|||
# == Schema Information
|
||||
# Schema version: 20090115123421
|
||||
# Schema version: 20090115232435
|
||||
#
|
||||
# Table name: messages
|
||||
#
|
||||
# id :integer(4) not null, primary key
|
||||
# sender_id :integer(4)
|
||||
# recipients_ids :text default(""), not null
|
||||
# recipients_ids :text
|
||||
# subject :string(255) not null
|
||||
# body :text
|
||||
# email_state :integer(4) default(0), not null
|
||||
|
|
28
test/fixtures/stock_changes.yml
vendored
Normal file
28
test/fixtures/stock_changes.yml
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
# == Schema Information
|
||||
# Schema version: 20090115232435
|
||||
#
|
||||
# Table name: stock_changes
|
||||
#
|
||||
# id :integer(4) not null, primary key
|
||||
# delivery_id :integer(4)
|
||||
# order_id :integer(4)
|
||||
# article_id :integer(4)
|
||||
# quantity :decimal(6, 2) default(0.0)
|
||||
# created_at :datetime
|
||||
#
|
||||
|
||||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
|
||||
one:
|
||||
delivery:
|
||||
order:
|
||||
article:
|
||||
quantity: 1
|
||||
created_at: 2009-01-16 00:24:35
|
||||
|
||||
two:
|
||||
delivery:
|
||||
order:
|
||||
article:
|
||||
quantity: 1
|
||||
created_at: 2009-01-16 00:24:35
|
2
test/fixtures/suppliers.yml
vendored
2
test/fixtures/suppliers.yml
vendored
|
@ -1,5 +1,5 @@
|
|||
# == Schema Information
|
||||
# Schema version: 20090115123421
|
||||
# Schema version: 20090115232435
|
||||
#
|
||||
# Table name: suppliers
|
||||
#
|
||||
|
|
8
test/unit/stock_change_test.rb
Normal file
8
test/unit/stock_change_test.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
class StockChangeTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue