mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-05 02:41:33 +00:00
Merging master into all the things
This commit is contained in:
@@ -197,12 +197,13 @@ angular.module('order_cycle', ['ngResource'])
|
||||
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
|
||||
this.order_cycle.incoming_exchanges.splice(incoming_index, 1) if incoming_index > -1
|
||||
outgoing_index = this.order_cycle.outgoing_exchanges.indexOf exchange
|
||||
this.order_cycle.outgoing_exchanges.splice(outgoing_index, 1) if outgoing_index > -1
|
||||
|
||||
this.removeDistributionOfVariant(variant_id) for variant_id, active of exchange.variants when active
|
||||
if exchange.incoming
|
||||
incoming_index = this.order_cycle.incoming_exchanges.indexOf exchange
|
||||
this.order_cycle.incoming_exchanges.splice(incoming_index, 1)
|
||||
this.removeDistributionOfVariant(variant_id) for variant_id, active of exchange.variants when active
|
||||
else
|
||||
outgoing_index = this.order_cycle.outgoing_exchanges.indexOf exchange
|
||||
this.order_cycle.outgoing_exchanges.splice(outgoing_index, 1) if outgoing_index > -1
|
||||
|
||||
addCoordinatorFee: ->
|
||||
this.order_cycle.coordinator_fees.push({})
|
||||
|
||||
@@ -2,7 +2,7 @@ require 'open_food_network/spree_api_key_loader'
|
||||
|
||||
Spree::Admin::ProductsController.class_eval do
|
||||
include OpenFoodNetwork::SpreeApiKeyLoader
|
||||
before_filter :load_bpe_data, :only => :bulk_edit
|
||||
before_filter :load_form_data, :only => [:bulk_edit, :new, :edit]
|
||||
before_filter :load_spree_api_key, :only => :bulk_edit
|
||||
|
||||
alias_method :location_after_save_original, :location_after_save
|
||||
@@ -89,7 +89,7 @@ Spree::Admin::ProductsController.class_eval do
|
||||
|
||||
private
|
||||
|
||||
def load_bpe_data
|
||||
def load_form_data
|
||||
@producers = OpenFoodNetwork::Permissions.new(spree_current_user).managed_product_enterprises.is_primary_producer.by_name
|
||||
@taxons = Spree::Taxon.order(:name)
|
||||
end
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
Deface::Override.new(:virtual_path => "spree/admin/products/_form",
|
||||
:insert_top => "[data-hook='admin_product_form_right']",
|
||||
:partial => "spree/admin/products/supplier_form",
|
||||
:name => "add_supplier_to_admin_product",
|
||||
:original => '18bd94de3eb8bdf8b669932bf04fc59e2e85288b')
|
||||
@@ -0,0 +1,7 @@
|
||||
/ insert_top "[data-hook='admin_product_form_right']"
|
||||
|
||||
= f.field_container :supplier do
|
||||
= f.label :supplier
|
||||
%br
|
||||
= f.collection_select(:supplier_id, @producers, :id, :name, {:include_blank => true}, {:class => "select2"})
|
||||
= f.error_message_on :supplier
|
||||
@@ -7,7 +7,7 @@
|
||||
= f.field_container :supplier do
|
||||
= f.label :supplier_id, t(:supplier)
|
||||
%span.required *
|
||||
= f.collection_select(:supplier_id, Enterprise.is_primary_producer.managed_by(spree_current_user).by_name, :id, :name, {:include_blank => true}, {:class => "select2 fullwidth"})
|
||||
= f.collection_select(:supplier_id, @producers, :id, :name, {:include_blank => true}, {:class => "select2 fullwidth"})
|
||||
= f.error_message_on :supplier
|
||||
.six.columns.omega
|
||||
= f.field_container :name do
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
= f.field_container :supplier do
|
||||
= f.label :supplier
|
||||
%br
|
||||
= f.collection_select(:supplier_id, Enterprise.is_primary_producer.managed_by(spree_current_user).by_name, :id, :name, {:include_blank => true}, {:class => "select2"})
|
||||
= f.error_message_on :supplier
|
||||
@@ -744,8 +744,6 @@ feature %q{
|
||||
permissions_list: [:manage_products])
|
||||
end
|
||||
|
||||
use_short_wait
|
||||
|
||||
before do
|
||||
@enterprise_user = create_enterprise_user
|
||||
@enterprise_user.enterprise_roles.build(enterprise: supplier_managed1).save
|
||||
@@ -778,6 +776,28 @@ feature %q{
|
||||
expect(page).to have_field 'product_name', with: product_supplied_inactive.name
|
||||
end
|
||||
|
||||
it "allows me to create a product" do
|
||||
taxon = create(:taxon, name: 'Fruit')
|
||||
|
||||
visit '/admin/products/bulk_edit'
|
||||
|
||||
find("a", text: "NEW PRODUCT").click
|
||||
expect(page).to have_content 'NEW PRODUCT'
|
||||
expect(page).to have_select 'product_supplier_id', with_options: [supplier_managed1.name, supplier_managed2.name, supplier_permitted.name]
|
||||
|
||||
within 'fieldset#new_product' do
|
||||
fill_in 'product_name', with: 'Big Bag Of Apples'
|
||||
select supplier_permitted.name, from: 'product_supplier_id'
|
||||
fill_in 'product_price', with: '10.00'
|
||||
select taxon.name, from: 'product_primary_taxon_id'
|
||||
end
|
||||
click_button 'Create'
|
||||
|
||||
expect(URI.parse(current_url).path).to eq '/admin/products/bulk_edit'
|
||||
expect(flash_message).to eq 'Product "Big Bag Of Apples" has been successfully created!'
|
||||
expect(page).to have_field "product_name", with: 'Big Bag Of Apples'
|
||||
end
|
||||
|
||||
it "allows me to update a product" do
|
||||
p = product_supplied_permitted
|
||||
|
||||
|
||||
@@ -86,11 +86,14 @@ feature %q{
|
||||
|
||||
context "as an enterprise user" do
|
||||
|
||||
before(:each) do
|
||||
before do
|
||||
@new_user = create_enterprise_user
|
||||
@supplier2 = create(:supplier_enterprise, name: 'Another Supplier')
|
||||
@supplier_permitted = create(:supplier_enterprise, name: 'Permitted Supplier')
|
||||
@new_user.enterprise_roles.build(enterprise: @supplier2).save
|
||||
@new_user.enterprise_roles.build(enterprise: @distributors[0]).save
|
||||
create(:enterprise_relationship, parent: @supplier_permitted, child: @supplier2,
|
||||
permissions_list: [:manage_products])
|
||||
|
||||
login_to_admin_as @new_user
|
||||
end
|
||||
@@ -116,9 +119,8 @@ feature %q{
|
||||
select taxon.name, from: "product_primary_taxon_id"
|
||||
|
||||
# Should only have suppliers listed which the user can manage
|
||||
within "#product_supplier_id" do
|
||||
page.should_not have_content @supplier.name
|
||||
end
|
||||
page.should have_select 'product_supplier_id', with_options: [@supplier2.name, @supplier_permitted.name]
|
||||
page.should_not have_select 'product_supplier_id', with_options: [@supplier.name]
|
||||
|
||||
click_button 'Create'
|
||||
|
||||
@@ -127,6 +129,18 @@ feature %q{
|
||||
product.supplier.should == @supplier2
|
||||
end
|
||||
|
||||
scenario "editing a product" do
|
||||
product = create(:simple_product, name: 'a product', supplier: @supplier2)
|
||||
|
||||
visit spree.edit_admin_product_path product
|
||||
|
||||
select 'Permitted Supplier', from: 'product_supplier_id'
|
||||
click_button 'Update'
|
||||
flash_message.should == 'Product "a product" has been successfully updated!'
|
||||
product.reload
|
||||
product.supplier.should == @supplier_permitted
|
||||
end
|
||||
|
||||
scenario "editing product distributions" do
|
||||
product = create(:simple_product, supplier: @supplier2)
|
||||
|
||||
|
||||
@@ -12,5 +12,5 @@ describe "enterprise relationships", ->
|
||||
EnterpriseRelationships = _EnterpriseRelationships_
|
||||
|
||||
it "presents permission names", ->
|
||||
expect(EnterpriseRelationships.permission_presentation("add_to_order_cycle")).toEqual "can add to order cycle"
|
||||
expect(EnterpriseRelationships.permission_presentation("manage_products")).toEqual "can manage the products of"
|
||||
expect(EnterpriseRelationships.permission_presentation("add_to_order_cycle")).toEqual "to add to order cycle"
|
||||
expect(EnterpriseRelationships.permission_presentation("manage_products")).toEqual "to manage products"
|
||||
|
||||
@@ -8,18 +8,21 @@ describe "Hubs service", ->
|
||||
active: false
|
||||
orders_close_at: new Date()
|
||||
is_distributor: true
|
||||
has_shopfront: true
|
||||
}
|
||||
{
|
||||
id: 3
|
||||
active: false
|
||||
orders_close_at: new Date()
|
||||
is_distributor: true
|
||||
has_shopfront: true
|
||||
}
|
||||
{
|
||||
id: 1
|
||||
active: true
|
||||
orders_close_at: new Date()
|
||||
is_distributor: true
|
||||
has_shopfront: true
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -516,30 +516,44 @@ describe 'OrderCycle services', ->
|
||||
]
|
||||
|
||||
describe 'removing exchanges', ->
|
||||
it 'removes incoming exchanges', ->
|
||||
exchange = {enterprise_id: '123', active: true, variants: {}, enterprise_fees: []}
|
||||
OrderCycle.order_cycle.incoming_exchanges = [exchange]
|
||||
OrderCycle.removeExchange(exchange)
|
||||
expect(OrderCycle.order_cycle.incoming_exchanges).toEqual []
|
||||
exchange = null
|
||||
|
||||
it 'removes outgoing exchanges', ->
|
||||
exchange = {enterprise_id: '123', active: true, variants: {}, enterprise_fees: []}
|
||||
OrderCycle.order_cycle.outgoing_exchanges = [exchange]
|
||||
OrderCycle.removeExchange(exchange)
|
||||
expect(OrderCycle.order_cycle.outgoing_exchanges).toEqual []
|
||||
|
||||
it 'removes distribution of all exchange variants', ->
|
||||
beforeEach ->
|
||||
spyOn(OrderCycle, 'removeDistributionOfVariant')
|
||||
exchange =
|
||||
enterprise_id: '123'
|
||||
active: true
|
||||
incoming: false
|
||||
variants: {1: true, 2: false, 3: true}
|
||||
enterprise_fees: []
|
||||
OrderCycle.order_cycle.incoming_exchanges = [exchange]
|
||||
OrderCycle.removeExchange(exchange)
|
||||
expect(OrderCycle.removeDistributionOfVariant).toHaveBeenCalledWith('1')
|
||||
expect(OrderCycle.removeDistributionOfVariant).not.toHaveBeenCalledWith('2')
|
||||
expect(OrderCycle.removeDistributionOfVariant).toHaveBeenCalledWith('3')
|
||||
|
||||
describe "removing incoming exchanges", ->
|
||||
beforeEach ->
|
||||
exchange.incoming = true
|
||||
OrderCycle.order_cycle.incoming_exchanges = [exchange]
|
||||
|
||||
it 'removes the exchange', ->
|
||||
OrderCycle.removeExchange(exchange)
|
||||
expect(OrderCycle.order_cycle.incoming_exchanges).toEqual []
|
||||
|
||||
it 'removes distribution of all exchange variants', ->
|
||||
OrderCycle.removeExchange(exchange)
|
||||
expect(OrderCycle.removeDistributionOfVariant).toHaveBeenCalledWith('1')
|
||||
expect(OrderCycle.removeDistributionOfVariant).not.toHaveBeenCalledWith('2')
|
||||
expect(OrderCycle.removeDistributionOfVariant).toHaveBeenCalledWith('3')
|
||||
|
||||
describe "removing outgoing exchanges", ->
|
||||
beforeEach ->
|
||||
exchange.incoming = false
|
||||
OrderCycle.order_cycle.outgoing_exchanges = [exchange]
|
||||
|
||||
it 'removes the exchange', ->
|
||||
OrderCycle.removeExchange(exchange)
|
||||
expect(OrderCycle.order_cycle.outgoing_exchanges).toEqual []
|
||||
|
||||
it "does not remove distribution of any variants", ->
|
||||
OrderCycle.removeExchange(exchange)
|
||||
expect(OrderCycle.removeDistributionOfVariant).not.toHaveBeenCalled()
|
||||
|
||||
it 'adds coordinator fees', ->
|
||||
OrderCycle.addCoordinatorFee()
|
||||
|
||||
Reference in New Issue
Block a user