mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-18 04:39:14 +00:00
Extract applicable_rate? and thus resolve rubocop complexity issue
This commit is contained in:
@@ -51,16 +51,17 @@ module Calculator
|
||||
def per_item_fees_total(order, calculator)
|
||||
order.line_items.sum do |line_item|
|
||||
calculator.per_item_enterprise_fee_applicators_for(line_item.variant)
|
||||
.select { |applicator|
|
||||
(!applicator.enterprise_fee.inherits_tax_category &&
|
||||
applicator.enterprise_fee.tax_category == rate.tax_category) ||
|
||||
(applicator.enterprise_fee.inherits_tax_category &&
|
||||
line_item.product.tax_category == rate.tax_category)
|
||||
}
|
||||
.select { |applicator| applicable_rate?(applicator, line_item) }
|
||||
.sum { |applicator| applicator.enterprise_fee.compute_amount(line_item) }
|
||||
end
|
||||
end
|
||||
|
||||
def applicable_rate?(applicator, line_item)
|
||||
fee = applicator.enterprise_fee
|
||||
(!fee.inherits_tax_category && fee.tax_category == rate.tax_category) ||
|
||||
(fee.inherits_tax_category && line_item.product.tax_category == rate.tax_category)
|
||||
end
|
||||
|
||||
# Finds relevant fees for whole order,
|
||||
# calculates the tax on them, and returns the total tax
|
||||
def per_order_fees_total(order, calculator)
|
||||
|
||||
Reference in New Issue
Block a user