mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #12847 from dacook/fix-bug-12835
Fix bug #12835 for producer reports
This commit is contained in:
@@ -243,7 +243,7 @@ module Spree
|
||||
can [:admin, :index], ::Admin::DfcProductImportsController
|
||||
|
||||
# Reports page
|
||||
can [:admin, :index, :show], ::Admin::ReportsController
|
||||
can [:admin, :index, :show, :create], ::Admin::ReportsController
|
||||
can [:admin, :show, :create, :customers, :orders_and_distributors, :group_buys, :payments,
|
||||
:orders_and_fulfillment, :products_and_inventory, :order_cycle_management,
|
||||
:packing, :enterprise_fee_summary, :bulk_coop], :report
|
||||
|
||||
@@ -7,12 +7,12 @@ module Reporting
|
||||
module OrdersAndFulfillment
|
||||
RSpec.describe OrderCycleSupplierTotalsByDistributor do
|
||||
let!(:distributor) { create(:distributor_enterprise) }
|
||||
let!(:order) do
|
||||
create(:completed_order_with_totals, line_items_count: 3, distributor:)
|
||||
end
|
||||
let(:supplier) { order.line_items.first.variant.supplier }
|
||||
let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor]) }
|
||||
|
||||
describe "as the distributor" do
|
||||
let!(:order) do
|
||||
create(:completed_order_with_totals, line_items_count: 3, distributor:)
|
||||
end
|
||||
let(:current_user) { distributor.owner }
|
||||
let(:params) { { display_summary_row: true } }
|
||||
let(:report) do
|
||||
@@ -42,18 +42,32 @@ module Reporting
|
||||
end
|
||||
end
|
||||
|
||||
describe "as the supplier of the order cycle" do
|
||||
describe "as the supplier permitting products in the order cycle" do
|
||||
let!(:order) {
|
||||
create(:completed_order_with_totals, line_items_count: 0, distributor:,
|
||||
order_cycle_id: order_cycle.id)
|
||||
}
|
||||
let(:supplier){ order.line_items.first.variant.supplier }
|
||||
|
||||
before do
|
||||
pending("S2 bug fix - #12835")
|
||||
3.times do
|
||||
owner = create(:user)
|
||||
s = create(:supplier_enterprise, owner:)
|
||||
variant = create(:variant, supplier: s)
|
||||
create(:line_item_with_shipment, variant:, quantity: 1, order:)
|
||||
end
|
||||
|
||||
create(:enterprise_relationship, parent: supplier, child: distributor,
|
||||
permissions_list: [:add_to_order_cycle])
|
||||
end
|
||||
|
||||
let!(:current_user) { supplier.owner }
|
||||
let!(:params) { { display_summary_row: true } }
|
||||
let!(:report) do
|
||||
let(:current_user) { supplier.owner }
|
||||
let(:params) { { display_summary_row: true } }
|
||||
let(:report) do
|
||||
OrderCycleSupplierTotalsByDistributor.new(current_user, params)
|
||||
end
|
||||
|
||||
let!(:report_table) do
|
||||
let(:report_table) do
|
||||
report.table_rows
|
||||
end
|
||||
|
||||
|
||||
@@ -415,7 +415,7 @@ RSpec.describe Spree::Ability do
|
||||
|
||||
it "should be able to read some reports" do
|
||||
is_expected.to have_ability(
|
||||
[:admin, :index, :show], for: Admin::ReportsController
|
||||
[:admin, :index, :show, :create], for: Admin::ReportsController
|
||||
)
|
||||
is_expected.to have_ability(
|
||||
[:customers, :bulk_coop, :orders_and_fulfillment, :products_and_inventory,
|
||||
@@ -651,7 +651,7 @@ RSpec.describe Spree::Ability do
|
||||
|
||||
it "should be able to read some reports" do
|
||||
is_expected.to have_ability(
|
||||
[:admin, :index, :show], for: Admin::ReportsController
|
||||
[:admin, :index, :show, :create], for: Admin::ReportsController
|
||||
)
|
||||
is_expected.to have_ability(
|
||||
[:customers, :sales_tax, :group_buys, :bulk_coop, :payments,
|
||||
|
||||
@@ -423,14 +423,18 @@ RSpec.describe "Orders And Fulfillment" do
|
||||
end
|
||||
end
|
||||
|
||||
context "as the supplier" do
|
||||
context "as the supplier granting P-OC to distributor" do
|
||||
let(:current_user) { supplier.owner }
|
||||
|
||||
before do
|
||||
pending("S2 bug fix - #12835")
|
||||
create(:enterprise_relationship, parent: supplier, child: distributor,
|
||||
permissions_list: [:add_to_order_cycle])
|
||||
|
||||
login_as(current_user)
|
||||
visit admin_reports_path
|
||||
click_link "Order Cycle Supplier Totals by Distributor"
|
||||
visit admin_report_path(:orders_and_fulfillment,
|
||||
:order_cycle_supplier_totals_by_distributor)
|
||||
|
||||
uncheck "Header Row"
|
||||
run_report
|
||||
end
|
||||
|
||||
@@ -456,24 +460,20 @@ RSpec.describe "Orders And Fulfillment" do
|
||||
end
|
||||
|
||||
it "aggregates results per variant" do
|
||||
expect(all('table.report__table tbody tr').count).to eq(4)
|
||||
rows = find("table.report__table").all("tbody tr")
|
||||
table = rows.map { |r| r.all("td").map { |c| c.text.strip } }
|
||||
|
||||
expect(table.count).to eq(4)
|
||||
# 1 row per variant = 2 rows
|
||||
# 2 TOTAL rows
|
||||
# 2 TOTAL rows for distributors
|
||||
# 4 rows total
|
||||
|
||||
expect(table_headers[0]).to eq(
|
||||
["Supplier Name", "Baked Beans", "1g Small",
|
||||
"Distributor Name", "7", "10.0", "70.0", "UPS Ground"]
|
||||
)
|
||||
expect(table_headers[1]).to eq(
|
||||
["", "", "", "TOTAL", "7", "", "70.0", ""]
|
||||
)
|
||||
expect(table_headers[2]).to eq(
|
||||
["Supplier Name", "Baked Beans", "1g Big",
|
||||
"Distributor Name",
|
||||
"3", "10.0", "30.0", "UPS Ground"]
|
||||
)
|
||||
expect(table_headers[3]).to eq(["", "", "", "TOTAL", "3", "", "30.0", ""])
|
||||
expect(table[0]).to eq(["Supplier Name", "Baked Beans", "1g Big",
|
||||
"Distributor Name", "3", "10.0", "30.0", "UPS Ground"])
|
||||
expect(table[1]).to eq(["", "", "", "TOTAL", "3", "", "30.0", ""])
|
||||
expect(table[2]).to eq(["Supplier Name", "Baked Beans", "1g Small",
|
||||
"Distributor Name", "7", "10.0", "70.0", "UPS Ground"])
|
||||
expect(table[3]).to eq(["", "", "", "TOTAL", "7", "", "70.0", ""])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user