diff --git a/app/controllers/spree/admin/adjustments_controller.rb b/app/controllers/spree/admin/adjustments_controller.rb index 3cfb5787e9..10909f805f 100644 --- a/app/controllers/spree/admin/adjustments_controller.rb +++ b/app/controllers/spree/admin/adjustments_controller.rb @@ -9,7 +9,6 @@ module Spree before_action :set_order_id, only: [:create, :update] before_action :skip_changing_canceled_orders, only: [:create, :update] after_action :update_order, only: [:create, :update, :destroy] - before_action :set_default_tax_rate, only: :edit private @@ -42,34 +41,6 @@ module Spree redirect_to admin_order_adjustments_path(@order) if @order.canceled? end - # Choose a default tax rate to show on the edit form. The adjustment stores its included - # tax in dollars, but doesn't store the source of the tax (ie. TaxRate that generated it). - # We guess which tax rate here, choosing: - # 1. A tax rate that will compute to the same amount as the existing tax - # 2. If that's not present, the first tax rate that's valid for the current order - # When we have to go with 2, we show an error message to ask the admin to check that the - # correct tax is being applied. - def set_default_tax_rate - return if @adjustment.included_tax <= 0 - - tax_rates = TaxRate.match(@order) - tax_rate_with_matching_tax = find_tax_rate_with_matching_tax(tax_rates) - tax_rate_valid_for_order = tax_rates.first.andand.id - - @tax_rate_id = tax_rate_with_matching_tax || tax_rate_valid_for_order - - return unless tax_rate_with_matching_tax.nil? - - @adjustment.errors.add :tax_rate_id, I18n.t(:adjustments_tax_rate_error) - end - - def find_tax_rate_with_matching_tax(tax_rates) - tax_rates_yielding_matching_tax = tax_rates.select do |tr| - tr.compute_tax(@adjustment.amount) == @adjustment.included_tax - end - tax_rates_yielding_matching_tax.first.andand.id - end - def set_included_tax included_tax = 0 if params[:tax_rate_id].present?