optimize for dashboards
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
class MenuCategory < ApplicationRecord
|
||||
class MenuCategory < ApplicationRecord
|
||||
# before_create :generate_menu_category_code
|
||||
|
||||
belongs_to :menu
|
||||
belongs_to :menu
|
||||
has_many :children, :class_name => "MenuCategory", foreign_key: "menu_category_id"
|
||||
belongs_to :parent, :class_name => "MenuCategory", foreign_key: "menu_category_id", optional: true
|
||||
has_many :menu_items
|
||||
@@ -38,9 +38,7 @@ class MenuCategory < ApplicationRecord
|
||||
end
|
||||
|
||||
def valid_time
|
||||
|
||||
menu_category = MenuCategory.find(self.id)
|
||||
menu = Menu.find(menu_category.menu_id)
|
||||
menu = self.menu
|
||||
|
||||
from_t = Time.parse(menu.valid_time_from.strftime("%H:%M:%S"))
|
||||
to_t = Time.parse(menu.valid_time_to.strftime("%H:%M:%S"))
|
||||
@@ -64,7 +62,7 @@ class MenuCategory < ApplicationRecord
|
||||
|
||||
c +=24
|
||||
current = c*3600 + current_t.min* 60 + current_t.sec
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
else # (after) noon
|
||||
@@ -77,8 +75,8 @@ class MenuCategory < ApplicationRecord
|
||||
|
||||
day = Date.today.wday
|
||||
dayresult = menu.valid_days.include?(day.to_s)
|
||||
|
||||
|
||||
|
||||
|
||||
if current.between?(from, to) && menu.valid_days.include?(day.to_s)
|
||||
return true
|
||||
else
|
||||
@@ -104,12 +102,12 @@ class MenuCategory < ApplicationRecord
|
||||
|
||||
private
|
||||
|
||||
# def generate_menu_category_code
|
||||
# self.code = SeedGenerator.generate_code(self.class.name, "C")
|
||||
# def generate_menu_category_code
|
||||
# self.code = SeedGenerator.generate_code(self.class.name, "C")
|
||||
# end
|
||||
|
||||
def self.to_csv
|
||||
|
||||
|
||||
mc_attributes = %w{id menu_id code name alt_name order_by created_by menu_category_id is_available created_at updated_at}
|
||||
CSV.generate(headers: true) do |csv|
|
||||
csv << mc_attributes
|
||||
@@ -123,7 +121,3 @@ class MenuCategory < ApplicationRecord
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user