mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge pull request #3512 from kristinalim/fix/3478-scope_enterprise_fee_summary_to_eligible
3466,3478 [Enterprise Fee Summary] Scope report to eligible: true and non-zero adjustments
This commit is contained in:
@@ -17,7 +17,7 @@ module OrderManagement
|
||||
end
|
||||
|
||||
def result
|
||||
group_data.select_attributes
|
||||
group_data.exclude_groups_with_zero_total.select_attributes
|
||||
@scope.all
|
||||
end
|
||||
|
||||
@@ -46,7 +46,7 @@ module OrderManagement
|
||||
|
||||
def find_adjustments
|
||||
chain_to_scope do
|
||||
Spree::Adjustment
|
||||
Spree::Adjustment.eligible
|
||||
end
|
||||
end
|
||||
|
||||
@@ -336,6 +336,10 @@ module OrderManagement
|
||||
if params.payment_method_ids.present?
|
||||
end
|
||||
|
||||
def exclude_groups_with_zero_total
|
||||
filter_scope("spree_adjustments.amount != 0")
|
||||
end
|
||||
|
||||
def group_data
|
||||
chain_to_scope do
|
||||
group("enterprise_fees.id", "enterprises.id", "customers.id", "hubs.id",
|
||||
|
||||
@@ -151,6 +151,94 @@ describe OrderManagement::Reports::EnterpriseFeeSummary::ReportService do
|
||||
end
|
||||
end
|
||||
|
||||
describe "data exclusions" do
|
||||
describe "invalid adjustments (through 'eligible') like failed payments" do
|
||||
let!(:customer_order) { prepare_order(customer: customer) }
|
||||
|
||||
before do
|
||||
# Make the payment fail. See Spree::Payment#revoke_adjustment_eligibility.
|
||||
payment = customer_order.payments.first
|
||||
payment.state = "failed"
|
||||
payment.save!
|
||||
end
|
||||
|
||||
it "is included" do
|
||||
totals = service.list
|
||||
|
||||
expect(totals.length).to eq(1)
|
||||
|
||||
expected_result = [
|
||||
["Shipment", "Sample Distributor", "Sample Shipping Method", "Sample Customer",
|
||||
nil, nil, "Platform Rate", "1.00"]
|
||||
]
|
||||
|
||||
expected_result.each_with_index do |expected_attributes, row_index|
|
||||
expect_total_attributes(totals[row_index], expected_attributes)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "non-mandatory $0 adjustments (through 'eligible')" do
|
||||
let!(:variant) { prepare_variant(outgoing_exchange_fees: [enterprise_fee]) }
|
||||
|
||||
let!(:enterprise_fee) do
|
||||
create(:enterprise_fee, :per_item, name: "Sample Enterprise Fee", enterprise: distributor,
|
||||
fee_type: "admin", amount: 0)
|
||||
end
|
||||
|
||||
let!(:customer_order) { prepare_order(customer: customer) }
|
||||
|
||||
before do
|
||||
# Change "eligible" in enterprise fee adjustment to false. $0 adjustments that are not
|
||||
# mandatory are set to be ineligible, but there are no non-mandatory adjustments supported
|
||||
# by the report yet.
|
||||
adjustment = Spree::Adjustment.where(originator_type: "EnterpriseFee").first
|
||||
adjustment.eligible = false
|
||||
adjustment.save!
|
||||
end
|
||||
|
||||
it "is included" do
|
||||
totals = service.list
|
||||
|
||||
expect(totals.length).to eq(2)
|
||||
|
||||
expected_result = [
|
||||
["Payment Transaction", "Sample Distributor", "Sample Payment Method", "Sample Customer",
|
||||
nil, nil, nil, "2.00"],
|
||||
["Shipment", "Sample Distributor", "Sample Shipping Method", "Sample Customer",
|
||||
nil, nil, "Platform Rate", "1.00"]
|
||||
]
|
||||
|
||||
expected_result.each_with_index do |expected_attributes, row_index|
|
||||
expect_total_attributes(totals[row_index], expected_attributes)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "$0 mandatory adjustments" do
|
||||
let!(:payment_method) do
|
||||
create(:payment_method, :per_item, amount: 0, name: "Sample Payment Method")
|
||||
end
|
||||
|
||||
let!(:customer_order) { prepare_order(customer: customer) }
|
||||
|
||||
it "is included" do
|
||||
totals = service.list
|
||||
|
||||
expect(totals.length).to eq(1)
|
||||
|
||||
expected_result = [
|
||||
["Shipment", "Sample Distributor", "Sample Shipping Method", "Sample Customer",
|
||||
nil, nil, "Platform Rate", "1.00"]
|
||||
]
|
||||
|
||||
expected_result.each_with_index do |expected_attributes, row_index|
|
||||
expect_total_attributes(totals[row_index], expected_attributes)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "handling of more complex cases" do
|
||||
context "with non-sender fee for incoming exchange and non-receiver fee for outgoing" do
|
||||
let!(:variant) do
|
||||
|
||||
Reference in New Issue
Block a user