mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-02 21:57:17 +00:00
Add all variants for only one distributor
This commit is contained in:
@@ -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)()
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user