Groups are now workgroups. First part of moving groups-logic into admin-namespace.

This commit is contained in:
Benjamin Meichsner 2009-01-13 19:01:56 +01:00
parent 461dfa8531
commit 2d5dc03b90
31 changed files with 616 additions and 37 deletions

View file

@ -1,3 +1,28 @@
# == Schema Information
# Schema version: 20090113111624
#
# 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
#
# == Schema Information
# Schema version: 20090102171850
#

View file

@ -28,12 +28,6 @@
class Group < ActiveRecord::Base
has_many :memberships, :dependent => :destroy
has_many :users, :through => :memberships
has_many :tasks
# returns all non-finished tasks
has_many :open_tasks, :class_name => 'Task', :conditions => ['done = ?', false], :order => 'due_date ASC'
attr_accessible :name, :description, :role_admin, :role_suppliers, :role_article_meta, :role_finance, :role_orders,
:weekly_task, :weekday, :task_name, :task_description, :task_required_users
validates_length_of :name, :in => 1..25
validates_uniqueness_of :name
@ -63,31 +57,9 @@ class Group < ActiveRecord::Base
raise ERR_LAST_ADMIN_GROUP_DELETE if self.role_admin == true && Group.find_all_by_role_admin(true).size == 1
end
# Returns an Array with date-objects to represent the next weekly-tasks
def next_weekly_tasks(number = 8)
# our system starts from 0 (sunday) to 6 (saturday)
# get difference between groups weekday and now
diff = self.weekday - Time.now.wday
if diff >= 0
# weektask is in current week
nextTask = diff.day.from_now
else
# weektask is in the next week
nextTask = (diff + 7).day.from_now
end
# now generate the Array
nextTasks = Array.new
number.times do
nextTasks << nextTask
nextTask = 1.week.from_now(nextTask)
end
return nextTasks
end
# get all groups, which are NOT OrderGroups
#TODO: better implement a new model, which inherits from Group, e.g. WorkGroup
def self.workgroups
Group.find :all, :conditions => "type IS NULL"
Workgroup.all
end
protected

View file

@ -1,5 +1,5 @@
# == Schema Information
# Schema version: 20090102171850
# Schema version: 20090113111624
#
# Table name: invoices
#
@ -9,6 +9,7 @@
# number :string(255)
# date :date
# paid_on :date
# note :text
# amount :decimal(8, 2) default(0.0), not null
# created_at :datetime
# updated_at :datetime

View file

@ -72,8 +72,10 @@ class User < ActiveRecord::Base
end
def update_settings
for setting in User::setting_keys.keys
self.settings[setting] = setting_attributes[setting] && setting_attributes[setting] == '1' ? '1' : nil
unless setting_attributes.nil?
for setting in User::setting_keys.keys
self.settings[setting] = setting_attributes[setting] && setting_attributes[setting] == '1' ? '1' : nil
end
end
end

57
app/models/workgroup.rb Normal file
View file

@ -0,0 +1,57 @@
# == Schema Information
# Schema version: 20090113111624
#
# Table name: groups
#
# id :integer(4) not null, primary key
# type :string(255) default(""), not null
# name :string(255) default(""), not null
# description :string(255)
# actual_size :integer(4)
# account_balance :decimal(8, 2) default(0.0), not null
# account_updated :datetime
# created_on :datetime not null
# role_admin :boolean(1) not null
# role_suppliers :boolean(1) not null
# role_article_meta :boolean(1) not null
# role_finance :boolean(1) not null
# role_orders :boolean(1) not null
# weekly_task :boolean(1)
# weekday :integer(4)
# task_name :string(255)
# task_description :string(255)
# task_required_users :integer(4) default(1)
#
class Workgroup < Group
has_many :tasks
# returns all non-finished tasks
has_many :open_tasks, :class_name => 'Task', :conditions => ['done = ?', false], :order => 'due_date ASC'
def self.weekdays
[["Montag", "1"], ["Dienstag", "2"], ["Mittwoch","3"],["Donnerstag","4"],["Freitag","5"],["Samstag","6"],["Sonntag","0"]]
end
# Returns an Array with date-objects to represent the next weekly-tasks
def next_weekly_tasks(number = 8)
# our system starts from 0 (sunday) to 6 (saturday)
# get difference between groups weekday and now
diff = self.weekday - Time.now.wday
if diff >= 0
# weektask is in current week
nextTask = diff.day.from_now
else
# weektask is in the next week
nextTask = (diff + 7).day.from_now
end
# now generate the Array
nextTasks = Array.new
number.times do
nextTasks << nextTask
nextTask = 1.week.from_now(nextTask)
end
return nextTasks
end
end