mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-07 22:46:06 +00:00
23 lines
528 B
Ruby
23 lines
528 B
Ruby
# frozen_string_literal: true
|
|
|
|
# Collects Tax Adjustments related to an order, and returns a hash with a total for each rate.
|
|
|
|
module Orders
|
|
class FetchTaxAdjustmentsService
|
|
def initialize(order)
|
|
@order = order
|
|
end
|
|
|
|
def totals(tax_adjustments = order.all_adjustments.tax)
|
|
tax_adjustments.each_with_object({}) do |adjustment, hash|
|
|
tax_rate = adjustment.originator
|
|
hash[tax_rate] = hash[tax_rate].to_f + adjustment.amount
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
attr_reader :order
|
|
end
|
|
end
|