end of day commit
This commit is contained in:
@@ -8,6 +8,7 @@ class List
|
||||
has_many :orders, dependent: :destroy
|
||||
belongs_to :table
|
||||
belongs_to :supplier
|
||||
belongs_to :section
|
||||
has_and_belongs_to_many :users, storing_keys: true
|
||||
|
||||
validates :table_id, presence: true
|
||||
@@ -15,6 +16,16 @@ class List
|
||||
|
||||
view :by_supplier_id_and_id, key: [:supplier_id, :_id]
|
||||
|
||||
def self.from_table table, user
|
||||
return if user.has_active_list?
|
||||
list = new table: table, supplier_id: table.supplier_id, section_id: table.section_id
|
||||
list.add_user user
|
||||
list.save
|
||||
user.active_list_id = list.id
|
||||
user.save
|
||||
list
|
||||
end
|
||||
|
||||
def close!
|
||||
orders.map(&:close!)
|
||||
self.state = 'closed'
|
||||
@@ -48,6 +59,13 @@ class List
|
||||
@order
|
||||
end
|
||||
|
||||
def move_to_table to_table
|
||||
TableMove.create list: self, from_table_id: table_id, to_table: to_table
|
||||
self.table = to_table
|
||||
self.section_id = to_table.section_id
|
||||
save
|
||||
end
|
||||
|
||||
def as_json
|
||||
super.merge(table_number: table_number)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user