Fix active order display in supplier side
This commit is contained in:
+13
-4
@@ -168,10 +168,15 @@ class List
|
||||
self.table = to_table
|
||||
self.section_id = to_table.section_id
|
||||
if save
|
||||
for user_id in user_ids
|
||||
broadcast_user user_id, 'list_changed_table', list_id: id, table: to_table, section_title: to_table.section.try(:title), from_table_id: from_table
|
||||
# Update the section of an order
|
||||
orders.each do |order|
|
||||
order.section_id = self.section_id
|
||||
order.save
|
||||
end
|
||||
broadcast_supplier supplier_id, 'list_changed_table', list_id: id, table: to_table, section_title: to_table.section.try(:title), from_table_id: from_table
|
||||
for user_id in user_ids
|
||||
broadcast_user user_id, 'list_changed_table', list: as_json, section_title: to_table.section.try(:title), from_table_id: from_table
|
||||
end
|
||||
broadcast_supplier supplier_id, 'list_changed_table', list: as_json, section_title: to_table.section.try(:title), from_table_id: from_table
|
||||
end
|
||||
end
|
||||
|
||||
@@ -272,7 +277,7 @@ class List
|
||||
end
|
||||
|
||||
def as_json(*args)
|
||||
super.merge(table_number: table_number)
|
||||
super.merge(table_number: table_number, has_active_orders: has_active_orders? )
|
||||
end
|
||||
|
||||
def with_orders_as_json
|
||||
@@ -305,6 +310,10 @@ class List
|
||||
@with_orders_and_join_requests_as_json = with_orders_as_json.merge(join_requests_as_json)
|
||||
end
|
||||
|
||||
def has_active_orders?
|
||||
Order.count_active_for_supplier_and_list(supplier_id, id) > 0
|
||||
end
|
||||
|
||||
# Return a join requests object in the form of:
|
||||
# {join_request: [{user_id: '1saf3...', user_email: 'info@qwaiter.com'}, [....]]}
|
||||
def join_requests_as_json
|
||||
|
||||
+21
-6
@@ -15,25 +15,40 @@ class Order
|
||||
|
||||
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);
|
||||
emit([doc.supplier_id, doc.list_id], 1);
|
||||
}
|
||||
}], reduce_function: '_sum'
|
||||
}], reduce_function: '_sum'
|
||||
|
||||
view :active_for_supplier_and_section_view, type: :custom, map_function: %[function(doc){
|
||||
if(doc.ruby_class == 'Order' && (doc.state == 'placed' || doc.state == 'active')){
|
||||
emit([doc.supplier_id, doc.section_id], 1);
|
||||
}
|
||||
}], reduce_function: '_sum'
|
||||
view :by_supplier_id_and_id, key: [:supplier_id, :_id]
|
||||
view :by_list_id, key: :list_id
|
||||
}], reduce_function: '_sum'
|
||||
|
||||
#view :by_supplier_id_and_id, key: [:supplier_id, :_id]
|
||||
|
||||
# Return all currently active orders for a given supplier
|
||||
def self.active_for_supplier(supplier_id)
|
||||
database.view(active_for_supplier_view(key: supplier_id, reduce: false, include_docs: true))
|
||||
database.view(active_for_supplier_view(startkey: [supplier_id], endkey: [supplier_id, {}], reduce: false, include_docs: true))
|
||||
end
|
||||
|
||||
# Return all currently active orders for a given supplier and list
|
||||
def self.active_for_supplier_and_list(supplier_id, list_id)
|
||||
supplier_id = supplier_id.id if supplier_id.is_a?(SimplyStored::Couch)
|
||||
list_id = list_id.id if list_id.is_a?(SimplyStored::Couch)
|
||||
database.view(active_for_supplier_view(key: [supplier_id, list_id], reduce: false, include_docs: true))
|
||||
end
|
||||
|
||||
def self.count_active_for_supplier_and_list(supplier_id, list_id)
|
||||
supplier_id = supplier_id.id if supplier_id.is_a?(SimplyStored::Couch)
|
||||
list_id = list_id.id if list_id.is_a?(SimplyStored::Couch)
|
||||
database.view(active_for_supplier_view(key: [supplier_id, list_id], reduce: true, include_docs: false))
|
||||
end
|
||||
|
||||
# Return all currently active orders for a given section
|
||||
def self.active_for_supplier_and_section(supplier, section_id)
|
||||
supplier_id = supplier.is_a?(SimplyStored::Couch) ? supplier.id : supplier
|
||||
section_id = section_id.id if section_id.is_a?(SimplyStored::Couch)
|
||||
database.view(active_for_supplier_and_section_view(key: [supplier_id, section_id], reduce: false, include_docs: true))
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user