remove denormalization of lists and orders towards the section
This commit is contained in:
+14
-11
@@ -16,7 +16,7 @@ class List
|
||||
has_many :orders, dependent: :destroy
|
||||
belongs_to :table
|
||||
belongs_to :supplier
|
||||
belongs_to :section
|
||||
belongs_to :section #TODO: deprecate
|
||||
has_many :list_payments
|
||||
has_and_belongs_to_many :users, storing_keys: true
|
||||
has_and_belongs_to_many :employees, storing_keys: true
|
||||
@@ -46,12 +46,14 @@ class List
|
||||
#}
|
||||
#}|, reduce_function: '_sum'
|
||||
|
||||
#TODO: deprecate
|
||||
view :active_by_section_id_view, type: :custom, map_function: %|function(doc){
|
||||
if(doc.ruby_class == 'List' && doc.state == 'active' && doc.section_id){
|
||||
emit(doc.section_id, 1);
|
||||
}
|
||||
}|, reduce_function: '_sum'
|
||||
|
||||
#TODO: deprecate
|
||||
view :active_for_supplier_and_section_view, type: :custom, map_function: %|function(doc){
|
||||
if(doc.ruby_class == 'List' && doc.state == 'active'){
|
||||
emit([doc.supplier_id, doc.section_id], 1);
|
||||
@@ -81,13 +83,13 @@ class List
|
||||
# Create, a list given a table and a user
|
||||
def self.from_table table, user
|
||||
return if user.has_active_list?
|
||||
list = new table: table, section_id: table.section_id
|
||||
list = new table: table #, section_id: table.section_id
|
||||
list.supplier_id = table.supplier_id
|
||||
list.add_user user
|
||||
list.save
|
||||
user.active_list_id = list.id
|
||||
user.save
|
||||
# list_added is depricated, now handled by list_update
|
||||
# list_added is deprecated, now handled by list_update
|
||||
#list.broadcast_supplier list.supplier_id, 'list_added', list.with_info_as_json
|
||||
list
|
||||
end
|
||||
@@ -95,7 +97,7 @@ class List
|
||||
# Create, a list given a table and a employee
|
||||
def self.from_table_by_employee table, employee
|
||||
unless list = table.active_list
|
||||
list = new table: table, section_id: table.section_id
|
||||
list = new table: table #, section_id: table.section_id
|
||||
list.supplier_id = table.supplier_id
|
||||
list.add_employee employee
|
||||
list.save
|
||||
@@ -116,11 +118,13 @@ class List
|
||||
database.view(active_view(startkey: [supplier.id], endkey: ["#{supplier.id}\u9999"], reduce: false, include_docs: true))
|
||||
end
|
||||
|
||||
#TODO: deprecate
|
||||
def self.active_for_section(section, options = {})
|
||||
database.view(active_by_section_id_view(key: section.id, reduce: false, include_docs: true))
|
||||
end
|
||||
|
||||
# Return all currently active orders for a given section
|
||||
#TODO: deprecate
|
||||
def self.active_for_supplier_and_section(supplier, section_id, options = {})
|
||||
database.view(active_for_supplier_and_section_view(key: [supplier.id, section_id], reduce: false, include_docs: true))
|
||||
end
|
||||
@@ -229,13 +233,13 @@ class List
|
||||
UserTableMove.create list: self, from_table_id: table_id, to_table: to_table
|
||||
from_table_id = self.table_id.try(:dup)
|
||||
self.table = to_table
|
||||
self.section_id = to_table.section_id
|
||||
#self.section_id = to_table.section_id
|
||||
if save
|
||||
# Update the section of an order
|
||||
orders.each do |order|
|
||||
order.section_id = self.section_id
|
||||
order.save
|
||||
end
|
||||
#orders.each do |order|
|
||||
#order.section_id = self.section_id
|
||||
#order.save
|
||||
#end
|
||||
# user performs a client side refresh
|
||||
broadcast_users 'list_changed_table', list_id: id, from_table_id: from_table_id, to_table_id: to_table.id
|
||||
broadcast_supplier supplier_id, 'list_changed_table',
|
||||
@@ -288,7 +292,7 @@ class List
|
||||
|
||||
def place_order(product_orders: [], user: nil, employee: nil, first_order: true)
|
||||
return false unless product_orders.any?
|
||||
order = Order.create list: self, supplier: supplier, user: user, employee: employee, section_id: section_id, table_id: table_id
|
||||
order = Order.create list: self, supplier: supplier, user: user, employee: employee #, section_id: section_id, table_id: table_id
|
||||
return unless order.id
|
||||
orders_placed_count = supplier.increment_orders_placed_count!
|
||||
loaded_products = self.class.database.load_document product_orders.map{|po| po['product_id'] || po['product']}
|
||||
@@ -321,7 +325,6 @@ class List
|
||||
orders.product_orders
|
||||
orders.product_orders.product
|
||||
users
|
||||
section
|
||||
table
|
||||
])
|
||||
# broadcast_supplier supplier.id, 'new_order', OrderSerializer.new(order)
|
||||
|
||||
Reference in New Issue
Block a user