supplier improvements
This commit is contained in:
@@ -44,6 +44,7 @@ class ProductCategory
|
||||
@week_days = typecasted_value
|
||||
end
|
||||
|
||||
#TODO I am uuuuggggllyyyyy
|
||||
def self.for_user(user, options = {})
|
||||
table = options[:table]
|
||||
raise "ProductCategory.for_user requires a table" unless table.present?
|
||||
@@ -54,19 +55,17 @@ class ProductCategory
|
||||
product_categories = for_supplier_in_time(supplier, options[:time])
|
||||
|
||||
# The following part is creating the products hash. This should not be performed here!!!!!! #TODO fix this!!!@@!!@@!!@
|
||||
products = supplier.products
|
||||
# sort categories
|
||||
product_categories.sort_by!{|pc| (pc.position || 90000).to_i }
|
||||
#products = supplier.products
|
||||
|
||||
# Append other category if not defined by supplier
|
||||
other = product_categories.find(&:other?) || (product_categories << self.other).last # Container for non categorized products
|
||||
#other = product_categories.find(&:other?) || (product_categories << self.other).last # Container for non categorized products
|
||||
|
||||
# Initialize base return object
|
||||
h = {table_number: table.number, table_occupied: table.occupied?, supplier_name: supplier.name, my_list: list.try(:user_ids).to_a.include?(user.id)}
|
||||
|
||||
(products - product_categories.map(&:products).flatten).each{ |p| other.add_product(p) }
|
||||
#(products - product_categories.map(&:products).flatten).each{ |p| other.add_product(p) }
|
||||
|
||||
h[:categories] = product_categories.map{|pc| {name: pc.name, products: pc.products.to_a.map{|p| p.as_json}}}.select{|pc| pc && pc[:products].present?}
|
||||
h[:categories] = product_categories.map(&:to_client_format).select(&:present?)
|
||||
h
|
||||
end
|
||||
|
||||
@@ -81,7 +80,15 @@ class ProductCategory
|
||||
week_day = 6 if week_day < 0 # Saturday
|
||||
end
|
||||
view_options = {reduce: false, include_docs: true}
|
||||
database.view(by_supplier_id_and_week_time(view_options.merge(keys: [[supplier.id, week_day], [supplier.id, week_day, minute]])))
|
||||
product_categories = database.view(by_supplier_id_and_week_time(view_options.merge(keys: [[supplier.id, week_day], [supplier.id, week_day, minute]])))
|
||||
product_categories.sort_by!{|pc| (pc.position || 90000).to_i }
|
||||
# sort categories
|
||||
product_categories
|
||||
end
|
||||
|
||||
def to_client_format
|
||||
return {} unless products.present?
|
||||
{name: name, products: products.to_a.map{|p| p.as_json}}
|
||||
end
|
||||
|
||||
def other?
|
||||
|
||||
Reference in New Issue
Block a user