Moved User.address-info into Ordergroup.contact_... attributes. Updated model-fixtures for testing.

This commit is contained in:
Benjamin Meichsner 2009-02-02 16:35:43 +01:00
parent aa47a24fda
commit 0a2a79237a
60 changed files with 466 additions and 443 deletions

View file

@ -3,24 +3,24 @@
#
# Table name: articles
#
# id :integer(4) not null, primary key
# id :integer 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
# supplier_id :integer default(0), not null
# article_category_id :integer default(0), not null
# unit :string(255) default(""), not null
# note :string(255)
# availability :boolean(1) default(TRUE), not null
# availability :boolean default(TRUE), not null
# manufacturer :string(255)
# origin :string(255)
# shared_updated_on :datetime
# price :decimal(8, 2)
# price :decimal(, )
# tax :float
# deposit :decimal(8, 2) default(0.0)
# unit_quantity :integer(4) default(1), not null
# deposit :decimal(, ) default(0.0)
# unit_quantity :integer default(1), not null
# order_number :string(255)
# created_at :datetime
# updated_at :datetime
# quantity :decimal(6, 2) default(0.0)
# quantity :decimal(, ) default(0.0)
# deleted_at :datetime
#

View file

@ -1,9 +1,9 @@
# == Schema Information
# Schema version: 20090102171850
# Schema version: 20090119155930
#
# Table name: article_categories
#
# id :integer(4) not null, primary key
# id :integer not null, primary key
# name :string(255) default(""), not null
# description :string(255)
#

View file

@ -1,14 +1,14 @@
# == Schema Information
# Schema version: 20090120184410
# Schema version: 20090119155930
#
# Table name: article_prices
#
# id :integer(4) not null, primary key
# article_id :integer(4)
# id :integer not null, primary key
# article_id :integer
# price :decimal(8, 2) default(0.0), not null
# tax :decimal(8, 2) default(0.0), not null
# deposit :decimal(8, 2) default(0.0), not null
# unit_quantity :integer(4)
# unit_quantity :integer
# created_at :datetime
#

View file

@ -1,12 +1,12 @@
# == Schema Information
# Schema version: 20090102171850
# Schema version: 20090119155930
#
# Table name: assignments
#
# id :integer(4) not null, primary key
# user_id :integer(4) default(0), not null
# task_id :integer(4) default(0), not null
# accepted :boolean(1)
# id :integer not null, primary key
# user_id :integer default(0), not null
# task_id :integer default(0), not null
# accepted :boolean
#
class Assignment < ActiveRecord::Base

View file

@ -1,10 +1,10 @@
# == Schema Information
# Schema version: 20090102171850
# Schema version: 20090119155930
#
# Table name: deliveries
#
# id :integer(4) not null, primary key
# supplier_id :integer(4)
# id :integer not null, primary key
# supplier_id :integer
# delivered_on :date
# created_at :datetime
#

View file

@ -1,13 +1,13 @@
# == Schema Information
# Schema version: 20090114101610
# Schema version: 20090119155930
#
# Table name: financial_transactions
#
# id :integer(4) not null, primary key
# ordergroup_id :integer(4) default(0), not null
# id :integer not null, primary key
# ordergroup_id :integer default(0), not null
# amount :decimal(8, 2) default(0.0), not null
# note :text default(""), not null
# user_id :integer(4) default(0), not null
# note :text not null
# user_id :integer default(0), not null
# created_on :datetime not null
#

View file

@ -3,25 +3,27 @@
#
# Table name: groups
#
# id :integer(4) not null, primary key
# id :integer 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_balance :decimal(, ) 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)
# role_admin :boolean not null
# role_suppliers :boolean not null
# role_article_meta :boolean not null
# role_finance :boolean not null
# role_orders :boolean not null
# weekly_task :boolean
# weekday :integer
# task_name :string(255)
# task_description :string(255)
# task_required_users :integer(4) default(1)
# task_required_users :integer default(1)
# deleted_at :datetime
# contact_person :string(255)
# contact_phone :string(255)
# contact_address :string(255)
#
# Groups organize the User.

View file

@ -1,15 +1,15 @@
# == Schema Information
# Schema version: 20090120184410
# Schema version: 20090119155930
#
# Table name: group_orders
#
# id :integer(4) not null, primary key
# ordergroup_id :integer(4) default(0), not null
# order_id :integer(4) default(0), not null
# id :integer not null, primary key
# ordergroup_id :integer default(0), not null
# order_id :integer default(0), not null
# price :decimal(8, 2) default(0.0), not null
# lock_version :integer(4) default(0), not null
# lock_version :integer default(0), not null
# updated_on :datetime not null
# updated_by_user_id :integer(4)
# updated_by_user_id :integer
#
# A GroupOrder represents an Order placed by an Ordergroup.

View file

@ -1,13 +1,13 @@
# == Schema Information
# Schema version: 20090102171850
# Schema version: 20090119155930
#
# Table name: group_order_articles
#
# id :integer(4) not null, primary key
# group_order_id :integer(4) default(0), not null
# order_article_id :integer(4) default(0), not null
# quantity :integer(4) default(0), not null
# tolerance :integer(4) default(0), not null
# id :integer not null, primary key
# group_order_id :integer default(0), not null
# order_article_id :integer default(0), not null
# quantity :integer default(0), not null
# tolerance :integer default(0), not null
# updated_on :datetime not null
#

