From 0247386f82ea4bb27acf50b78e9cecbe9dd647a8 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 23 Jan 2021 00:05:56 +0000 Subject: [PATCH] Delete dead code Spree::Order#price_adjustments This method returns the same thing as the Spree::Order#line_items_adjustments scope, but in a slightly less useful format (an array instead of a relation). The method's name is also totally inaccurate, as currently the only adjustments that appear on line items are tax adjustments for inclusive tax rates, which by definition have no effect on the price whatsoever... --- app/models/spree/order.rb | 10 +--------- app/models/spree/tax_rate.rb | 4 ++-- app/views/spree/admin/orders/_form.html.haml | 2 +- spec/models/spree/adjustment_spec.rb | 2 +- 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index ceb603e275..6a884c78c9 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -723,15 +723,7 @@ module Spree end def total_tax - (adjustments.to_a + price_adjustments.to_a).sum(&:included_tax) - end - - def price_adjustments - adjustments = [] - - line_items.each { |line_item| adjustments.concat line_item.adjustments } - - adjustments + (adjustments.to_a + line_item_adjustments.to_a).sum(&:included_tax) end def price_adjustment_totals diff --git a/app/models/spree/tax_rate.rb b/app/models/spree/tax_rate.rb index 064baf8852..eeee5673aa 100644 --- a/app/models/spree/tax_rate.rb +++ b/app/models/spree/tax_rate.rb @@ -83,8 +83,8 @@ module Spree order.adjustments(:reload) order.line_items(:reload) # TaxRate adjustments (order.adjustments.tax) - # and price adjustments (tax included on line items) consist of 100% tax - (order.adjustments.tax + order.price_adjustments).each do |adjustment| + # and line item adjustments (tax included on line items) consist of 100% tax + (order.adjustments.tax + order.line_item_adjustments.reload).each do |adjustment| adjustment.set_absolute_included_tax! adjustment.amount end end diff --git a/app/views/spree/admin/orders/_form.html.haml b/app/views/spree/admin/orders/_form.html.haml index 3a0b74b56e..6bc77012bc 100644 --- a/app/views/spree/admin/orders/_form.html.haml +++ b/app/views/spree/admin/orders/_form.html.haml @@ -4,7 +4,7 @@ = render :partial => "spree/admin/orders/shipment", :collection => @order.shipments, :locals => { :order => order } - = render :partial => "spree/admin/orders/_form/adjustments", :locals => { :adjustments => @order.price_adjustments, :title => t(".line_item_adjustments")} + = render :partial => "spree/admin/orders/_form/adjustments", :locals => { :adjustments => @order.line_item_adjustments, :title => t(".line_item_adjustments")} = render :partial => "spree/admin/orders/_form/adjustments", :locals => { :adjustments => order_adjustments_for_display(@order), :title => t(".order_adjustments")} - if order.line_items.exists? diff --git a/spec/models/spree/adjustment_spec.rb b/spec/models/spree/adjustment_spec.rb index 1f77bd725b..de6bdb1f98 100644 --- a/spec/models/spree/adjustment_spec.rb +++ b/spec/models/spree/adjustment_spec.rb @@ -221,7 +221,7 @@ module Spree end it "does not crash when order data has been updated previously" do - order.price_adjustments.first.destroy + order.line_item_adjustments.first.destroy tax_rate.adjust(order) end end