end of day commit

This commit is contained in:
2012-08-29 17:42:04 +02:00
parent 89700f36e9
commit 8213bae2c6
57 changed files with 1109 additions and 128 deletions
+5
View File
@@ -0,0 +1,5 @@
class Administrator
include SimplyStored::Couch
include Devise::Orm::SimplyStored
devise :database_authenticatable, :rememberable #, :recoverable, :rememberable, :trackable, :registerable
end
+18
View File
@@ -8,6 +8,7 @@ class List
has_many :orders, dependent: :destroy
belongs_to :table
belongs_to :supplier
belongs_to :section
has_and_belongs_to_many :users, storing_keys: true
validates :table_id, presence: true
@@ -15,6 +16,16 @@ class List
view :by_supplier_id_and_id, key: [:supplier_id, :_id]
def self.from_table table, user
return if user.has_active_list?
list = new table: table, supplier_id: table.supplier_id, section_id: table.section_id
list.add_user user
list.save
user.active_list_id = list.id
user.save
list
end
def close!
orders.map(&:close!)
self.state = 'closed'
@@ -48,6 +59,13 @@ class List
@order
end
def move_to_table to_table
TableMove.create list: self, from_table_id: table_id, to_table: to_table
self.table = to_table
self.section_id = to_table.section_id
save
end
def as_json
super.merge(table_number: table_number)
end
+1
View File
@@ -6,6 +6,7 @@ class Order
belongs_to :list
belongs_to :user
belongs_to :supplier
belongs_to :section
has_many :product_orders, dependent: :destroy
#has_many :products, through: :product_orders
+2
View File
@@ -7,6 +7,8 @@ class ProductCategory
belongs_to :supplier
has_many :products
attr_protected :supplier_id
validates :position, numericality: true
validates :supplier_id, presence: true
end
+2
View File
@@ -7,6 +7,8 @@ class Section
belongs_to :supplier
has_many :tables
has_many :lists
has_many :orders
attr_protected :supplier_id
+2 -1
View File
@@ -23,7 +23,8 @@ class Table
}|, reduce_function: '_sum'
def occupied?
not self.class.database.view(self.class.active_lists(key: id, reduce: true)).zero?
return @is_occupied if instance_variable_defined?(:'@is_occupied')
@is_occupied = !self.class.database.view(self.class.active_lists(key: id, reduce: true)).zero?
end
def name
+6
View File
@@ -0,0 +1,6 @@
class TableMove
include SimplyStored::Couch
belongs_to :list
belongs_to :from_table, class_name: 'Table'
belongs_to :to_table, class_name: 'Table'
end
+11
View File
@@ -1,10 +1,21 @@
class User
include SimplyStored::Couch
include Devise::Orm::SimplyStored
property :active_list_id
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable
has_and_belongs_to_many :lists, storing_keys: false
has_many :orders
validates_uniqueness_of :email
def list_is_closed!
self.active_list_id = nil
save
end
def has_active_list?
active_list_id.present?
end
end