Add all variants for only one distributor

This commit is contained in:
GeorgeThoppil
2022-04-03 10:35:37 -04:00
parent c4fc8e9396
commit 706f6025e9
2 changed files with 33 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
angular.module('admin.orderCycles').factory 'OrderCycle', ($resource, $window, $timeout, StatusMessage, Panels) ->
angular.module('admin.orderCycles').factory 'OrderCycle', ($resource, $window, $timeout, StatusMessage, Panels, Enterprise) ->
OrderCycleResource = $resource '/admin/order_cycles/:action_name/:order_cycle_id.json', {}, {
'index': { method: 'GET', isArray: true}
'new' : { method: 'GET', params: { action_name: "new" } }
@@ -50,7 +50,14 @@ angular.module('admin.orderCycles').factory 'OrderCycle', ($resource, $window, $
(callback || angular.noop)()
addDistributor: (new_distributor_id, callback) ->
this.order_cycle.outgoing_exchanges.push({ enterprise_id: new_distributor_id, incoming: false, active: true, variants: {}, enterprise_fees: [] })
exchange = { enterprise_id: new_distributor_id, incoming: false, active: true, variants: {}, enterprise_fees: [] }
if (Enterprise.hub_enterprises.length == 1)
editable = this.order_cycle["editable_variants_for_outgoing_exchanges"][new_distributor_id] || []
variants = this.incomingExchangesVariants()
for variant in variants when variant in editable
exchange.variants[variant] = true
this.order_cycle.outgoing_exchanges.push(exchange)
$timeout ->
(callback || angular.noop)()

View File

@@ -120,19 +120,41 @@ describe 'OrderCycle service', ->
]
describe 'adding distributors', ->
exchange = null
$httpBackend = null
Enterprise = null
beforeEach ->
# Initialise OC
OrderCycle.new()
$httpBackend.flush()
inject ($injector, _$httpBackend_)->
Enterprise = $injector.get('Enterprise')
$httpBackend = _$httpBackend_
$httpBackend.whenGET('/admin/enterprises/for_order_cycle.json').respond [
{id: 1, name: 'Three', sells: 'any'}
]
it 'adds the distributor to outgoing exchanges', ->
$httpBackend.flush()
OrderCycle.addDistributor('123')
expect(OrderCycle.order_cycle.outgoing_exchanges).toEqual [
{enterprise_id: '123', incoming: false, active: true, variants: {}, enterprise_fees: []}
]
it 'selects all variants if only one distributor', ->
Enterprise.index()
$httpBackend.flush()
OrderCycle.order_cycle.editable_variants_for_outgoing_exchanges = {
123: [123, 234, 456, 789]
}
OrderCycle.order_cycle.incoming_exchanges = [
{variants: {123: true, 234: true}}
{variants: {456: true, 789: false}}
]
OrderCycle.addDistributor('123')
expect(OrderCycle.order_cycle.outgoing_exchanges).toEqual [
{enterprise_id: '123', incoming: false, active: true, variants: {123: true, 234: true, 456: true}, enterprise_fees: []}
]
describe 'removing exchanges', ->
exchange = null