class List module DepricatedSerialization extend ActiveSupport::Concern def as_json(*args) super.merge(id: id, table_number: table_number, has_active_orders: has_active_orders? ) end def with_orders_as_json return @with_orders_as_json if @with_orders_as_json.present? orders.include_relations(product_orders: :product) h = as_json h[:orders] = [] h[:list_active] = active? list_total = 0.0 for order in orders ho = {products: []} ho[:id] = order.id ho[:state] = order.state order_total = 0.0 for product_order in order.product_orders order_total += (product_order.quantity * product_order.price).round(2) ho[:products] << {name: product_order.product_name, id: product_order.product_id, number: product_order.quantity, price: product_order.price} end ho[:total_amount] = order_total.round(2) ho[:state] = order.state list_total += ho[:total_amount] h[:orders] << ho end h[:total_amount] = list_total.round(2) @with_orders_as_json = h end def with_orders_and_join_requests_as_json return @with_orders_and_join_requests_as_json if @with_orders_and_join_requests_as_json.present? @with_orders_and_join_requests_as_json = with_orders_as_json.merge(join_requests_as_json) end def with_orders_and_join_requests_and_supplier_info_as_json with_orders_and_join_requests_as_json.merge( supplier_name: supplier.name, ).merge(supplier_counter_info) end def serialized_with_status_join_requests_and_supplier_counters as_json.merge(list_active: active? ).merge(join_requests_as_json).merge(supplier_counter_info) end end end