mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Bulk product edit lists managed products
This commit is contained in:
@@ -19,7 +19,9 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
def managed_products
|
||||
Spree::Product.managed_by(@user)
|
||||
managed_enterprise_products_ids = managed_enterprise_products.pluck :id
|
||||
permitted_enterprise_products_ids = related_enterprise_products.pluck :id
|
||||
Spree::Product.where('id IN (?)', managed_enterprise_products_ids + permitted_enterprise_products_ids)
|
||||
end
|
||||
|
||||
|
||||
@@ -37,5 +39,13 @@ module OpenFoodNetwork
|
||||
|
||||
Enterprise.where('id IN (?)', parent_ids)
|
||||
end
|
||||
|
||||
def managed_enterprise_products
|
||||
Spree::Product.managed_by(@user)
|
||||
end
|
||||
|
||||
def related_enterprise_products
|
||||
Spree::Product.where('supplier_id IN (?)', related_enterprises_with(:manage_products))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -732,12 +732,21 @@ feature %q{
|
||||
let(:supplier_managed1) { create(:supplier_enterprise, name: 'Supplier Managed 1') }
|
||||
let(:supplier_managed2) { create(:supplier_enterprise, name: 'Supplier Managed 2') }
|
||||
let(:supplier_unmanaged) { create(:supplier_enterprise, name: 'Supplier Unmanaged') }
|
||||
let(:supplier_permitted) { create(:supplier_enterprise, name: 'Supplier Permitted') }
|
||||
let(:distributor_managed) { create(:distributor_enterprise, name: 'Distributor Managed') }
|
||||
let(:distributor_unmanaged) { create(:distributor_enterprise, name: 'Distributor Unmanaged') }
|
||||
let!(:product_supplied) { create(:product, supplier: supplier_managed1, price: 10.0, on_hand: 6) }
|
||||
let!(:product_not_supplied) { create(:product, supplier: supplier_unmanaged) }
|
||||
let!(:product_supplied_permitted) { create(:product, name: 'Product Permitted', supplier: supplier_permitted, price: 10.0, on_hand: 6) }
|
||||
let(:product_supplied_inactive) { create(:product, supplier: supplier_managed1, price: 10.0, on_hand: 6, available_on: 1.week.from_now) }
|
||||
|
||||
let!(:supplier_permitted_relationship) do
|
||||
create(:enterprise_relationship, parent: supplier_permitted, child: supplier_managed1,
|
||||
permissions_list: [:manage_products])
|
||||
end
|
||||
|
||||
use_short_wait
|
||||
|
||||
before do
|
||||
@enterprise_user = create_enterprise_user
|
||||
@enterprise_user.enterprise_roles.build(enterprise: supplier_managed1).save
|
||||
@@ -751,6 +760,7 @@ feature %q{
|
||||
visit '/admin/products/bulk_edit'
|
||||
|
||||
expect(page).to have_field 'product_name', with: product_supplied.name
|
||||
expect(page).to have_field 'product_name', with: product_supplied_permitted.name
|
||||
expect(page).to have_no_field 'product_name', with: product_not_supplied.name
|
||||
end
|
||||
|
||||
@@ -782,13 +792,15 @@ feature %q{
|
||||
expect(page).to have_field "price", with: "10.0"
|
||||
expect(page).to have_field "on_hand", with: "6"
|
||||
|
||||
fill_in "product_name", with: "Big Bag Of Potatoes"
|
||||
select(supplier_managed2.name, :from => 'producer')
|
||||
fill_in "available_on", with: (Date.today-3).strftime("%F %T")
|
||||
fill_in "price", with: "20"
|
||||
select "Weight (kg)", from: "variant_unit_with_scale"
|
||||
fill_in "on_hand", with: "18"
|
||||
fill_in "display_as", with: "Big Bag"
|
||||
within("tr#p_#{product_supplied.id}") do
|
||||
fill_in "product_name", with: "Big Bag Of Potatoes"
|
||||
select(supplier_managed2.name, :from => 'producer')
|
||||
fill_in "available_on", with: (Date.today-3).strftime("%F %T")
|
||||
fill_in "price", with: "20"
|
||||
select "Weight (kg)", from: "variant_unit_with_scale"
|
||||
fill_in "on_hand", with: "18"
|
||||
fill_in "display_as", with: "Big Bag"
|
||||
end
|
||||
|
||||
click_button 'Save Changes'
|
||||
expect(page.find("#update-status-message")).to have_content "Changes saved."
|
||||
|
||||
@@ -55,6 +55,26 @@ module OpenFoodNetwork
|
||||
end
|
||||
end
|
||||
|
||||
describe "finding managed products" do
|
||||
let!(:p1) { create(:simple_product) }
|
||||
let!(:p2) { create(:simple_product) }
|
||||
|
||||
before do
|
||||
permissions.stub(:managed_enterprise_products) { Spree::Product.where('1=0') }
|
||||
permissions.stub(:related_enterprise_products) { Spree::Product.where('1=0') }
|
||||
end
|
||||
|
||||
it "returns products produced by managed enterprises" do
|
||||
permissions.stub(:managed_enterprise_products) { Spree::Product.where(id: p1) }
|
||||
permissions.managed_products.should == [p1]
|
||||
end
|
||||
|
||||
it "returns products produced by permitted enterprises" do
|
||||
permissions.stub(:related_enterprise_products) { Spree::Product.where(id: p2) }
|
||||
permissions.managed_products.should == [p2]
|
||||
end
|
||||
end
|
||||
|
||||
########################################
|
||||
|
||||
describe "finding related enterprises with a particular permission" do
|
||||
@@ -70,5 +90,16 @@ module OpenFoodNetwork
|
||||
permissions.send(:related_enterprises_with, permission).should == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "finding the supplied products of related enterprises" do
|
||||
let!(:e) { create(:enterprise) }
|
||||
let!(:p) { create(:simple_product, supplier: e) }
|
||||
|
||||
it "returns supplied products" do
|
||||
permissions.should_receive(:related_enterprises_with).with(:manage_products) { [e] }
|
||||
|
||||
permissions.send(:related_enterprise_products).should == [p]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user