12776: refactor supplier_adjustments method

This commit is contained in:
Ahmed Ejaz
2024-11-12 00:55:19 +05:00
committed by Rachel Arnould
parent f3e086ad59
commit bc57447d54

View File

@@ -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