diff --git a/backend/app/controllers/spree/admin/return_authorizations_controller.rb b/backend/app/controllers/spree/admin/return_authorizations_controller.rb
index f191b3ff0d..914304da66 100644
--- a/backend/app/controllers/spree/admin/return_authorizations_controller.rb
+++ b/backend/app/controllers/spree/admin/return_authorizations_controller.rb
@@ -30,7 +30,7 @@ def load_return_items
unassociated_inventory_units = all_inventory_units - associated_inventory_units
new_return_items = unassociated_inventory_units.map do |new_unit|
- Spree::ReturnItem.new(inventory_unit: new_unit).tap(&:set_default_pre_tax_amount)
+ Spree::ReturnItem.new(inventory_unit: new_unit).tap(&:set_default_amount)
end
@form_return_items = (@return_authorization.return_items + new_return_items).sort_by(&:inventory_unit_id)
end
diff --git a/backend/app/views/spree/admin/customer_returns/_return_item_decision.html.erb b/backend/app/views/spree/admin/customer_returns/_return_item_decision.html.erb
index c1d45383be..fe4271d8d7 100644
--- a/backend/app/views/spree/admin/customer_returns/_return_item_decision.html.erb
+++ b/backend/app/views/spree/admin/customer_returns/_return_item_decision.html.erb
@@ -3,7 +3,7 @@
<%= Spree::Product.model_name.human %> |
<%= Spree::Variant.human_attribute_name(:sku) %> |
- <%= Spree::ReturnItem.human_attribute_name(:pre_tax_amount) %> |
+ <%= Spree::ReturnItem.human_attribute_name(:amount) %> |
<%= Spree::ReturnItem.human_attribute_name(:preferred_reimbursement_type) %> |
<%= Spree::ReturnItem.human_attribute_name(:exchange_variant) %> |
<%= Spree::ReturnItem.human_attribute_name(:acceptance_status_errors) %> |
@@ -27,7 +27,7 @@
<%= return_item.inventory_unit.variant.sku %>
- <%= return_item.display_pre_tax_amount %>
+ <%= return_item.display_amount %>
|
<%= reimbursement_type_name(return_item.preferred_reimbursement_type) %>
diff --git a/backend/app/views/spree/admin/customer_returns/_return_item_selection.html.erb b/backend/app/views/spree/admin/customer_returns/_return_item_selection.html.erb
index 259e0507be..5091969a42 100644
--- a/backend/app/views/spree/admin/customer_returns/_return_item_selection.html.erb
+++ b/backend/app/views/spree/admin/customer_returns/_return_item_selection.html.erb
@@ -6,7 +6,7 @@
| <%= Spree::Product.model_name.human %> |
<%= Spree::Variant.human_attribute_name(:sku) %> |
- <%= Spree::ReturnItem.human_attribute_name(:pre_tax_amount) %> |
+ <%= Spree::ReturnItem.human_attribute_name(:amount) %> |
<%= Spree::ReturnItem.human_attribute_name(:inventory_unit_state) %> |
<%= Spree::ReturnItem.human_attribute_name(:exchange_variant) %> |
<%= Spree::ReturnItem.human_attribute_name(:resellable) %> |
@@ -23,9 +23,9 @@
<%= item_fields.hidden_field :inventory_unit_id %>
<%= item_fields.hidden_field :return_authorization_id %>
- <%= item_fields.hidden_field :pre_tax_amount %>
+ <%= item_fields.hidden_field :amount %>
- <%= item_fields.check_box :returned, {checked: false, class: 'add-item', "data-price" => return_item.pre_tax_amount}, '1', '0' %>
+ <%= item_fields.check_box :returned, {checked: false, class: 'add-item', "data-price" => return_item.amount}, '1', '0' %>
<%= return_item.inventory_unit.variant.name %>
@@ -35,7 +35,7 @@
<%= return_item.inventory_unit.variant.sku %>
|
- <%= return_item.display_pre_tax_amount %>
+ <%= return_item.display_amount %>
|
<%= return_item.inventory_unit.state %>
diff --git a/backend/app/views/spree/admin/reimbursements/edit.html.erb b/backend/app/views/spree/admin/reimbursements/edit.html.erb
index 4db8274783..bf94935411 100644
--- a/backend/app/views/spree/admin/reimbursements/edit.html.erb
+++ b/backend/app/views/spree/admin/reimbursements/edit.html.erb
@@ -44,7 +44,7 @@
) %>
|
- <%= item_fields.text_field :pre_tax_amount, { class: 'refund-amount-input' } %>
+ <%= item_fields.text_field :amount, { class: 'refund-amount-input' } %>
|
<%= return_item.display_total %>
diff --git a/backend/app/views/spree/admin/reimbursements/show.html.erb b/backend/app/views/spree/admin/reimbursements/show.html.erb
index 7e098dbcd2..d55b630304 100644
--- a/backend/app/views/spree/admin/reimbursements/show.html.erb
+++ b/backend/app/views/spree/admin/reimbursements/show.html.erb
@@ -19,7 +19,7 @@
| <%= Spree.t(:preferred_reimbursement_type) %> |
<%= Spree.t(:reimbursement_type_override) %> |
<%= Spree.t(:exchange_for) %> |
- <%= Spree.t(:pre_tax_amount) %> |
+ <%= Spree.t(:amount) %> |
<%= Spree.t(:total) %> |
@@ -41,7 +41,7 @@
<%= return_item.exchange_variant.try(:exchange_name) %>
- <%= return_item.display_pre_tax_amount %>
+ <%= return_item.display_amount %>
|
<%= return_item.display_total %>
diff --git a/backend/app/views/spree/admin/return_authorizations/_form.html.erb b/backend/app/views/spree/admin/return_authorizations/_form.html.erb
index b1ea07fff0..584cd1a5ba 100644
--- a/backend/app/views/spree/admin/return_authorizations/_form.html.erb
+++ b/backend/app/views/spree/admin/return_authorizations/_form.html.erb
@@ -27,7 +27,7 @@
|
<% if editable %>
<%= item_fields.hidden_field :inventory_unit_id %>
- <%= item_fields.check_box :_destroy, {checked: return_item.persisted?, class: 'add-item', "data-price" => return_item.pre_tax_amount}, '0', '1' %>
+ <%= item_fields.check_box :_destroy, {checked: return_item.persisted?, class: 'add-item', "data-price" => return_item.amount}, '0', '1' %>
<% end %>
|
@@ -36,13 +36,13 @@
|
<%= inventory_unit.state.humanize %> |
- <%= return_item.display_pre_tax_amount %>
+ <%= return_item.display_amount %>
|
<% if editable %>
- <%= item_fields.text_field :pre_tax_amount, { class: 'refund-amount-input' } %>
+ <%= item_fields.text_field :amount, { class: 'refund-amount-input' } %>
<% else %>
- <%= return_item.display_pre_tax_amount %>
+ <%= return_item.display_amount %>
<% end %>
|
diff --git a/backend/spec/controllers/spree/admin/customer_returns_controller_spec.rb b/backend/spec/controllers/spree/admin/customer_returns_controller_spec.rb
index 63efb005f8..c97f2815b6 100644
--- a/backend/spec/controllers/spree/admin/customer_returns_controller_spec.rb
+++ b/backend/spec/controllers/spree/admin/customer_returns_controller_spec.rb
@@ -193,7 +193,7 @@ module Admin
return_items_attributes: {
"0" => {
returned: "1",
- "pre_tax_amount" => "15.99",
+ amount: "15.99",
inventory_unit_id: order.inventory_units.shipped.last.id,
reception_status_event: reception_status_event
}
diff --git a/core/app/models/spree/calculator/returns/default_refund_amount.rb b/core/app/models/spree/calculator/returns/default_refund_amount.rb
index 96cf2563a5..013ff4c9e1 100644
--- a/core/app/models/spree/calculator/returns/default_refund_amount.rb
+++ b/core/app/models/spree/calculator/returns/default_refund_amount.rb
@@ -9,7 +9,7 @@ def self.description
def compute(return_item)
return 0.0.to_d if return_item.part_of_exchange?
- weighted_order_adjustment_amount(return_item.inventory_unit) + weighted_line_item_pre_tax_amount(return_item.inventory_unit)
+ weighted_order_adjustment_amount(return_item.inventory_unit) + weighted_line_item_amount(return_item.inventory_unit)
end
private
@@ -18,18 +18,18 @@ def weighted_order_adjustment_amount(inventory_unit)
inventory_unit.order.adjustments.eligible.non_tax.sum(:amount) * percentage_of_order_total(inventory_unit)
end
- def weighted_line_item_pre_tax_amount(inventory_unit)
- inventory_unit.line_item.pre_tax_amount * percentage_of_line_item(inventory_unit)
+ def weighted_line_item_amount(inventory_unit)
+ inventory_unit.line_item.discounted_amount * percentage_of_line_item(inventory_unit)
end
def percentage_of_order_total(inventory_unit)
- return 0.0 if inventory_unit.order.pre_tax_item_amount.zero?
- weighted_line_item_pre_tax_amount(inventory_unit) / inventory_unit.order.pre_tax_item_amount
+ return 0.0 if inventory_unit.order.discounted_item_amount.zero?
+ weighted_line_item_amount(inventory_unit) / inventory_unit.order.discounted_item_amount
end
def percentage_of_line_item(inventory_unit)
1 / BigDecimal.new(inventory_unit.line_item.quantity)
end
- end
- end
+ end
+ end
end
diff --git a/core/app/models/spree/customer_return.rb b/core/app/models/spree/customer_return.rb
index 7f32a6ec96..fcdb7d8c3f 100644
--- a/core/app/models/spree/customer_return.rb
+++ b/core/app/models/spree/customer_return.rb
@@ -17,7 +17,8 @@ class CustomerReturn < Spree::Base
extend DisplayMoney
money_methods pre_tax_total: { currency: Spree::Config[:currency] },
- total: { currency: Spree::Config[:currency] }
+ total: { currency: Spree::Config[:currency] },
+ amount: { currency: Spree::Config[:currency] }
delegate :id, to: :order, prefix: true, allow_nil: true
@@ -26,7 +27,11 @@ def total
end
def pre_tax_total
- return_items.sum(:pre_tax_amount)
+ return_items.map(&:pre_tax_amount).sum
+ end
+
+ def amount
+ return_items.sum(:amount)
end
# Temporarily tie a customer_return to one order
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index 958aa7bfd4..540f7a0741 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -162,6 +162,11 @@ 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)
+ end
+
def currency
self[:currency] || Spree::Config[:currency]
end
diff --git a/core/app/models/spree/reimbursement_tax_calculator.rb b/core/app/models/spree/reimbursement_tax_calculator.rb
index 0a42a3e31d..0f5ae1c157 100644
--- a/core/app/models/spree/reimbursement_tax_calculator.rb
+++ b/core/app/models/spree/reimbursement_tax_calculator.rb
@@ -18,7 +18,7 @@ def call(reimbursement)
private
def set_tax!(return_item)
- percent_of_tax = (return_item.pre_tax_amount <= 0) ? 0 : return_item.pre_tax_amount / Spree::ReturnItem.refund_amount_calculator.new.compute(return_item)
+ percent_of_tax = (return_item.amount <= 0) ? 0 : return_item.amount / Spree::ReturnItem.refund_amount_calculator.new.compute(return_item)
additional_tax_total = percent_of_tax * return_item.inventory_unit.additional_tax_total
included_tax_total = percent_of_tax * return_item.inventory_unit.included_tax_total
diff --git a/core/app/models/spree/return_authorization.rb b/core/app/models/spree/return_authorization.rb
index b8195b2b79..ce1e83eb52 100644
--- a/core/app/models/spree/return_authorization.rb
+++ b/core/app/models/spree/return_authorization.rb
@@ -34,12 +34,16 @@ class ReturnAuthorization < Spree::Base
end
extend DisplayMoney
- money_methods :pre_tax_total
+ money_methods :pre_tax_total, :amount
self.whitelisted_ransackable_attributes = ['memo']
def pre_tax_total
- return_items.sum(:pre_tax_amount)
+ return_items.map(&:pre_tax_amount).sum
+ end
+
+ def amount
+ return_item.sum(:amount)
end
def currency
@@ -47,7 +51,7 @@ def currency
end
def refundable_amount
- order.pre_tax_item_amount + order.promo_total
+ order.discounted_item_amount + order.promo_total
end
def customer_returned_items?
diff --git a/core/app/models/spree/return_item.rb b/core/app/models/spree/return_item.rb
index 6d9d7ffd0a..986a79d84a 100644
--- a/core/app/models/spree/return_item.rb
+++ b/core/app/models/spree/return_item.rb
@@ -72,8 +72,8 @@ class ReturnItem < Spree::Base
delegate :variant, to: :inventory_unit
delegate :shipment, to: :inventory_unit
- before_create :set_default_pre_tax_amount, unless: :pre_tax_amount_changed?
- before_save :set_exchange_pre_tax_amount
+ before_create :set_default_amount, unless: :amount_changed?
+ before_save :set_exchange_amount
state_machine :reception_status, initial: :awaiting do
after_transition to: COMPLETED_RECEPTION_STATUSES, do: :attempt_accept
@@ -93,7 +93,7 @@ class ReturnItem < Spree::Base
end
extend DisplayMoney
- money_methods :pre_tax_amount, :total
+ money_methods :pre_tax_amount, :amount, :total
# @return [Boolean] true when this retur item is in a complete reception
# state
@@ -133,7 +133,7 @@ def reception_completed?
# unit if one exists, or a new one if one does not
def self.from_inventory_unit(inventory_unit)
valid.find_by(inventory_unit: inventory_unit) ||
- new(inventory_unit: inventory_unit).tap(&:set_default_pre_tax_amount)
+ new(inventory_unit: inventory_unit).tap(&:set_default_amount)
end
# @return [Boolean] true when an exchange has been requested on this return
@@ -154,10 +154,14 @@ def exchange_required?
exchange_requested? && !exchange_processed?
end
- # @return [BigDecimal] the cost of the item before tax, plus the included
- # and additional taxes
+ # @return [BigDecimal] the cost of the item after tax
def total
- pre_tax_amount + included_tax_total + additional_tax_total
+ amount + additional_tax_total
+ end
+
+ # @return [BigDecimal] the cost of the item before tax
+ def pre_tax_amount
+ amount - included_tax_total
end
# @note This uses the exchange_variant_engine configured on the class.
@@ -185,12 +189,12 @@ def exchange_shipment
exchange_inventory_unit.try(:shipment)
end
- # Calculates and sets the default pre-tax amount to be refunded.
+ # Calculates and sets the default amount to be refunded.
#
# @note This uses the configured refund_amount_calculator configured on the
# class.
- def set_default_pre_tax_amount
- self.pre_tax_amount = refund_amount_calculator.new.compute(self)
+ def set_default_amount
+ self.amount = refund_amount_calculator.new.compute(self)
end
def potential_reception_transitions
@@ -240,7 +244,7 @@ def check_unexchange
original_ri = sibling_intended_for_exchange('awaiting')
if original_ri
original_ri.unexchange!
- set_default_pre_tax_amount
+ set_default_amount
save!
end
end
@@ -276,8 +280,8 @@ def validate_acceptance_status_for_reimbursement
end
end
- def set_exchange_pre_tax_amount
- self.pre_tax_amount = 0.0.to_d if exchange_requested?
+ def set_exchange_amount
+ self.amount = 0.0.to_d if exchange_requested?
end
def validate_no_other_completed_return_items
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index 2d7f1465e7..32f91f6183 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -184,7 +184,7 @@ en:
exchange_variant: Exchange for
inventory_unit_state: State
item_received?: "Item Received?"
- pre_tax_amount: Pre-Tax Amount
+ pre_tax_amount: Amount before sales tax
preferred_reimbursement_type_id: Preferred Reimbursement Type
reception_status: Reception Status
resellable: "Resellable?"
diff --git a/core/db/migrate/20151026093607_change_return_item_pre_tax_amount_to_amount.rb b/core/db/migrate/20151026093607_change_return_item_pre_tax_amount_to_amount.rb
new file mode 100644
index 0000000000..8e328195f1
--- /dev/null
+++ b/core/db/migrate/20151026093607_change_return_item_pre_tax_amount_to_amount.rb
@@ -0,0 +1,27 @@
+class ChangeReturnItemPreTaxAmountToAmount < ActiveRecord::Migration
+ def up
+ execute(<<-SQL)
+ UPDATE spree_return_items
+ SET included_tax_total = 0
+ WHERE included_tax_total IS NULL;
+
+ UPDATE spree_return_items
+ SET pre_tax_amount = pre_tax_amount + included_tax_total;
+ SQL
+
+ rename_column :spree_return_items, :pre_tax_amount, :amount
+ end
+
+ def down
+ execute(<<-SQL)
+ UPDATE spree_return_items
+ SET included_tax_total = 0
+ WHERE included_tax_total IS NULL;
+
+ UPDATE spree_return_items
+ SET amount = amount - included_tax_total;
+ SQL
+
+ rename_column :spree_return_items, :amount, :pre_tax_amount
+ end
+end
diff --git a/core/lib/spree/permitted_attributes.rb b/core/lib/spree/permitted_attributes.rb
index 53e0147e7c..d0b59be1e8 100644
--- a/core/lib/spree/permitted_attributes.rb
+++ b/core/lib/spree/permitted_attributes.rb
@@ -52,7 +52,7 @@ module PermittedAttributes
:month, :year, :expiry, :first_name, :last_name, :name
]
- @@customer_return_attributes = [:stock_location_id, return_items_attributes: [:id, :inventory_unit_id, :return_authorization_id, :returned, :pre_tax_amount, :reception_status_event, :acceptance_status, :exchange_variant_id, :resellable]]
+ @@customer_return_attributes = [:stock_location_id, return_items_attributes: [:id, :inventory_unit_id, :return_authorization_id, :returned, :amount, :reception_status_event, :acceptance_status, :exchange_variant_id, :resellable]]
@@image_attributes = [:alt, :attachment, :position, :viewable_type, :viewable_id]
diff --git a/core/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb b/core/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb
index f5ae21d4b6..9431231438 100644
--- a/core/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb
+++ b/core/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb
@@ -1,21 +1,19 @@
require 'spec_helper'
describe Spree::Calculator::Returns::DefaultRefundAmount, type: :model do
- let(:order) { create(:order) }
let(:line_item_quantity) { 2 }
- let(:pre_tax_amount) { 100.0 }
- let(:line_item) { create(:line_item, price: 100.0, quantity: line_item_quantity, pre_tax_amount: pre_tax_amount) }
+ let(:line_item_price) { 100.0 }
+ let(:line_item) { create(:line_item, price: line_item_price, quantity: line_item_quantity) }
let(:inventory_unit) { build(:inventory_unit, order: order, line_item: line_item) }
let(:return_item) { build(:return_item, inventory_unit: inventory_unit ) }
let(:calculator) { Spree::Calculator::Returns::DefaultRefundAmount.new }
-
- before { order.line_items << line_item }
+ let(:order) { line_item.order }
subject { calculator.compute(return_item) }
context "not an exchange" do
context "no promotions or taxes" do
- it { is_expected.to eq pre_tax_amount / line_item_quantity }
+ it { is_expected.to eq line_item_price }
end
context "order adjustments" do
@@ -35,7 +33,7 @@
order.adjustments.first.update_attributes(amount: adjustment_amount)
end
- it { is_expected.to eq((pre_tax_amount - adjustment_amount.abs) / line_item_quantity) }
+ it { is_expected.to eq line_item_price - (adjustment_amount.abs / line_item_quantity) }
end
context "shipping adjustments" do
@@ -43,7 +41,7 @@
before { order.shipments << Spree::Shipment.new(adjustment_total: adjustment_total) }
- it { is_expected.to eq pre_tax_amount / line_item_quantity }
+ it { is_expected.to eq line_item_price }
end
end
@@ -53,8 +51,8 @@
it { is_expected.to eq 0.0 }
end
- context "pre_tax_amount is zero" do
- let(:pre_tax_amount) { 0.0 }
+ context "line item amount is zero" do
+ let(:line_item_price) { 0 }
it { is_expected.to eq 0.0 }
end
end
diff --git a/core/spec/models/spree/customer_return_spec.rb b/core/spec/models/spree/customer_return_spec.rb
index 7247eb90eb..edde017dd3 100644
--- a/core/spec/models/spree/customer_return_spec.rb
+++ b/core/spec/models/spree/customer_return_spec.rb
@@ -72,19 +72,19 @@
end
describe "#total" do
- let(:pre_tax_amount) { 15.0 }
+ let(:amount) { 15.0 }
let(:tax_amount) { 5.0 }
let(:customer_return) { create(:customer_return, line_items_count: 2) }
before do
- Spree::ReturnItem.where(customer_return_id: customer_return.id).update_all(pre_tax_amount: pre_tax_amount, additional_tax_total: tax_amount)
+ Spree::ReturnItem.where(customer_return_id: customer_return.id).update_all(amount: amount, additional_tax_total: tax_amount)
customer_return.reload
end
subject { customer_return.total }
it "returns the sum of the return item's total amount" do
- expect(subject).to eq((pre_tax_amount * 2) + (tax_amount * 2))
+ expect(subject).to eq((amount * 2) + (tax_amount * 2))
end
end
@@ -97,27 +97,27 @@
end
end
- describe "#pre_tax_total" do
- let(:pre_tax_amount) { 15.0 }
+ describe "#amount" do
+ let(:amount) { 15.0 }
let(:customer_return) { create(:customer_return, line_items_count: 2) }
before do
- Spree::ReturnItem.where(customer_return_id: customer_return.id).update_all(pre_tax_amount: pre_tax_amount)
+ Spree::ReturnItem.where(customer_return_id: customer_return.id).update_all(amount: amount)
end
- subject { customer_return.pre_tax_total }
+ subject { customer_return.amount }
- it "returns the sum of the return item's pre_tax_amount" do
- expect(subject).to eq(pre_tax_amount * 2)
+ it "returns the sum of the return item's amount" do
+ expect(subject).to eq(amount * 2)
end
end
- describe "#display_pre_tax_total" do
+ describe "#display_amount" do
let(:customer_return) { Spree::CustomerReturn.new }
it "returns a Spree::Money" do
- allow(customer_return).to receive_messages(pre_tax_total: 21.22)
- expect(customer_return.display_pre_tax_total).to eq(Spree::Money.new(21.22))
+ allow(customer_return).to receive_messages(amount: 21.22)
+ expect(customer_return.display_amount).to eq(Spree::Money.new(21.22))
end
end
diff --git a/core/spec/models/spree/reimbursement_spec.rb b/core/spec/models/spree/reimbursement_spec.rb
index 828bcfb096..9adcdc3a64 100644
--- a/core/spec/models/spree/reimbursement_spec.rb
+++ b/core/spec/models/spree/reimbursement_spec.rb
@@ -106,8 +106,8 @@
return_item.reload
expect(return_item.additional_tax_total).to be > 0
expect(return_item.additional_tax_total).to eq line_item.additional_tax_total
- expect(reimbursement.total).to eq line_item.pre_tax_amount + line_item.additional_tax_total
- expect(Spree::Refund.last.amount).to eq line_item.pre_tax_amount + line_item.additional_tax_total
+ expect(reimbursement.total).to eq line_item.amount + line_item.additional_tax_total
+ expect(Spree::Refund.last.amount).to eq line_item.amount + line_item.additional_tax_total
end
end
@@ -192,8 +192,8 @@
subject { reimbursement.calculated_total }
before do
- reimbursement.return_items << Spree::ReturnItem.new(pre_tax_amount: 10.003)
- reimbursement.return_items << Spree::ReturnItem.new(pre_tax_amount: 10.003)
+ reimbursement.return_items << Spree::ReturnItem.new(amount: 10.003)
+ reimbursement.return_items << Spree::ReturnItem.new(amount: 10.003)
end
it 'rounds down' do
diff --git a/core/spec/models/spree/reimbursement_type/original_payment_spec.rb b/core/spec/models/spree/reimbursement_type/original_payment_spec.rb
index 550c12078c..e0a3d90166 100644
--- a/core/spec/models/spree/reimbursement_type/original_payment_spec.rb
+++ b/core/spec/models/spree/reimbursement_type/original_payment_spec.rb
@@ -61,7 +61,7 @@ module Spree
before do
reimbursement.order.payments.first.update_attributes!(amount: 5.0)
- return_item.update_attributes!(pre_tax_amount: refund_amount)
+ return_item.update_attributes!(amount: refund_amount)
end
it "includes refunds all payment type" do
diff --git a/core/spec/models/spree/return_authorization_spec.rb b/core/spec/models/spree/return_authorization_spec.rb
index 8ac9797f19..3f9bc0325a 100644
--- a/core/spec/models/spree/return_authorization_spec.rb
+++ b/core/spec/models/spree/return_authorization_spec.rb
@@ -137,19 +137,19 @@
end
describe "#pre_tax_total" do
- let(:pre_tax_amount_1) { 15.0 }
- let!(:return_item_1) { create(:return_item, return_authorization: return_authorization, pre_tax_amount: pre_tax_amount_1) }
+ let(:amount_1) { 15.0 }
+ let!(:return_item_1) { create(:return_item, return_authorization: return_authorization, amount: amount_1) }
- let(:pre_tax_amount_2) { 50.0 }
- let!(:return_item_2) { create(:return_item, return_authorization: return_authorization, pre_tax_amount: pre_tax_amount_2) }
+ let(:amount_2) { 50.0 }
+ let!(:return_item_2) { create(:return_item, return_authorization: return_authorization, amount: amount_2) }
- let(:pre_tax_amount_3) { 5.0 }
- let!(:return_item_3) { create(:return_item, return_authorization: return_authorization, pre_tax_amount: pre_tax_amount_3) }
+ let(:amount_3) { 5.0 }
+ let!(:return_item_3) { create(:return_item, return_authorization: return_authorization, amount: amount_3) }
- subject { return_authorization.pre_tax_total }
+ subject { return_authorization.reload.pre_tax_total }
- it "sums it's associated return_item's pre-tax amounts" do
- expect(subject).to eq(pre_tax_amount_1 + pre_tax_amount_2 + pre_tax_amount_3)
+ it "sums it's associated return_item's amounts" do
+ expect(subject).to eq(amount_1 + amount_2 + amount_3)
end
end
@@ -177,27 +177,27 @@
end
describe "#refundable_amount" do
- let(:weighted_line_item_pre_tax_amount) { 5.0 }
- let(:line_item_count) { return_authorization.order.line_items.count }
+ let(:line_item_price) { 5.0 }
+ let(:line_item_count) { return_authorization.order.line_items.count }
subject { return_authorization.refundable_amount }
before do
- return_authorization.order.line_items.update_all(pre_tax_amount: weighted_line_item_pre_tax_amount)
+ return_authorization.order.line_items.update_all(price: line_item_price)
return_authorization.order.update_attribute(:promo_total, promo_total)
end
context "no promotions" do
let(:promo_total) { 0.0 }
it "returns the pre-tax line item total" do
- expect(subject).to eq(weighted_line_item_pre_tax_amount * line_item_count)
+ expect(subject).to eq(line_item_price * line_item_count)
end
end
context "promotions" do
let(:promo_total) { -10.0 }
it "returns the pre-tax line item total minus the order level promotion value" do
- expect(subject).to eq((weighted_line_item_pre_tax_amount * line_item_count) + promo_total)
+ expect(subject).to eq((line_item_price * line_item_count) + promo_total)
end
end
end
diff --git a/core/spec/models/spree/return_item_spec.rb b/core/spec/models/spree/return_item_spec.rb
index 3525d2ef2e..98b0489450 100644
--- a/core/spec/models/spree/return_item_spec.rb
+++ b/core/spec/models/spree/return_item_spec.rb
@@ -69,7 +69,7 @@
return_item_in_lieu.reload
expect(return_item_with_exchange.reception_status).to eq 'unexchanged'
expect(return_item_in_lieu.reception_status).to eq 'received'
- expect(return_item_in_lieu.pre_tax_amount).to eq 0
+ expect(return_item_in_lieu.amount).to eq 0
expect(inventory_unit.reload.state).to eq 'shipped'
expect(exchange_inventory_unit.reload.state).to eq 'returned'
end
@@ -141,11 +141,12 @@
end
describe "#display_pre_tax_amount" do
- let(:pre_tax_amount) { 21.22 }
- let(:return_item) { build(:return_item, pre_tax_amount: pre_tax_amount) }
+ 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(pre_tax_amount)
+ expect(return_item.display_pre_tax_amount).to eq Spree::Money.new(amount - included_tax_total)
end
end
@@ -155,28 +156,28 @@
end
end
- describe "pre_tax_amount calculations on create" do
+ describe "amount calculations on create" do
let(:inventory_unit) { build(:inventory_unit) }
before { subject.save! }
- context "pre tax amount is not specified" do
+ context "amount is not specified" do
subject { build(:return_item, inventory_unit: inventory_unit) }
context "not an exchange" do
- it { expect(subject.pre_tax_amount).to eq Spree::Calculator::Returns::DefaultRefundAmount.new.compute(subject) }
+ it { expect(subject.amount).to eq Spree::Calculator::Returns::DefaultRefundAmount.new.compute(subject) }
end
context "an exchange" do
subject { build(:exchange_return_item) }
- it { expect(subject.pre_tax_amount).to eq 0.0 }
+ it { expect(subject.amount).to eq 0.0 }
end
end
- context "pre tax amount is specified" do
- subject { build(:return_item, inventory_unit: inventory_unit, pre_tax_amount: 100) }
+ context "amount is specified" do
+ subject { build(:return_item, inventory_unit: inventory_unit, amount: 100) }
- it { expect(subject.pre_tax_amount).to eq 100 }
+ it { expect(subject.amount).to eq 100 }
end
end
@@ -567,17 +568,17 @@
end
it do
- return_item.pre_tax_amount = 5.0
+ return_item.amount = 5.0
return_item.save!
- expect(return_item.reload.pre_tax_amount).to eq 0.0
+ expect(return_item.reload.amount).to eq 0.0
end
end
context "the return item is not intended to be exchanged" do
it do
- return_item.pre_tax_amount = 5.0
+ return_item.amount = 5.0
return_item.save!
- expect(return_item.reload.pre_tax_amount).to eq 5.0
+ expect(return_item.reload.amount).to eq 5.0
end
end
end
@@ -686,14 +687,14 @@
create(
:return_item,
inventory_unit: inventory_unit,
- included_tax_total: 10
+ included_tax_total: 5
)
end
it 'includes included tax total' do
- expect(return_item.pre_tax_amount).to eq 10
- expect(return_item.included_tax_total).to eq 10
- expect(return_item.total).to eq 20
+ expect(return_item.amount).to eq 10
+ expect(return_item.included_tax_total).to eq 5
+ expect(return_item.total).to eq 10
end
end
|