From c729f64fcff7152a425fa34944a6bf46758b0075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Sun, 24 May 2020 11:52:10 +0200 Subject: [PATCH] Include adjustments without positive taxes --- app/models/spree/order_decorator.rb | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 82609dccbc..32ad471fae 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -313,12 +313,14 @@ Spree::Order.class_eval do end def tax_adjustments - adjustments.with_tax + - line_items.includes(:adjustments).map { |li| li.adjustments.with_tax }.flatten + adjustments + price_adjustments end def tax_adjustment_totals tax_adjustments.each_with_object({}) do |adjustment, hash| + # No need of dealing with a missing Tax Rate if no tax setup + next if adjustment.included_tax.zero? + tax_rates = TaxRateFinder.tax_rates_of(adjustment) tax_rates_hash = Hash[tax_rates.collect do |tax_rate| tax_amount = tax_rates.one? ? adjustment.included_tax : tax_rate.compute_tax(adjustment.amount) @@ -328,21 +330,6 @@ Spree::Order.class_eval do end end - def price_adjustments - adjustments = [] - - line_items.each { |line_item| adjustments.concat line_item.adjustments } - - adjustments - end - - def price_adjustment_totals - Hash[tax_adjustment_totals.map do |tax_rate, tax_amount| - [tax_rate.name, - Spree::Money.new(tax_amount, currency: currency)] - end] - end - def has_taxes_included !line_items.with_tax.empty? end