View file

@ -1,12 +1,12 @@
# == Schema Information
# Schema version: 20090102171850
# Schema version: 20090119155930
#
# Table name: group_order_article_quantities
#
# id :integer(4) not null, primary key
# group_order_article_id :integer(4) default(0), not null
# quantity :integer(4) default(0)
# tolerance :integer(4) default(0)
# id :integer not null, primary key
# group_order_article_id :integer default(0), not null
# quantity :integer default(0)
# tolerance :integer default(0)
# created_on :datetime not null
#

View file

@ -1,13 +1,13 @@
# == Schema Information
# Schema version: 20090102171850
# Schema version: 20090119155930
#
# Table name: invites
#
# id :integer(4) not null, primary key
# id :integer not null, primary key
# token :string(255) default(""), not null
# expires_at :datetime not null
# group_id :integer(4) default(0), not null
# user_id :integer(4) default(0), not null
# group_id :integer default(0), not null
# user_id :integer default(0), not null
# email :string(255) default(""), not null
#

View file

@ -1,11 +1,11 @@
# == Schema Information
# Schema version: 20090120184410
# Schema version: 20090119155930
#
# Table name: invoices
#
# id :integer(4) not null, primary key
# supplier_id :integer(4)
# delivery_id :integer(4)
# id :integer not null, primary key
# supplier_id :integer
# delivery_id :integer
# number :string(255)
# date :date
# paid_on :date
@ -13,7 +13,7 @@
# amount :decimal(8, 2) default(0.0), not null
# created_at :datetime
# updated_at :datetime
# order_id :integer(4)
# order_id :integer
# deposit :decimal(8, 2) default(0.0), not null
# deposit_credit :decimal(8, 2) default(0.0), not null
#

View file

@ -1,11 +1,11 @@
# == Schema Information
# Schema version: 20090102171850
# Schema version: 20090119155930
#
# Table name: memberships
#
# id :integer(4) not null, primary key
# group_id :integer(4) default(0), not null
# user_id :integer(4) default(0), not null
# id :integer not null, primary key
# group_id :integer default(0), not null
# user_id :integer default(0), not null
#
class Membership < ActiveRecord::Base

View file

@ -1,15 +1,15 @@
# == Schema Information
# Schema version: 20090115232435
# Schema version: 20090119155930
#
# Table name: messages
#
# id :integer(4) not null, primary key
# sender_id :integer(4)
# id :integer not null, primary key
# sender_id :integer
# recipients_ids :text
# subject :string(255) not null
# body :text
# email_state :integer(4) default(0), not null
# private :boolean(1)
# email_state :integer default(0), not null
# private :boolean
# created_at :datetime
#

View file

@ -1,16 +1,16 @@
# == Schema Information
# Schema version: 20090120184410
# Schema version: 20090119155930
#
# Table name: orders
#
# id :integer(4) not null, primary key
# supplier_id :integer(4)
# id :integer not null, primary key
# supplier_id :integer
# note :text
# starts :datetime
# ends :datetime
# state :string(255) default("open")
# lock_version :integer(4) default(0), not null
# updated_by_user_id :integer(4)
# lock_version :integer default(0), not null
# updated_by_user_id :integer
#
class Order < ActiveRecord::Base

View file

@ -1,16 +1,16 @@
# == Schema Information
# Schema version: 20090120184410
# Schema version: 20090119155930
#
# Table name: order_articles
#
# id :integer(4) not null, primary key
# order_id :integer(4) default(0), not null
# article_id :integer(4) default(0), not null
# quantity :integer(4) default(0), not null
# tolerance :integer(4) default(0), not null
# units_to_order :integer(4) default(0), not null
# lock_version :integer(4) default(0), not null
# article_price_id :integer(4)
# id :integer not null, primary key
# order_id :integer default(0), not null
# article_id :integer default(0), not null
# quantity :integer default(0), not null
# tolerance :integer default(0), not null
# units_to_order :integer default(0), not null
# lock_version :integer default(0), not null
# article_price_id :integer
#
# An OrderArticle represents a single Article that is part of an Order.

View file

@ -1,11 +1,11 @@
# == Schema Information
# Schema version: 20090120184410
# Schema version: 20090119155930
#
# Table name: order_comments
#
# id :integer(4) not null, primary key
# order_id :integer(4)
# user_id :integer(4)
# id :integer not null, primary key
# order_id :integer
# user_id :integer
# text :text
# created_at :datetime
#

View file

