Save progress

This commit is contained in:
2014-03-30 15:55:22 +02:00
parent e179f6e582
commit 013a41b9f6
71 changed files with 1699 additions and 107 deletions
@@ -3,19 +3,26 @@ Qsupplier.App.Order = DS.Model.extend
state: attr('string')
list: DS.belongsTo('list')
price: attr('number')
product_orders: attr()
section: DS.belongsTo('section')
section_id: attr('string')
product_orders: DS.hasMany('product_order')
active: (-> @get('state') == 'active').property('state')
delivered: (-> @get('state') == 'delivered').property('state')
placed: (-> @get('state') == 'placed').property('state')
needs_supplier_attention: (-> @get('state') == 'placed' || @get('state') == 'active').property('state')
display: (->
return '' unless @get('product_orders')
@get('product_orders').map((po)-> "#{po.product_name} (#{po.quantity})").join(',')
).property('product_orders')
#display: (->
#return '' unless @get('product_orders')
#@get('product_orders').map((po)-> "#{po.product_name} (#{po.quantity})").join(',')
#).property('product_orders')
markClosed: ->
@set 'state', 'closed'
total: (->
@get('product_orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
).property('product_orders.@each.quantity', 'product_orders.@each.product.@each.price')
display: (->
@get('product_orders').map((po) -> "#{po.get('quantity')} x #{po.get('product.name')}").join(', ')
).property('product_orders.@each.quantity', 'product_orders.@each.product.@each.name')
@@ -1,3 +1,6 @@
attr = DS.attr
Qsupplier.App.Product = DS.Model.extend
order: DS.belongsTo('order')
name: attr 'string'
price: attr 'number'
product_category: DS.belongsTo('product_category')
product_orders: DS.hasMany('product_order')
@@ -0,0 +1,4 @@
attr = DS.attr
Qsupplier.App.ProductCategory = DS.Model.extend
name: attr('string')
products: DS.hasMany('product')
@@ -0,0 +1,8 @@
attr = DS.attr
Qsupplier.App.ProductOrder = DS.Model.extend
quantity: attr 'number', defaultValue: 1
product: DS.belongsTo('product')
order: DS.belongsTo('order')
increment: ->
@set('quantity', @get('quantity') + 1)
total: (-> @get('quantity') * @get('product.price')).property('quantity', 'product.price')