mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-30 21:27:17 +00:00
Merge pull request #11688 from mkllnk/enterprise-fee-report
Avoid error when generating Enterprise fees w/ Tax Report by Producer
This commit is contained in:
@@ -138,7 +138,7 @@ module Reporting
|
||||
filtered_line_items(order)
|
||||
.filter do |line_item|
|
||||
item[:enterprise_fee_id].in?(
|
||||
enterprise_fees_per_variant[line_item.variant]
|
||||
enterprise_fees_per_variant.fetch(line_item.variant, [])
|
||||
)
|
||||
end
|
||||
.map do |line_item|
|
||||
|
||||
@@ -100,12 +100,6 @@ describe Reporting::Reports::EnterpriseFeeSummary::FeeSummary do
|
||||
let!(:second_customer_order) { prepare_order(customer:) }
|
||||
let!(:other_customer_order) { prepare_order(customer: another_customer) }
|
||||
|
||||
it "doesn't delete params" do
|
||||
params = ActionController::Parameters.new("completed_at_gt" => "2023-02-08+00:00")
|
||||
described_class.new(current_user, params)
|
||||
expect(params["completed_at_gt"]).to eq "2023-02-08+00:00"
|
||||
end
|
||||
|
||||
it "groups and sorts entries correctly" do
|
||||
totals = subject.query_result
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "spec_helper"
|
||||
|
||||
describe Reporting::Reports::EnterpriseFeeSummary::EnterpriseFeesWithTaxReportByProducer do
|
||||
let(:current_user) { create(:admin_user) }
|
||||
|
||||
let(:enterprise) {
|
||||
create(:distributor_enterprise_with_tax, is_primary_producer: true,
|
||||
shipping_methods: [shipping_method])
|
||||
}
|
||||
let(:shipping_method) { create(:shipping_method) }
|
||||
let(:order_cycle) {
|
||||
create(:simple_order_cycle, coordinator: enterprise).tap do |order_cycle|
|
||||
incoming = order_cycle.exchanges.create!(incoming: true, sender: enterprise,
|
||||
receiver: enterprise)
|
||||
outgoing = order_cycle.exchanges.create!(incoming: false, sender: enterprise,
|
||||
receiver: enterprise)
|
||||
|
||||
supplier_fee = create(:enterprise_fee, :per_item, enterprise:, amount: 15,
|
||||
name: 'Transport',
|
||||
fee_type: 'transport',)
|
||||
incoming.exchange_fees.create!(enterprise_fee: supplier_fee)
|
||||
|
||||
incoming.exchange_variants.create(variant:)
|
||||
outgoing.exchange_variants.create(variant:)
|
||||
end
|
||||
}
|
||||
let(:variant) { create(:product, supplier: enterprise).variants.first }
|
||||
let(:order) {
|
||||
create(
|
||||
:order, :with_line_item,
|
||||
variant:, distributor: enterprise, order_cycle:,
|
||||
shipping_method:, ship_address: create(:address)
|
||||
).tap do |order|
|
||||
order.recreate_all_fees!
|
||||
OrderWorkflow.new(order).complete!
|
||||
end
|
||||
}
|
||||
|
||||
it "renders an empty report" do
|
||||
report = described_class.new(current_user)
|
||||
expect(report.query_result).to eq({})
|
||||
end
|
||||
|
||||
it "lists orders" do
|
||||
order
|
||||
report = described_class.new(current_user)
|
||||
expect(report.query_result.values).to eq [[order]]
|
||||
end
|
||||
|
||||
it "handles products removed from the order cycle" do
|
||||
order
|
||||
order_cycle.exchanges.incoming.first.exchange_variants.first.destroy!
|
||||
|
||||
report = described_class.new(current_user)
|
||||
|
||||
pending "https://github.com/openfoodfoundation/openfoodnetwork/issues/11529"
|
||||
expect(report.query_result.values).to eq [[order]]
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user