mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
fix aggregation of taxes for taxes on adjustments
This commit is contained in:
committed by
Rob Harrington
parent
d22f5678be
commit
3fc2070b2c
@@ -44,8 +44,8 @@ module CheckoutHelper
|
||||
end
|
||||
|
||||
def display_checkout_taxes_hash(order)
|
||||
order.tax_adjustment_totals.each_with_object(Hash.new) do |(tax_rate, tax_value), acc|
|
||||
acc[number_to_percentage(tax_rate.amount * 100, :precision => 1)] = Spree::Money.new tax_value, currency: order.currency
|
||||
order.tax_adjustment_totals.each_with_object(Hash.new) do |(tax_rate, tax_amount), hash|
|
||||
hash[number_to_percentage(tax_rate * 100, :precision => 1)] = Spree::Money.new tax_amount, currency: order.currency
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ require 'open_food_network/variant_and_line_item_naming'
|
||||
Spree::LineItem.class_eval do
|
||||
include OpenFoodNetwork::VariantAndLineItemNaming
|
||||
has_and_belongs_to_many :option_values, join_table: 'spree_option_values_line_items', class_name: 'Spree::OptionValue'
|
||||
has_many :tax_adjustments, class_name: "Adjustment", conditions: "spree_adjustments.originator_type = 'Spree::TaxRate'", as: :adjustable
|
||||
|
||||
attr_accessible :max_quantity, :final_weight_volume, :price
|
||||
attr_accessible :final_weight_volume, :price, :as => :api
|
||||
|
||||
@@ -229,16 +229,20 @@ Spree::Order.class_eval do
|
||||
|
||||
def tax_adjustments
|
||||
adjustments.with_tax +
|
||||
line_items.includes(:tax_adjustments).map {|li| li.tax_adjustments}.flatten
|
||||
line_items.includes(:adjustments).map {|li| li.adjustments.with_tax }.flatten
|
||||
end
|
||||
|
||||
def tax_adjustment_totals
|
||||
Hash[tax_adjustments.group_by(&:label).map do |label, adjustments|
|
||||
[adjustments.first.originator, adjustments.sum(&:amount)]
|
||||
end]
|
||||
tax_adjustments.each_with_object(Hash.new) do |adjustment, hash|
|
||||
if adjustment.originator_type == "Spree::TaxRate"
|
||||
tax_rate = adjustment.originator.amount
|
||||
else
|
||||
tax_rate = (adjustment.included_tax / (adjustment.amount - adjustment.included_tax)).round(2)
|
||||
end
|
||||
hash.update({tax_rate => adjustment.included_tax}) { |_tax_rate, amount1, amount2| amount1 + amount2 }
|
||||
end
|
||||
end
|
||||
|
||||
# Uses the first associated tax to determine if taxes are included in price
|
||||
def has_taxes_included
|
||||
not line_items.with_tax.empty?
|
||||
end
|
||||
|
||||
@@ -26,7 +26,7 @@ module OpenFoodNetwork
|
||||
else
|
||||
[I18n.t(:report_header_order_number),
|
||||
I18n.t(:report_header_total_excl_vat, currency_symbol: currency_symbol)] +
|
||||
relevant_rates.map { |rate| "%s (%.1f%%) (%s)" % [rate.name, rate.amount.to_f * 100, currency_symbol] } +
|
||||
relevant_rates.map { |rate| "%.1f%% (%s)" % [rate.to_f * 100, currency_symbol] } +
|
||||
[I18n.t(:report_header_total_tax, currency_symbol: currency_symbol),
|
||||
I18n.t(:report_header_total_incl_vat, currency_symbol: currency_symbol)]
|
||||
end
|
||||
@@ -66,9 +66,7 @@ module OpenFoodNetwork
|
||||
|
||||
def relevant_rates
|
||||
return @relevant_rates unless @relevant_rates.nil?
|
||||
item_rate_ids = search.result.joins(:line_items => {:adjustments => :tax_rate}).select('spree_tax_rates.id').uniq
|
||||
order_rate_ids = search.result.joins(:adjustments => :tax_rate).select('spree_tax_rates.id').uniq
|
||||
@relevant_rates = Spree::TaxRate.where(id: item_rate_ids | order_rate_ids)
|
||||
@relevant_rates = Spree::TaxRate.pluck(:amount).uniq
|
||||
end
|
||||
|
||||
def totals_of(line_items)
|
||||
|
||||
Reference in New Issue
Block a user