diff --git a/backend/app/views/spree/admin/customer_returns/index.html.erb b/backend/app/views/spree/admin/customer_returns/index.html.erb index b566199e969..e795d8f138f 100644 --- a/backend/app/views/spree/admin/customer_returns/index.html.erb +++ b/backend/app/views/spree/admin/customer_returns/index.html.erb @@ -15,7 +15,7 @@ <%= Spree::CustomerReturn.human_attribute_name(:number) %> - <%= Spree::CustomerReturn.human_attribute_name(:pre_tax_total) %> + <%= Spree::CustomerReturn.human_attribute_name(:total_excluding_vat) %> <%= Spree::CustomerReturn.human_attribute_name(:total) %> <%= Spree::CustomerReturn.human_attribute_name(:created_at) %> <%= Spree::CustomerReturn.human_attribute_name(:reimbursement_status) %> @@ -26,7 +26,7 @@ <% @customer_returns.each do |customer_return| %> <%= link_to customer_return.number, edit_admin_order_customer_return_path(@order, customer_return) %> - <%= customer_return.display_pre_tax_total.to_html %> + <%= customer_return.display_total_excluding_vat.to_html %> <%= customer_return.display_total.to_html %> <%= pretty_time(customer_return.created_at) %> diff --git a/backend/app/views/spree/admin/return_authorizations/index.html.erb b/backend/app/views/spree/admin/return_authorizations/index.html.erb index b46a82a83f6..7710f4bcb6e 100644 --- a/backend/app/views/spree/admin/return_authorizations/index.html.erb +++ b/backend/app/views/spree/admin/return_authorizations/index.html.erb @@ -19,7 +19,7 @@ <%= Spree::ReturnAuthorization.human_attribute_name(:number) %> <%= Spree::ReturnAuthorization.human_attribute_name(:state) %> - <%= Spree::ReturnAuthorization.human_attribute_name(:pre_tax_total) %> + <%= Spree::ReturnAuthorization.human_attribute_name(:total_excluding_vat) %> <%= Spree::ReturnAuthorization.human_attribute_name(:created_at) %> @@ -36,7 +36,7 @@ ) %> - <%= return_authorization.display_pre_tax_total.to_html %> + <%= return_authorization.display_total_excluding_vat.to_html %> <%= pretty_time(return_authorization.created_at) %> <% if can? :update, return_authorization %> diff --git a/core/app/models/spree/customer_return.rb b/core/app/models/spree/customer_return.rb index 98df0a84407..dfdca75c834 100644 --- a/core/app/models/spree/customer_return.rb +++ b/core/app/models/spree/customer_return.rb @@ -16,7 +16,8 @@ class CustomerReturn < Spree::Base accepts_nested_attributes_for :return_items extend DisplayMoney - money_methods :pre_tax_total, :total, :amount + money_methods :pre_tax_total, :total, :total_excluding_vat, :amount + deprecate display_pre_tax_total: :display_total_excluding_vat, deprecator: Spree::Deprecation delegate :currency, to: :order delegate :id, to: :order, prefix: true, allow_nil: true @@ -25,9 +26,11 @@ def total return_items.map(&:total).sum end - def pre_tax_total - return_items.map(&:pre_tax_amount).sum + def total_excluding_vat + return_items.map(&:total_excluding_vat).sum end + alias pre_tax_total total_excluding_vat + deprecate pre_tax_total: :total_excluding_vat, deprecator: Spree::Deprecation def amount return_items.sum(:amount) diff --git a/core/app/models/spree/line_item.rb b/core/app/models/spree/line_item.rb index 055bea28359..49de946e485 100644 --- a/core/app/models/spree/line_item.rb +++ b/core/app/models/spree/line_item.rb @@ -59,30 +59,37 @@ def discounted_amount end deprecate discounted_amount: :total_before_tax, deprecator: Spree::Deprecation + # @return [BigDecimal] the amount of this line item, taking into + # consideration all its adjustments. + def total + amount + adjustment_total + end + alias final_amount total + deprecate final_amount: :total, deprecator: Spree::Deprecation + # @return [BigDecimal] the amount of this item, taking into consideration # all non-tax adjustments. def total_before_tax amount + adjustments.select { |a| !a.tax? && a.eligible? }.sum(&:amount) end - # @return [BigDecimal] the amount of this line item, taking into - # consideration all its adjustments. - def final_amount - amount + adjustment_total - end - alias total final_amount - - # @return [BigDecimal] the amount of this line item before included tax + # @return [BigDecimal] the amount of this line item before VAT tax # @note just like `amount`, this does not include any additional tax - def pre_tax_amount + def total_excluding_vat total_before_tax - included_tax_total end + alias pre_tax_amount total_excluding_vat + deprecate pre_tax_amount: :total_excluding_vat, deprecator: Spree::Deprecation extend Spree::DisplayMoney - money_methods :amount, :discounted_amount, :final_amount, :pre_tax_amount, :price, + money_methods :amount, :discounted_amount, :price, :included_tax_total, :additional_tax_total, - :total_before_tax + :total, :total_before_tax, :total_excluding_vat deprecate display_discounted_amount: :display_total_before_tax, deprecator: Spree::Deprecation + alias display_final_amount display_total + deprecate display_final_amount: :display_total, deprecator: Spree::Deprecation + alias display_pre_tax_amount display_total_excluding_vat + deprecate display_pre_tax_amount: :display_total_excluding_vat, deprecator: Spree::Deprecation alias discounted_money display_discounted_amount deprecate discounted_money: :display_total_before_tax, deprecator: Spree::Deprecation diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb index ed61e5cccd7..3aa064afa98 100644 --- a/core/app/models/spree/order.rb +++ b/core/app/models/spree/order.rb @@ -185,11 +185,6 @@ def amount line_items.map(&:amount).sum end - # Sum of all line item amounts pre-tax - def pre_tax_item_amount - line_items.to_a.sum(&:pre_tax_amount) - end - # Sum of all line item amounts after promotions, before added tax def discounted_item_amount line_items.to_a.sum(&:discounted_amount) @@ -200,6 +195,13 @@ def item_total_before_tax line_items.to_a.sum(&:total_before_tax) end + # Sum of all line item amounts pre-tax + def item_total_excluding_vat + line_items.to_a.sum(&:total_excluding_vat) + end + alias pre_tax_item_amount item_total_excluding_vat + deprecate pre_tax_item_amount: :item_total_excluding_vat, deprecator: Spree::Deprecation + def currency self[:currency] || Spree::Config[:currency] end diff --git a/core/app/models/spree/return_authorization.rb b/core/app/models/spree/return_authorization.rb index 8081bf220a4..d7bc6f021bb 100644 --- a/core/app/models/spree/return_authorization.rb +++ b/core/app/models/spree/return_authorization.rb @@ -29,13 +29,16 @@ class ReturnAuthorization < Spree::Base end extend DisplayMoney - money_methods :pre_tax_total, :amount + money_methods :pre_tax_total, :amount, :total_excluding_vat + deprecate display_pre_tax_total: :display_total_excluding_vat, deprecator: Spree::Deprecation self.whitelisted_ransackable_attributes = ['memo'] - def pre_tax_total - return_items.map(&:pre_tax_amount).sum + def total_excluding_vat + return_items.map(&:total_excluding_vat).sum end + alias pre_tax_total total_excluding_vat + deprecate pre_tax_total: :total_excluding_vat, deprecator: Spree::Deprecation def amount return_items.sum(:amount) diff --git a/core/app/models/spree/return_item.rb b/core/app/models/spree/return_item.rb index 9dee2133064..241ca010a0b 100644 --- a/core/app/models/spree/return_item.rb +++ b/core/app/models/spree/return_item.rb @@ -93,7 +93,8 @@ class ReturnItem < Spree::Base end extend DisplayMoney - money_methods :pre_tax_amount, :amount, :total + money_methods :pre_tax_amount, :amount, :total, :total_excluding_vat + deprecate display_pre_tax_amount: :display_total_excluding_vat, deprecator: Spree::Deprecation # @return [Boolean] true when this retur item is in a complete reception # state @@ -159,10 +160,12 @@ def total amount + additional_tax_total end - # @return [BigDecimal] the cost of the item before tax - def pre_tax_amount + # @return [BigDecimal] the cost of the item before VAT tax + def total_excluding_vat amount - included_tax_total end + alias pre_tax_amount total_excluding_vat + deprecate pre_tax_amount: :total_excluding_vat, deprecator: Spree::Deprecation # @note This uses the exchange_variant_engine configured on the class. # @param stock_locations [Array] the stock locations to check diff --git a/core/app/models/spree/shipment.rb b/core/app/models/spree/shipment.rb index 05fe9bca024..e47bd05e8a9 100644 --- a/core/app/models/spree/shipment.rb +++ b/core/app/models/spree/shipment.rb @@ -91,9 +91,10 @@ def can_transition_from_canceled_to_ready? extend DisplayMoney money_methods( :cost, :amount, :discounted_cost, :final_price, :item_cost, - :total_before_tax, + :total, :total_before_tax, ) deprecate display_discounted_cost: :display_total_before_tax, deprecator: Spree::Deprecation + deprecate display_final_price: :display_total, deprecator: Spree::Deprecation alias_attribute :amount, :cost def add_shipping_method(shipping_method, selected = false) @@ -124,19 +125,33 @@ def discounted_cost alias discounted_amount discounted_cost deprecate discounted_amount: :total_before_tax, deprecator: Spree::Deprecation + # @return [BigDecimal] the amount of this shipment, taking into + # consideration all its adjustments. + def total + cost + adjustment_total + end + alias final_price total + deprecate final_price: :total, deprecator: Spree::Deprecation + # @return [BigDecimal] the amount of this item, taking into consideration # all non-tax adjustments. def total_before_tax amount + adjustments.select { |a| !a.tax? && a.eligible? }.sum(&:amount) end - def final_price - cost + adjustment_total + # @return [BigDecimal] the amount of this shipment before VAT tax + # @note just like `cost`, this does not include any additional tax + def total_excluding_vat + total_before_tax - included_tax_total end + alias pre_tax_amount total_excluding_vat + deprecate pre_tax_amount: :total_excluding_vat, deprecator: Spree::Deprecation - def final_price_with_items - item_cost + final_price + def total_with_items + total + item_cost end + alias final_price_with_items total_with_items + deprecate final_price_with_items: :total_with_items, deprecator: Spree::Deprecation def editable_by?(_user) !shipped? @@ -168,17 +183,13 @@ def inventory_units_for_item(line_item, variant = nil) end def item_cost - line_items.map(&:final_amount).sum + line_items.map(&:total).sum end def line_items inventory_units.includes(:line_item).map(&:line_item).uniq end - def pre_tax_amount - total_before_tax - included_tax_total - end - def ready_or_pending? ready? || pending? end diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index c52b1af37d4..b2abe99f4e7 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -72,6 +72,7 @@ en: number: Return Number pre_tax_total: Pre-Tax Total total: Total + total_excluding_vat: Pre-Tax Total created_at: "Date/Time" reimbursement_status: Reimbursement status name: Name @@ -250,6 +251,7 @@ en: spree/return_authorization: amount: Amount pre_tax_total: Pre-Tax Total + total_excluding_vat: Pre-Tax Total spree/return_item: acceptance_status: Acceptance status acceptance_status_errors: Acceptance errors @@ -2017,6 +2019,7 @@ en: to: to to_add_variants_you_must_first_define: To add variants, you must first define total: Total + total_excluding_vat: Pre-Tax Total total_per_item: Total per item total_pre_tax_refund: Total Pre-Tax Refund total_price: Total price diff --git a/core/spec/models/spree/inventory_unit_spec.rb b/core/spec/models/spree/inventory_unit_spec.rb index 3aa7f448166..fdebb746d44 100644 --- a/core/spec/models/spree/inventory_unit_spec.rb +++ b/core/spec/models/spree/inventory_unit_spec.rb @@ -150,7 +150,7 @@ end describe "#current_or_new_return_item" do - before { allow(inventory_unit).to receive_messages(pre_tax_amount: 100.0) } + before { allow(inventory_unit).to receive_messages(total_excluding_vat: 100.0) } subject { inventory_unit.current_or_new_return_item } diff --git a/core/spec/models/spree/order/outstanding_balance_integration_spec.rb b/core/spec/models/spree/order/outstanding_balance_integration_spec.rb index 155ab079647..75623933dc1 100644 --- a/core/spec/models/spree/order/outstanding_balance_integration_spec.rb +++ b/core/spec/models/spree/order/outstanding_balance_integration_spec.rb @@ -63,7 +63,7 @@ context 'with a removed item' do before do - item_amount = item_1.final_amount + item_amount = item_1.total order.contents.remove(item_1.variant) create(:refund, payment: payment, amount: item_amount) end diff --git a/core/spec/models/spree/order_spec.rb b/core/spec/models/spree/order_spec.rb index 5147f0c24d1..fc9c41ada84 100644 --- a/core/spec/models/spree/order_spec.rb +++ b/core/spec/models/spree/order_spec.rb @@ -995,14 +995,14 @@ def generate end end - describe "#pre_tax_item_amount" do + describe "#item_total_excluding_vat" do it "sums all of the line items' pre tax amounts" do subject.line_items = [ Spree::LineItem.new(price: 10, quantity: 2, included_tax_total: 15.0), Spree::LineItem.new(price: 30, quantity: 1, included_tax_total: 16.0) ] # (2*10)-15 + 30-16 = 5 + 14 = 19 - expect(subject.pre_tax_item_amount).to eq 19.0 + expect(subject.item_total_excluding_vat).to eq 19.0 end end diff --git a/core/spec/models/spree/reimbursement_spec.rb b/core/spec/models/spree/reimbursement_spec.rb index 59854eb17f8..aa41a6596bb 100644 --- a/core/spec/models/spree/reimbursement_spec.rb +++ b/core/spec/models/spree/reimbursement_spec.rb @@ -121,8 +121,8 @@ return_item.reload expect(return_item.included_tax_total).to be > 0 expect(return_item.included_tax_total).to eq line_item.included_tax_total - expect(reimbursement.total).to eq((line_item.pre_tax_amount + line_item.included_tax_total).round(2, :down)) - expect(Spree::Refund.last.amount).to eq((line_item.pre_tax_amount + line_item.included_tax_total).round(2, :down)) + expect(reimbursement.total).to eq((line_item.total_excluding_vat + line_item.included_tax_total).round(2, :down)) + expect(Spree::Refund.last.amount).to eq((line_item.total_excluding_vat + line_item.included_tax_total).round(2, :down)) end end diff --git a/core/spec/models/spree/return_authorization_spec.rb b/core/spec/models/spree/return_authorization_spec.rb index 59fbbd7416f..4e3984cdb87 100644 --- a/core/spec/models/spree/return_authorization_spec.rb +++ b/core/spec/models/spree/return_authorization_spec.rb @@ -77,7 +77,7 @@ end end - describe "#pre_tax_total" do + describe "#total_excluding_vat" do let(:amount_1) { 15.0 } let!(:return_item_1) { create(:return_item, return_authorization: return_authorization, amount: amount_1) } @@ -87,17 +87,17 @@ let(:amount_3) { 5.0 } let!(:return_item_3) { create(:return_item, return_authorization: return_authorization, amount: amount_3) } - subject { return_authorization.reload.pre_tax_total } + subject { return_authorization.reload.total_excluding_vat } it "sums it's associated return_item's amounts" do expect(subject).to eq(amount_1 + amount_2 + amount_3) end end - describe "#display_pre_tax_total" do + describe "#display_total_excluding_vat" do it "returns a Spree::Money" do - allow(return_authorization).to receive_messages(pre_tax_total: 21.22) - expect(return_authorization.display_pre_tax_total).to eq(Spree::Money.new(21.22)) + allow(return_authorization).to receive_messages(total_excluding_vat: 21.22) + expect(return_authorization.display_total_excluding_vat).to eq(Spree::Money.new(21.22)) end end diff --git a/core/spec/models/spree/return_item_spec.rb b/core/spec/models/spree/return_item_spec.rb index 8756e08bd39..2f0b6b53443 100644 --- a/core/spec/models/spree/return_item_spec.rb +++ b/core/spec/models/spree/return_item_spec.rb @@ -140,13 +140,13 @@ end end - describe "#display_pre_tax_amount" do + describe "#display_total_excluding_vat" do let(:amount) { 21.22 } let(:included_tax_total) { 1.22 } let(:return_item) { build(:return_item, amount: amount, included_tax_total: included_tax_total) } it "returns a Spree::Money" do - expect(return_item.display_pre_tax_amount).to eq Spree::Money.new(amount - included_tax_total) + expect(return_item.display_total_excluding_vat).to eq Spree::Money.new(amount - included_tax_total) end end @@ -558,7 +558,7 @@ end end - describe "exchange pre_tax_amount" do + describe "exchange amount" do let(:return_item) { build(:return_item) } context "the return item is intended to be exchanged" do diff --git a/core/spec/models/spree/shipment_spec.rb b/core/spec/models/spree/shipment_spec.rb index 443476c9d29..cafd5ba39a2 100644 --- a/core/spec/models/spree/shipment_spec.rb +++ b/core/spec/models/spree/shipment_spec.rb @@ -105,10 +105,10 @@ end end - context "display_final_price" do + context "display_total" do it "retuns a Spree::Money" do - allow(shipment).to receive(:final_price) { 21.22 } - expect(shipment.display_final_price).to eq(Spree::Money.new(21.22)) + allow(shipment).to receive(:total) { 21.22 } + expect(shipment.display_total).to eq(Spree::Money.new(21.22)) end end @@ -177,12 +177,12 @@ expect(shipment.tax_total).to eq(10) end - it "#final_price" do + it "#total" do shipment = Spree::Shipment.new shipment.cost = 10 shipment.adjustment_total = -2 shipment.included_tax_total = 1 - expect(shipment.final_price).to eq(8) + expect(shipment.total).to eq(8) end context "manifest" do