Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3283 [Enterprise Fee Summary] Receiver as "Fee Calc on Transfer Through" for incoming exchange fees #3319

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -282,7 +282,7 @@ def include_outgoing_exchange_details
join_scope(
<<-JOIN_STRING.strip_heredoc
LEFT OUTER JOIN enterprises AS outgoing_exchange_enterprises
ON (outgoing_exchange_enterprises.id = outgoing_exchanges.sender_id)
ON (outgoing_exchange_enterprises.id = outgoing_exchanges.receiver_id)
JOIN_STRING
)
end
Expand Down
Expand Up @@ -116,9 +116,9 @@
["Admin", "Sample Coordinator", "Coordinator Fee 1", "Sample Customer",
"Coordinator", "All", "Sample Coordinator Tax", "1024.00"],
["Admin", "Sample Distributor", "Distributor Fee 1", "Another Customer",
"Outgoing", "Sample Coordinator", "Sample Distributor Tax", "4.00"],
"Outgoing", "Sample Distributor", "Sample Distributor Tax", "4.00"],
["Admin", "Sample Distributor", "Distributor Fee 1", "Sample Customer",
"Outgoing", "Sample Coordinator", "Sample Distributor Tax", "8.00"],
"Outgoing", "Sample Distributor", "Sample Distributor Tax", "8.00"],
["Payment Transaction", "Sample Distributor", "Sample Payment Method", "Another Customer",
nil, nil, nil, "2.00"],
["Payment Transaction", "Sample Distributor", "Sample Payment Method", "Sample Customer",
Expand All @@ -128,9 +128,9 @@
["Sales", "Sample Coordinator", "Coordinator Fee 2", "Sample Customer",
"Coordinator", "All", "Sample Product Tax", "2048.00"],
["Sales", "Sample Distributor", "Distributor Fee 2", "Another Customer",
"Outgoing", "Sample Coordinator", "Sample Product Tax", "8.00"],
"Outgoing", "Sample Distributor", "Sample Product Tax", "8.00"],
["Sales", "Sample Distributor", "Distributor Fee 2", "Sample Customer",
"Outgoing", "Sample Coordinator", "Sample Product Tax", "16.00"],
"Outgoing", "Sample Distributor", "Sample Product Tax", "16.00"],
["Sales", "Sample Producer", "Producer Fee 1", "Another Customer",
"Incoming", "Sample Producer", "Sample Producer Tax", "64.00"],
["Sales", "Sample Producer", "Producer Fee 1", "Sample Customer",
Expand All @@ -151,6 +151,63 @@
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
prepare_variant(incoming_exchange_fees: variant_incoming_exchange_fees,
outgoing_exchange_fees: variant_outgoing_exchange_fees)
end
let!(:variant_incoming_exchange_fees) { [coordinator_fee, distributor_fee] }
let!(:variant_outgoing_exchange_fees) { [producer_fee, coordinator_fee] }

let!(:producer_fee) do
tax_category = create(:tax_category, name: "Sample Producer Tax")
create(:enterprise_fee, :per_item, name: "Sample Producer Fee", enterprise: producer,
fee_type: "sales", amount: 64.0,
tax_category: tax_category)
end
let!(:coordinator_fee) do
tax_category = create(:tax_category, name: "Sample Coordinator Tax")
create(:enterprise_fee, :per_item, name: "Sample Coordinator Fee", enterprise: coordinator,
fee_type: "admin", amount: 512.0,
tax_category: tax_category)
end
let!(:distributor_fee) do
tax_category = create(:tax_category, name: "Sample Distributor Tax")
create(:enterprise_fee, :per_item, name: "Sample Distributor Fee", enterprise: distributor,
fee_type: "admin", amount: 4.0,
tax_category: tax_category)
end

let!(:customer_order) { prepare_order(customer: customer) }

it "fetches data correctly" do
totals = service.list

expect(totals.length).to eq(6)

expected_result = [
["Admin", "Sample Coordinator", "Sample Coordinator Fee", "Sample Customer",
"Incoming", "Sample Producer", "Sample Coordinator Tax", "512.00"],
["Admin", "Sample Coordinator", "Sample Coordinator Fee", "Sample Customer",
"Outgoing", "Sample Distributor", "Sample Coordinator Tax", "512.00"],
["Admin", "Sample Distributor", "Sample Distributor Fee", "Sample Customer",
"Incoming", "Sample Producer", "Sample Distributor Tax", "4.00"],
["Payment Transaction", "Sample Distributor", "Sample Payment Method", "Sample Customer",
nil, nil, nil, "2.00"],
["Sales", "Sample Producer", "Sample Producer Fee", "Sample Customer",
"Outgoing", "Sample Distributor", "Sample Producer Tax", "64.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
end

describe "filtering results based on permissions" do
let!(:distributor_a) do
create(:distributor_enterprise, name: "Distributor A", payment_methods: [payment_method],
Expand Down