Fixed bug in orders index if order.ends.nil?

This commit is contained in:
Benjamin Meichsner 2010-06-19 12:23:18 +02:00
parent db52c6e4ed
commit fbf6a283a0
3 changed files with 8 additions and 3 deletions

View file

@ -94,6 +94,10 @@ class Order < ActiveRecord::Base
state == "closed" state == "closed"
end end
def expired?
!ends.nil? && ends < Time.now
end
# search GroupOrder of given Ordergroup # search GroupOrder of given Ordergroup
def group_order(ordergroup) def group_order(ordergroup)
group_orders.first :conditions => { :ordergroup_id => ordergroup.id } group_orders.first :conditions => { :ordergroup_id => ordergroup.id }

View file

@ -81,7 +81,7 @@ class Ordergroup < Group
def update_stats! def update_stats!
time = 6.month.ago time = 6.month.ago
jobs = users.collect { |u| u.tasks.done.all(:conditions => ["updated_on > ?", time]).size }.sum jobs = users.collect { |u| u.tasks.done.all(:conditions => ["updated_on > ?", time]).size }.sum
orders_sum = group_orders.select { |go| go.order.ends > time }.collect(&:price).sum orders_sum = group_orders.select { |go| !go.order.ends.nil? && go.order.ends > time }.collect(&:price).sum
update_attribute(:stats, {:jobs_size => jobs, :orders_sum => orders_sum}) update_attribute(:stats, {:jobs_size => jobs, :orders_sum => orders_sum})
end end

View file

@ -22,8 +22,9 @@
%th{:colspan => "2"} %th{:colspan => "2"}
%tbody %tbody
- for order in @open_orders - for order in @open_orders
- active = (order.open? and order.ends < Time.now) ? " active" : "" - tr_class = cycle('even', 'odd', :name => 'open_orders')
%tr{:class => cycle('even', 'odd', :name => 'open_orders') + active} - tr_class += " active" if order.expired?
%tr{:class => tr_class}
%td=h order.name %td=h order.name
%td=h format_time(order.ends) unless order.ends.nil? %td=h format_time(order.ends) unless order.ends.nil?
%td=h truncate(order.note) %td=h truncate(order.note)