attr = DS.attr
App.Order = DS.Model.extend
  state: attr 'string'
  list: DS.belongsTo('list', async: true)
  table: DS.belongsTo('table')
  product_orders: DS.hasMany('product_order', async: false)
  total: (->
    @get('product_orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
  ).property('product_orders.@each.quantity')
  display: (->
    @get('product_orders').map((po) -> po.get 'display').join(', ')
  ).property('product_orders.@each.quantity', 'product_orders.@each.product.@each.name')
  markCancelled: ->
    @set 'state', 'cancelled'
