37 lines
1.0 KiB
Ruby
37 lines
1.0 KiB
Ruby
class OrderItem < ApplicationRecord
|
|
#Associations
|
|
belongs_to :order, autosave: true
|
|
|
|
#Validation
|
|
validates_presence_of :item_code, :item_name, :qty
|
|
validates :qty, numericality: { :greater_than => 0 }
|
|
validates_associated :order
|
|
|
|
#This Method - handle how items is added into order
|
|
# order_item : {
|
|
# order_item_code : "",
|
|
# item_instance_code : "",
|
|
# quantity : 0,
|
|
# option_values : [],
|
|
# sub_order_items : [],
|
|
# }
|
|
def self.processs_item (item_code, menu_name, qty,price, options, set_menu_items, order_id, item_order_by)
|
|
|
|
orderitem = OrderItem.create do |oitem|
|
|
oitem.order_id = order_id
|
|
oitem.item_code = item_code
|
|
oitem.item_name = menu_name
|
|
oitem.qty = qty
|
|
oitem.price = price
|
|
oitem.options = options
|
|
oitem.set_menu_items = set_menu_items
|
|
oitem.item_order_by = item_order_by #person who order this. * If emenu - it will be login user on the app
|
|
end
|
|
|
|
#logger.debug orderitem.to_yml
|
|
orderitem.save!
|
|
|
|
|
|
end
|
|
end
|