Save and display creator of Order

This commit is contained in:
Julius 2012-11-12 14:24:49 +01:00
parent 69c4fc5817
commit c17ff281c3
8 changed files with 25 additions and 4 deletions

View file

@ -172,4 +172,4 @@ class OrdersController < ApplicationController
end end
redirect_to order redirect_to order
end end
end end

View file

@ -154,5 +154,11 @@ module ApplicationHelper
link_to h(address), "http://maps.google.de/?q=#{h(address)}", :title => "Show it on google maps", link_to h(address), "http://maps.google.de/?q=#{h(address)}", :title => "Show it on google maps",
:target => "_blank" :target => "_blank"
end end
# offers a link for writing message to user
# checks for nil (useful for relations)
def link_to_user_message_if_valid(user)
user.nil? ? '??' : ( link_to user.nick, user_message_path(user), :title => _('Nachricht schreiben') )
end
end end

View file

@ -11,13 +11,17 @@ class Order < ActiveRecord::Base
has_many :comments, :class_name => "OrderComment", :order => "created_at" has_many :comments, :class_name => "OrderComment", :order => "created_at"
has_many :stock_changes has_many :stock_changes
belongs_to :supplier belongs_to :supplier
belongs_to :updated_by, :class_name => "User", :foreign_key => "updated_by_user_id" belongs_to :updated_by, :class_name => 'User', :foreign_key => 'updated_by_user_id'
belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id'
# Validations # Validations
validates_presence_of :starts validates_presence_of :starts
validate :starts_before_ends, :include_articles validate :starts_before_ends, :include_articles
# Callbacks # Callbacks
before_create do |order|
order.created_by = User.current_user
end
after_update :update_price_of_group_orders after_update :update_price_of_group_orders
# Finders # Finders

View file

@ -11,6 +11,7 @@ class User < ActiveRecord::Base
has_many :tasks, :through => :assignments has_many :tasks, :through => :assignments
has_many :send_messages, :class_name => "Message", :foreign_key => "sender_id" has_many :send_messages, :class_name => "Message", :foreign_key => "sender_id"
has_many :pages, :foreign_key => 'updated_by' has_many :pages, :foreign_key => 'updated_by'
has_many :created_orders, :class_name => 'Order', :foreign_key => 'created_by_user_id', :dependent => :nullify
attr_accessor :password, :setting_attributes attr_accessor :password, :setting_attributes

View file

@ -10,6 +10,9 @@
%p %p
%b Lieferantin: %b Lieferantin:
=h @order.name =h @order.name
%p
%b Erstellt von:
=h link_to_user_message_if_valid(@order.created_by)
%p %p
%b Ende: %b Ende:
=h format_time(@order.ends) =h format_time(@order.ends)

View file

@ -32,6 +32,9 @@
%p %p
Notiz: Notiz:
=h @order.note =h @order.note
%p
Erstellt von:
=h link_to_user_message_if_valid(@order.created_by)
%p %p
Ende: Ende:
%b=h format_time(@order.ends) %b=h format_time(@order.ends)

View file

@ -21,6 +21,9 @@
%p %p
Notiz: Notiz:
=h @order.note =h @order.note
%p
Erstellt von:
=h link_to_user_message_if_valid(@order.created_by)
%p %p
Beginn: Beginn:
%b=h format_time(@order.starts) %b=h format_time(@order.starts)
@ -90,4 +93,4 @@
%br/ %br/
= submit_tag "Kommentar hinzufügen" = submit_tag "Kommentar hinzufügen"
= link_to_top = link_to_top

View file

@ -9,7 +9,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 => 20120622094337) do ActiveRecord::Schema.define(:version => 20121112093327) 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
@ -234,6 +234,7 @@ ActiveRecord::Schema.define(:version => 20120622094337) do
t.integer "lock_version", :default => 0, :null => false t.integer "lock_version", :default => 0, :null => false
t.integer "updated_by_user_id" t.integer "updated_by_user_id"
t.decimal "foodcoop_result", :precision => 8, :scale => 2 t.decimal "foodcoop_result", :precision => 8, :scale => 2
t.integer "created_by_user_id"
end end
add_index "orders", ["state"], :name => "index_orders_on_state" add_index "orders", ["state"], :name => "index_orders_on_state"