When a variant is removed from supply to an order cycle, remove it from distribution also

This commit is contained in:
Rohan Mitchell
2013-09-20 11:11:59 +10:00
parent 00fe10e847
commit d100d12ebe
3 changed files with 42 additions and 2 deletions

View File

@@ -58,6 +58,9 @@ angular.module('order_cycle', ['ngResource'])
$event.preventDefault()
OrderCycle.removeExchangeFee(exchange, index)
$scope.removeDistributionOfVariant = (variant_id) ->
OrderCycle.removeDistributionOfVariant(variant_id)
$scope.submit = ->
OrderCycle.create()
])
@@ -122,6 +125,9 @@ angular.module('order_cycle', ['ngResource'])
$event.preventDefault()
OrderCycle.removeExchangeFee(exchange, index)
$scope.removeDistributionOfVariant = (variant_id) ->
OrderCycle.removeDistributionOfVariant(variant_id)
$scope.submit = ->
OrderCycle.update()
])
@@ -198,6 +204,10 @@ angular.module('order_cycle', ['ngResource'])
distributors = (exchange.enterprise_id for exchange in this.order_cycle.outgoing_exchanges)
jQuery.unique(suppliers.concat(distributors)).sort()
removeDistributionOfVariant: (variant_id) ->
for exchange in this.order_cycle.outgoing_exchanges
exchange.variants[variant_id] = false
load: (order_cycle_id) ->
service = this
@@ -332,4 +342,12 @@ angular.module('order_cycle', ['ngResource'])
(scope, element, attrs) ->
element.bind 'change', ->
scope.$apply(attrs.ofwOnChange)
)
.directive('ofwSyncDistributions', ->
(scope, element, attrs) ->
element.bind 'change', ->
if !$(this).is(':checked')
scope.$apply ->
scope.removeDistributionOfVariant(attrs.ofwSyncDistributions)
)