Merge pull request #9752 from maniSHarma7575/9603-fix-order-cycle-fees-dropdown

Fixed same enterprise appear several times in the fee dropdown list
This commit is contained in:
Maikel
2022-10-11 09:41:02 +11:00
committed by GitHub
3 changed files with 20 additions and 4 deletions

View File

@@ -18,7 +18,8 @@ angular.module('admin.orderCycles')
OrderCycle.exchangeDirection(exchange)
$scope.enterprisesWithFees = ->
$scope.enterprises[id] for id in [OrderCycle.participatingEnterpriseIds()..., [OrderCycle.order_cycle.coordinator_id]...] when $scope.enterpriseFeesForEnterprise(id).length > 0
ids = [OrderCycle.participatingEnterpriseIds()..., [OrderCycle.order_cycle.coordinator_id]...]
$scope.enterprises[id] for id in Array.from(new Set(ids)) when $scope.enterpriseFeesForEnterprise(id).length > 0
$scope.removeExchange = ($event, exchange) ->
$event.preventDefault()

View File

@@ -93,9 +93,9 @@ angular.module('admin.orderCycles').factory 'OrderCycle', ($resource, $window, $
variant_ids
participatingEnterpriseIds: ->
suppliers = (exchange.enterprise_id for exchange in this.order_cycle.incoming_exchanges)
distributors = (exchange.enterprise_id for exchange in this.order_cycle.outgoing_exchanges)
jQuery.unique(suppliers.concat(distributors)).sort()
suppliers = (parseInt(exchange.enterprise_id) for exchange in this.order_cycle.incoming_exchanges)
distributors = (parseInt(exchange.enterprise_id) for exchange in this.order_cycle.outgoing_exchanges)
Array.from(new Set([suppliers..., distributors...]))
exchangesByDirection: (direction) ->
if direction == 'incoming'

View File

@@ -57,6 +57,21 @@ describe 'AdminOrderCycleExchangesCtrl', ->
{id: 2, name: 'Pepper Tree Place'},
{id: 4, name: 'coordinator'}
])
it 'Finds unique enterprises participating in the order cycle that have fees', ->
scope.enterpriseFeesForEnterprise = (enterprise_id) ->
EnterpriseFee.forEnterprise(parseInt(enterprise_id))
scope.enterprises =
1: {id: 1, name: 'Eaterprises'}
2: {id: 2, name: 'Pepper Tree Place'}
3: {id: 3, name: 'South East'}
4: {id: 4, name: 'coordinator'}
OrderCycle.participatingEnterpriseIds = jasmine.createSpy('participatingEnterpriseIds').and.returnValue([2, 2])
EnterpriseFee.enterprise_fees = [ {enterprise_id: 2} ]
expect(scope.enterprisesWithFees()).toEqual([
{id: 2, name: 'Pepper Tree Place'},
{id: 4, name: 'coordinator'}
])
it 'Removes order cycle exchanges', ->
scope.removeExchange(event, 'exchange')