Ember temp commit

This commit is contained in:
2013-09-24 08:47:30 +02:00
parent ebbb5dedfc
commit 5650ada04c
71 changed files with 595 additions and 66 deletions
+11 -1
View File
@@ -27,6 +27,14 @@ class Order
view :by_supplier_id_and_id, key: [:supplier_id, :_id] # Do not comment me out
def self.for_supplier(supplier, options = {})
total_entries = database.view(by_supplier_id_and_id({startkey: ["#{supplier.id}\u9999"], endkey: [supplier.id], include_docs: false, reduce: true, descending: true}))
options[:total_entries] = total_entries
with_pagination_options(options) do |options|
database.view(by_supplier_id_and_id({startkey: ["#{supplier.id}\u9999"], endkey: [supplier.id], include_docs: true, reduce: false, descending: true}.merge(options)))
end
end
# Return all currently active orders for a given supplier
def self.active_for_supplier(supplier_id)
database.view(active_for_supplier_view(startkey: [supplier_id], endkey: [supplier_id, {}], reduce: false, include_docs: true))
@@ -92,6 +100,7 @@ class Order
def as_json(*args)
h = super.with_indifferent_access
h[:id] = h[:_id]
h[:table_number] = table_number
h[:section_title] = list.table.section.try(:title)
h
@@ -105,7 +114,8 @@ class Order
order_total = 0.0
for product_order in product_orders
order_total += (product_order.amount * product_order.price).round(2)
ho[:products] << {name: product_order.product.name, id: product_order.product_id, number: product_order.amount, price: product_order.price}
# Use product order id as id since the price can be different for products and the state should be preserved
ho[:products] << {name: product_order.product.name, id: product_order.id, number: product_order.amount, price: product_order.price}
end
ho[:total_amount] = order_total.round(2)
@with_products_as_json = ho