@ -3,25 +3,27 @@
#
# Table name: groups
#
# id :integer(4) not null, primary key
# id :integer 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_balance :decimal(, ) 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)
# role_admin :boolean not null
# role_suppliers :boolean not null
# role_article_meta :boolean not null
# role_finance :boolean not null
# role_orders :boolean not null
# weekly_task :boolean
# weekday :integer
# task_name :string(255)
# task_description :string(255)
# task_required_users :integer(4) default(1)
# task_required_users :integer default(1)
# deleted_at :datetime
# contact_person :string(255)
# contact_phone :string(255)
# contact_address :string(255)
#
# Ordergroups can order, they are "children" of the class Group
@ -29,7 +31,6 @@
# Ordergroup have the following attributes, in addition to Group
# * account_balance (decimal)
# * account_updated (datetime)
# * actual_size (int) : how many persons are ordering through the Ordergroup
class Ordergroup < Group
acts_as_paranoid # Avoid deleting the ordergroup for consistency of order-results
extend ActiveSupport::Memoizable # Ability to cache method results. Use memoize :expensive_method
@ -38,9 +39,11 @@ class Ordergroup < Group
has_many :group_orders
has_many :orders, :through => :group_orders
validates_inclusion_of :actual_size, :in => 1..99
validates_numericality_of :account_balance, :message => 'ist keine gültige Zahl'
def contact
"#{contact_phone} (#{contact_person})"
end
def non_members
User.all(:order => 'nick').reject { |u| (users.include?(u) || u.ordergroup) }
end

View file

@ -1,12 +1,12 @@
# == Schema Information
# Schema version: 20090115232435
# Schema version: 20090119155930
#
# Table name: stock_changes
#
# id :integer(4) not null, primary key
# delivery_id :integer(4)
# order_id :integer(4)
# article_id :integer(4)
# id :integer not null, primary key
# delivery_id :integer
# order_id :integer
# article_id :integer
# quantity :decimal(6, 2) default(0.0)
# created_at :datetime
#

View file

@ -3,7 +3,7 @@
#
# Table name: suppliers
#
# id :integer(4) not null, primary key
# id :integer not null, primary key
# name :string(255) default(""), not null
# address :string(255) default(""), not null
# phone :string(255) default(""), not null
@ -16,7 +16,7 @@
# delivery_days :string(255)
# order_howto :string(255)
# note :string(255)
# shared_supplier_id :integer(4)
# shared_supplier_id :integer
# min_order_quantity :string(255)
# deleted_at :datetime
#

View file

@ -1,18 +1,18 @@
# == Schema Information
# Schema version: 20090114101610
# Schema version: 20090119155930
#
# Table name: tasks
#
# id :integer(4) not null, primary key
# id :integer not null, primary key
# name :string(255) default(""), not null
# description :string(255)
# due_date :date
# done :boolean(1)
# workgroup_id :integer(4)
# assigned :boolean(1)
# done :boolean
# workgroup_id :integer
# assigned :boolean
# created_on :datetime not null
# updated_on :datetime not null
# required_users :integer(4) default(1)
# required_users :integer default(1)
#
class Task < ActiveRecord::Base

View file

@ -1,9 +1,9 @@
# == Schema Information
# Schema version: 20090102171850
# Schema version: 20090120184410
#
# Table name: users
#
# id :integer(4) not null, primary key
# id :integer not null, primary key
# nick :string(255) default(""), not null
# password_hash :string(255) default(""), not null
# password_salt :string(255) default(""), not null
@ -11,7 +11,6 @@
# last_name :string(255) default(""), not null
# email :string(255) default(""), not null
# phone :string(255)
# address :string(255)
# created_on :datetime not null
# reset_password_token :string(255)
# reset_password_expires :datetime
@ -80,6 +79,13 @@ class User < ActiveRecord::Base
end
end
def name
[first_name, last_name].join(" ")
end
def ordergroup_name
ordergroup.name if ordergroup
end
# Sets the user's password. It will be stored encrypted along with a random salt.
def set_password
@ -94,22 +100,6 @@ class User < ActiveRecord::Base
Digest::SHA1.hexdigest(password + self.password_salt) == self.password_hash
end
# # Sets the passwort, and if fails it returns error-messages (see above)
# def set_password(options = {:required => false}, password = nil, confirmation = nil)
# required = options[:required]
# if required && (password.nil? || password.empty?)
# self.errors.add_to_base 'Password is required'
# elsif !password.nil? && !password.empty?
# if password != confirmation
# self.errors.add_to_base "Passwords doesn't match"
# elsif password.length < 5 || password.length > 25
# self.errors.add_to_base 'Password-length has to be between 5 and 25 characters'
# else
# self.password = password
# end
# end
# end
# Returns a random password.
def new_random_password(size = 3)
c = %w(b c d f g h j k l m n p qu r s t v w x z ch cr fr nd ng nk nt ph pr rd sh sl sp st th tr)

View file

@ -3,25 +3,27 @@
#
# Table name: groups
#
# id :integer(4) not null, primary key
# id :integer 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_balance :decimal(, ) 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)
# role_admin :boolean not null
# role_suppliers :boolean not null
# role_article_meta :boolean not null
# role_finance :boolean not null
# role_orders :boolean not null
# weekly_task :boolean
# weekday :integer
# task_name :string(255)
# task_description :string(255)
# task_required_users :integer(4) default(1)
# task_required_users :integer default(1)
# deleted_at :datetime
# contact_person :string(255)
# contact_phone :string(255)
# contact_address :string(255)
#
class Workgroup < Group