Big feactoring and bug fixing, Mailer, Tasks, GroupOrders

This commit is contained in:
benni 2012-08-24 11:11:40 +02:00
parent c936813967
commit 5fb0bc2444
43 changed files with 95 additions and 118 deletions

View file

@ -68,12 +68,12 @@ class Message < ActiveRecord::Base
end
def deliver
for recipient in recipients
if recipient.settings['messages.sendAsEmail'] == "1" && !recipient.email.blank?
for user in recipients
if user.receive_email?
begin
Mailer.foodsoft_message(self, recipient).deliver
# rescue
# logger.warn "Deliver failed for #{recipient.nick}: #{recipient.email}"
Mailer.foodsoft_message(self, user).deliver
rescue
logger.warn "Deliver failed for #{user.nick}: #{user.email}"
end
end
end

View file

@ -48,7 +48,7 @@ class Ordergroup < Group
self.account_balance = financial_transactions.sum('amount')
self.account_updated = trans.created_on
save!
notify_negative_balance(trans)
notify_negative_balance(trans)
end
end

View file

@ -13,6 +13,7 @@ class Task < ActiveRecord::Base
validates :name, :presence => true, :length => { :minimum => 3 }
validates :required_users, :presence => true
validates_numericality_of :duration, :required_users, :only_integer => true, :greater_than => 0
validates_length_of :description, maximum: 250
after_save :update_ordergroup_stats

View file

@ -72,6 +72,10 @@ class User < ActiveRecord::Base
[first_name, last_name].join(" ")
end
def receive_email?
settings['messages.sendAsEmail'] == "1" && email.present?
end
def ordergroup_name
ordergroup.name if ordergroup
end

View file

@ -6,9 +6,10 @@ class Workgroup < Group
has_many :open_tasks, :class_name => 'Task', :conditions => ['done = ?', false], :order => 'due_date ASC'
validates_presence_of :task_name, :weekday, :task_required_users, :next_weekly_tasks_number,
:if => :weekly_task
:if => :weekly_task
validates_numericality_of :next_weekly_tasks_number, :greater_than => 0, :less_than => 21, :only_integer => true,
:if => :weekly_task
:if => :weekly_task
validates_length_of :task_description, maximum: 250
validate :last_admin_on_earth, :on => :update
before_destroy :check_last_admin_group