mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Order cycle admin JS uses exchanges.incoming instead of role
This commit is contained in:
@@ -176,10 +176,10 @@ angular.module('order_cycle', ['ngResource'])
|
||||
exchange.showProducts = !exchange.showProducts
|
||||
|
||||
addSupplier: (new_supplier_id) ->
|
||||
this.order_cycle.incoming_exchanges.push({enterprise_id: new_supplier_id, active: true, variants: {}, enterprise_fees: []})
|
||||
this.order_cycle.incoming_exchanges.push({enterprise_id: new_supplier_id, incoming: true, active: true, variants: {}, enterprise_fees: []})
|
||||
|
||||
addDistributor: (new_distributor_id) ->
|
||||
this.order_cycle.outgoing_exchanges.push({enterprise_id: new_distributor_id, active: true, variants: {}, enterprise_fees: []})
|
||||
this.order_cycle.outgoing_exchanges.push({enterprise_id: new_distributor_id, incoming: false, active: true, variants: {}, enterprise_fees: []})
|
||||
|
||||
removeExchange: (exchange) ->
|
||||
incoming_index = this.order_cycle.incoming_exchanges.indexOf exchange
|
||||
@@ -239,18 +239,15 @@ angular.module('order_cycle', ['ngResource'])
|
||||
service.order_cycle.incoming_exchanges = []
|
||||
service.order_cycle.outgoing_exchanges = []
|
||||
for exchange in service.order_cycle.exchanges
|
||||
if exchange.sender_id == service.order_cycle.coordinator_id
|
||||
angular.extend(exchange, {enterprise_id: exchange.receiver_id, active: true})
|
||||
delete(exchange.sender_id)
|
||||
service.order_cycle.outgoing_exchanges.push(exchange)
|
||||
|
||||
else if exchange.receiver_id == service.order_cycle.coordinator_id
|
||||
if exchange.incoming
|
||||
angular.extend(exchange, {enterprise_id: exchange.sender_id, active: true})
|
||||
delete(exchange.receiver_id)
|
||||
service.order_cycle.incoming_exchanges.push(exchange)
|
||||
|
||||
else
|
||||
console.log('Exchange between two enterprises, neither of which is coordinator!')
|
||||
angular.extend(exchange, {enterprise_id: exchange.receiver_id, active: true})
|
||||
delete(exchange.sender_id)
|
||||
service.order_cycle.outgoing_exchanges.push(exchange)
|
||||
|
||||
delete(service.order_cycle.exchanges)
|
||||
service.loaded = true
|
||||
|
||||
@@ -13,6 +13,7 @@ r.element :order_cycle, @order_cycle do
|
||||
r.element :id
|
||||
r.element :sender_id
|
||||
r.element :receiver_id
|
||||
r.element :incoming
|
||||
|
||||
r.element :variants, Hash[ exchange.variants.map { |v| [v.id, true] } ], {}
|
||||
|
||||
|
||||
@@ -223,6 +223,28 @@ feature %q{
|
||||
end
|
||||
|
||||
|
||||
scenario "editing an order cycle with an exchange between the same enterprise" do
|
||||
c = create(:distributor_enterprise, is_primary_producer: true)
|
||||
login_to_admin_section
|
||||
|
||||
# Given two order cycles, one with a mono-enterprise incoming exchange...
|
||||
oc_incoming = create(:simple_order_cycle, suppliers: [c], coordinator: c)
|
||||
|
||||
# And the other with a mono-enterprise outgoing exchange
|
||||
oc_outgoing = create(:simple_order_cycle, coordinator: c, distributors: [c])
|
||||
|
||||
# When I edit the first order cycle, the exchange should appear as incoming
|
||||
visit edit_admin_order_cycle_path(oc_incoming)
|
||||
page.should have_selector 'table.exchanges tr.supplier'
|
||||
page.should_not have_selector 'table.exchanges tr.distributor'
|
||||
|
||||
# And when I edit the second order cycle, the exchange should appear as outgoing
|
||||
visit edit_admin_order_cycle_path(oc_outgoing)
|
||||
page.should have_selector 'table.exchanges tr.distributor'
|
||||
page.should_not have_selector 'table.exchanges tr.supplier'
|
||||
end
|
||||
|
||||
|
||||
scenario "updating an order cycle", js: true do
|
||||
# Given an order cycle with all the settings
|
||||
oc = create(:order_cycle)
|
||||
|
||||
@@ -403,8 +403,8 @@ describe 'OrderCycle services', ->
|
||||
coordinator_id: 456
|
||||
coordinator_fees: []
|
||||
exchanges: [
|
||||
{sender_id: 1, receiver_id: 456}
|
||||
{sender_id: 456, receiver_id: 2}
|
||||
{sender_id: 1, receiver_id: 456, incoming: true}
|
||||
{sender_id: 456, receiver_id: 2, incoming: false}
|
||||
]
|
||||
|
||||
it 'initialises order cycle', ->
|
||||
@@ -456,7 +456,7 @@ describe 'OrderCycle services', ->
|
||||
it 'adds the supplier to incoming exchanges', ->
|
||||
OrderCycle.addSupplier('123')
|
||||
expect(OrderCycle.order_cycle.incoming_exchanges).toEqual [
|
||||
{enterprise_id: '123', active: true, variants: {}, enterprise_fees: []}
|
||||
{enterprise_id: '123', incoming: true, active: true, variants: {}, enterprise_fees: []}
|
||||
]
|
||||
|
||||
describe 'adding distributors', ->
|
||||
@@ -465,7 +465,7 @@ describe 'OrderCycle services', ->
|
||||
it 'adds the distributor to outgoing exchanges', ->
|
||||
OrderCycle.addDistributor('123')
|
||||
expect(OrderCycle.order_cycle.outgoing_exchanges).toEqual [
|
||||
{enterprise_id: '123', active: true, variants: {}, enterprise_fees: []}
|
||||
{enterprise_id: '123', incoming: false, active: true, variants: {}, enterprise_fees: []}
|
||||
]
|
||||
|
||||
describe 'removing exchanges', ->
|
||||
@@ -630,12 +630,14 @@ describe 'OrderCycle services', ->
|
||||
expect(OrderCycle.order_cycle.incoming_exchanges).toEqual [
|
||||
sender_id: 1
|
||||
enterprise_id: 1
|
||||
incoming: true
|
||||
active: true
|
||||
]
|
||||
|
||||
expect(OrderCycle.order_cycle.outgoing_exchanges).toEqual [
|
||||
receiver_id: 2
|
||||
enterprise_id: 2
|
||||
incoming: false
|
||||
active: true
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user