From a15cb58ab5441323656b7e59f973cb77229dc581 Mon Sep 17 00:00:00 2001 From: Abdul Aziz Ali Date: Tue, 21 Jan 2025 06:53:42 +0800 Subject: [PATCH 1/4] fetch variant enterprise fees from order lineitems adjustments #11529 --- .../enterprise_fees_with_tax_report_by_producer.rb | 8 +++----- .../enterprise_fees_with_tax_report_by_producer_spec.rb | 1 - 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb index a9e487c2e7..4ee4d57d78 100644 --- a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb +++ b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb @@ -161,11 +161,9 @@ module Reporting # { variant: [enterprise_fee_ids] } def enterprise_fees_per_variant(order) hash = {} - order.order_cycle.exchanges.each do |exchange| - exchange.variants.each do |variant| - hash[variant] ||= order.order_cycle.coordinator_fee_ids - hash[variant] += exchange.enterprise_fee_ids - end + order.line_items.each do |li| + hash[li.variant] ||= order.order_cycle.coordinator_fee_ids + hash[li.variant] += li.adjustments.enterprise_fee.map(&:originator_id) end hash end diff --git a/spec/lib/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer_spec.rb b/spec/lib/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer_spec.rb index ae58f2e211..db4004a158 100644 --- a/spec/lib/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer_spec.rb +++ b/spec/lib/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer_spec.rb @@ -55,7 +55,6 @@ RSpec.describe Reporting::Reports::EnterpriseFeeSummary::EnterpriseFeesWithTaxRe report = described_class.new(current_user) - pending "https://github.com/openfoodfoundation/openfoodnetwork/issues/11529" expect(report.query_result.values).to eq [[order]] end end From 6a525c18ac6e1f04b4cc0f66db97190947b6e1c5 Mon Sep 17 00:00:00 2001 From: Abdul Aziz Ali Date: Wed, 19 Mar 2025 08:23:30 +0800 Subject: [PATCH 2/4] remove incoming exchange filtering #11529 --- .../enterprise_fees_with_tax_report_by_producer.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb index 4ee4d57d78..da4aaf8683 100644 --- a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb +++ b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb @@ -85,7 +85,6 @@ module Reporting query = order .all_adjustments .enterprise_fee - .where(originator_id: enterprise_fees_related_to_incoming_exchanges_ids(order)) if enterprise_fee_filters? query = query.where(originator_id: enterprise_fee_filtered_ids) From abe4c5e0da223916104f49cb6e15cc9b963107ba Mon Sep 17 00:00:00 2001 From: Abdul Aziz Ali Date: Fri, 28 Mar 2025 18:21:23 +0800 Subject: [PATCH 3/4] Filter fees by metadata.enterprise_role 'supplier' #11529 --- .../enterprise_fees_with_tax_report_by_producer.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb index da4aaf8683..2145e040d7 100644 --- a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb +++ b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb @@ -85,6 +85,8 @@ module Reporting query = order .all_adjustments .enterprise_fee + .joins(:metadata) + .where(adjustment_metadata: { enterprise_role: 'supplier' }) if enterprise_fee_filters? query = query.where(originator_id: enterprise_fee_filtered_ids) From 8b34505b36d37c18167570d776550b111c8ecc58 Mon Sep 17 00:00:00 2001 From: Abdul Aziz Ali Date: Fri, 28 Mar 2025 19:12:09 +0800 Subject: [PATCH 4/4] Fix query group and pluck #11529 --- .../enterprise_fees_with_tax_report_by_producer.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb index 2145e040d7..e4116030e0 100644 --- a/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb +++ b/lib/reporting/reports/enterprise_fee_summary/enterprise_fees_with_tax_report_by_producer.rb @@ -91,8 +91,8 @@ module Reporting if enterprise_fee_filters? query = query.where(originator_id: enterprise_fee_filtered_ids) end - query.group('originator_id') - .pluck("originator_id", 'array_agg(id)') + query.group('spree_adjustments.id', 'originator_id') + .pluck("originator_id", 'array_agg(spree_adjustments.id)') .map do |enterprise_fee_id, enterprise_fee_adjustment_ids| { enterprise_fee_id:,