end of day commit

This commit is contained in:
2012-08-23 18:50:06 +02:00
parent 13dd2bf335
commit 0bae1bcbed
37 changed files with 1157 additions and 83 deletions
+38 -2
View File
@@ -1,9 +1,45 @@
class Order
include SimplyStored::Couch
property :state, default: 'placed' # placed, active, delivered, cancelled
belongs_to :list
belongs_to :user
belongs_to :supplier
has_many :product_orders
has_many :products, through: :product_orders
has_many :product_orders, dependent: :destroy
#has_many :products, through: :product_orders
validates :supplier_id, presence: true
view :active_for_supplier_view, type: :custom, map_function: %[function(doc){
if(doc.ruby_class == 'Order' && (doc.state == 'placed' || doc.state == 'active')){
emit(doc.supplier_id, 1);
}
}], reduce_function: '_sum'
def self.active_for_supplier(supplier_id)
database.view(active_for_supplier_view(key: supplier_id, reduce: false, include_docs: true))
end
def table_number
list.table.number
end
alias table_nr table_number
def placed?
state == 'placed'
end
def active?
state == 'active'
end
def is_being_processed!
self.state = 'active'
save
end
def is_delivered!
self.state = 'delivered'
save
end
end