Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ def load_return_items
associated_inventory_units = @return_authorization.return_items.map(&:inventory_unit)
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_amount)
unassociated_inventory_units.each do |new_unit|
@return_authorization.return_items.
build(inventory_unit: new_unit).
tap(&:set_default_amount)
end
@form_return_items = (@return_authorization.return_items + new_return_items).sort_by(&:inventory_unit_id)

@form_return_items = @return_authorization.return_items.sort_by(&:inventory_unit_id)
end

def load_reimbursement_types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@
expect(assigns(:form_return_items).size).to eq 3
expect(assigns(:form_return_items).select(&:new_record?).size).to eq 3
end

context 'with an order with currency other than the store default' do
let!(:order) { create(:shipped_order, line_items_count: 3, currency: 'EUR') }

it 'sets the currency on the return items from the order' do
subject
expect(
assigns(:form_return_items).all? { |ri|
ri.display_amount.currency.iso_code == 'EUR'
}
).to be true
end
end
end
end

Expand Down
8 changes: 4 additions & 4 deletions core/app/models/spree/return_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,16 @@ def part_of_exchange?
exchange_requested? || sibling_intended_for_exchange('unexchanged')
end

def currency
return_authorization.try(:currency) || Spree::Config[:currency]
end

private

def persist_acceptance_status_errors
update(acceptance_status_errors: validator.errors)
end

def currency
return_authorization.try(:currency) || Spree::Config[:currency]
end

def process_inventory_unit!
inventory_unit.return!

Expand Down
15 changes: 14 additions & 1 deletion core/spec/models/spree/return_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,23 @@
end
end

describe "#display_amount" do
let(:amount) { 21.22 }
let(:order) { build(:order, currency: 'EUR') }
let(:return_authorization) { build(:return_authorization, order:) }
let(:return_item) { build(:return_item, return_authorization:, amount:) }

context 'with an amount in the non-default currency' do
it "returns a Spree::Money" do
expect(return_item.display_amount).to eq Spree::Money.new(amount, currency: 'EUR')
end
end
end

describe "#display_total_excluding_vat" do
let(:amount) { 21.22 }
let(:included_tax_total) { 1.22 }
let(:return_item) { build(:return_item, amount:, included_tax_total:) }
let(:return_item) { create(:return_item, amount:, included_tax_total:) }

it "returns a Spree::Money" do
expect(return_item.display_total_excluding_vat).to eq Spree::Money.new(amount - included_tax_total)
Expand Down
Loading