move to evented mustache system
This commit is contained in:
+33
-2
@@ -50,16 +50,47 @@ class Order
|
||||
|
||||
def is_being_processed!
|
||||
self.state = 'active'
|
||||
save
|
||||
if save
|
||||
for user_id in list.user_ids
|
||||
broadcast_user user_id, 'order_being_processed', id: id
|
||||
end
|
||||
broadcast_supplier supplier_id, 'order_being_processed', id: id
|
||||
end
|
||||
end
|
||||
|
||||
def is_delivered!
|
||||
self.state = 'delivered'
|
||||
save
|
||||
if save
|
||||
for user_id in list.user_ids
|
||||
broadcast_user user_id, 'order_being_delivered', id: id
|
||||
end
|
||||
broadcast_supplier supplier_id, 'order_being_delivered', id: id
|
||||
end
|
||||
end
|
||||
|
||||
def close!
|
||||
self.state = 'closed' if placed? || active?
|
||||
save
|
||||
end
|
||||
|
||||
def as_json(*args)
|
||||
h = super.with_indifferent_access
|
||||
h[:table_number] = table_number
|
||||
h[:section_title] = list.table.section.try(:title)
|
||||
h
|
||||
end
|
||||
|
||||
def with_products_as_json
|
||||
return @with_products_as_json if @with_products_as_json.present?
|
||||
product_orders.include_relation(:product)
|
||||
ho = as_json
|
||||
ho[:products] = []
|
||||
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}
|
||||
end
|
||||
ho[:total_amount] = order_total.round(2)
|
||||
@with_products_as_json = ho
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user