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)
)

View File

@@ -2,9 +2,9 @@
%td{:colspan => 3}
.exchange-product{'ng-repeat' => 'product in enterprises[exchange.enterprise_id].supplied_products'}
.exchange-product-details
= check_box_tag 'order_cycle_incoming_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}', 1, 1, 'ng-hide' => 'product.variants', 'ng-model' => 'exchange.variants[product.master_id]', 'id' => 'order_cycle_incoming_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}'
= check_box_tag 'order_cycle_incoming_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}', 1, 1, 'ng-hide' => 'product.variants', 'ng-model' => 'exchange.variants[product.master_id]', 'ofw-sync-distributions' => '{{ product.master_id }}', 'id' => 'order_cycle_incoming_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}'
%img{'ng-src' => '{{ product.image_url }}'}
{{ product.name }}
.exchange-product-variant{'ng-repeat' => 'variant in product.variants'}
= check_box_tag 'order_cycle_incoming_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}', 1, 1, 'ng-model' => 'exchange.variants[variant.id]', 'id' => 'order_cycle_incoming_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}'
= check_box_tag 'order_cycle_incoming_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}', 1, 1, 'ng-model' => 'exchange.variants[variant.id]', 'ofw-sync-distributions' => '{{ variant.id }}', 'id' => 'order_cycle_incoming_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}'
{{ variant.label }}

View File

@@ -25,6 +25,7 @@ describe 'OrderCycle controllers', ->
removeCoordinatorFee: jasmine.createSpy('removeCoordinatorFee')
addExchangeFee: jasmine.createSpy('addExchangeFee')
removeExchangeFee: jasmine.createSpy('removeExchangeFee')
removeDistributionOfVariant: jasmine.createSpy('removeDistributionOfVariant')
create: jasmine.createSpy('create')
Enterprise =
index: jasmine.createSpy('index').andReturn('enterprises list')
@@ -121,6 +122,10 @@ describe 'OrderCycle controllers', ->
expect(event.preventDefault).toHaveBeenCalled()
expect(OrderCycle.removeExchangeFee).toHaveBeenCalledWith('exchange', 0)
it 'Removes distribution of a variant', ->
scope.removeDistributionOfVariant('variant')
expect(OrderCycle.removeDistributionOfVariant).toHaveBeenCalledWith('variant')
it 'Submits the order cycle via OrderCycle create', ->
scope.submit()
expect(OrderCycle.create).toHaveBeenCalled()
@@ -154,6 +159,7 @@ describe 'OrderCycle controllers', ->
removeCoordinatorFee: jasmine.createSpy('removeCoordinatorFee')
addExchangeFee: jasmine.createSpy('addExchangeFee')
removeExchangeFee: jasmine.createSpy('removeExchangeFee')
removeDistributionOfVariant: jasmine.createSpy('removeDistributionOfVariant')
update: jasmine.createSpy('update')
Enterprise =
index: jasmine.createSpy('index').andReturn('enterprises list')
@@ -249,6 +255,10 @@ describe 'OrderCycle controllers', ->
expect(event.preventDefault).toHaveBeenCalled()
expect(OrderCycle.removeExchangeFee).toHaveBeenCalledWith('exchange', 0)
it 'Removes distribution of a variant', ->
scope.removeDistributionOfVariant('variant')
expect(OrderCycle.removeDistributionOfVariant).toHaveBeenCalledWith('variant')
it 'Submits the order cycle via OrderCycle update', ->
scope.submit()
expect(OrderCycle.update).toHaveBeenCalled()
@@ -514,6 +524,18 @@ describe 'OrderCycle services', ->
expect(OrderCycle.variantSuppliedToOrderCycle({id: 999})).toBeFalsy()
describe 'remove all distribution of a variant', ->
it 'removes the variant from every outgoing exchange', ->
OrderCycle.order_cycle.outgoing_exchanges = [
{variants: {123: true, 234: true}}
{variants: {123: true, 333: true}}
]
OrderCycle.removeDistributionOfVariant('123')
expect(OrderCycle.order_cycle.outgoing_exchanges).toEqual [
{variants: {123: false, 234: true}}
{variants: {123: false, 333: true}}
]
describe 'loading an order cycle', ->
beforeEach ->
OrderCycle.load('123')