diff --git a/lib/reporting/reports/suppliers/helpers/line_items_access_helper.rb b/lib/reporting/reports/suppliers/helpers/line_items_access_helper.rb index 937f6cb7a1..809efb0540 100644 --- a/lib/reporting/reports/suppliers/helpers/line_items_access_helper.rb +++ b/lib/reporting/reports/suppliers/helpers/line_items_access_helper.rb @@ -27,13 +27,13 @@ module Reporting def suppliers_adjustments(line_item, adjustment_type = 'EnterpriseFee') adjustments = line_item.adjustments - return adjustments if adjustment_type == 'Spree::TaxRate' + return adjustments.tax if adjustment_type == 'Spree::TaxRate' - supplier_name = supplier(line_item).name - adjustments.select do |adjustment| + supplier_id = supplier(line_item).id + adjustments.enterprise_fee.select do |adjustment| label = adjustment.label - - label.include?('supplier') && label.include?(supplier_name) + adjustment_enterprise_id = adjustment.originator.enterprise.id + label.include?('supplier') && adjustment_enterprise_id == supplier_id end end @@ -41,10 +41,8 @@ module Reporting total_amount = 0.0 adjustment_type = type == :tax ? 'Spree::TaxRate' : 'EnterpriseFee' suppliers_adjustments(line_item, adjustment_type).each do |adjustment| - if adjustment.originator_type == adjustment_type - amount = included == adjustment.included ? adjustment.amount : 0.0 - total_amount += amount - end + amount = included == adjustment.included ? adjustment.amount : 0.0 + total_amount += amount end total_amount @@ -53,11 +51,7 @@ module Reporting def tax_on_fees(line_item, included: false) total_amount = 0.0 suppliers_adjustments(line_item).each do |adjustment| - next unless adjustment.originator_type == 'EnterpriseFee' - - adjustment.adjustments.each do |fee_adjustment| - next unless fee_adjustment.originator_type == 'Spree::TaxRate' - + adjustment.adjustments.tax.each do |fee_adjustment| amount = included == fee_adjustment.included ? fee_adjustment.amount : 0.0 total_amount += amount end