Skip to content

Commit a570cc0

Browse files
forkataAlistairNorman
authored andcommitted
Associate return items with return authorization
This change ensures that return items built for a new return authorization are correctly associated with it. This will ensure that the display_* methods use the currency from the return authorization, instead of the default store currency. Co-authored-by: Alistair Norman <alistair@super.gd>
1 parent 6e9a0c7 commit a570cc0

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

backend/app/controllers/spree/admin/return_authorizations_controller.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ def load_return_items
4040
associated_inventory_units = @return_authorization.return_items.map(&:inventory_unit)
4141
unassociated_inventory_units = all_inventory_units - associated_inventory_units
4242

43-
new_return_items = unassociated_inventory_units.map do |new_unit|
44-
Spree::ReturnItem.new(inventory_unit: new_unit).tap(&:set_default_amount)
43+
unassociated_inventory_units.each do |new_unit|
44+
@return_authorization.return_items.
45+
build(inventory_unit: new_unit).
46+
tap(&:set_default_amount)
4547
end
46-
@form_return_items = (@return_authorization.return_items + new_return_items).sort_by(&:inventory_unit_id)
48+
49+
@form_return_items = @return_authorization.return_items.sort_by(&:inventory_unit_id)
4750
end
4851

4952
def load_reimbursement_types

backend/spec/controllers/spree/admin/return_authorizations_controller_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@
102102
expect(assigns(:form_return_items).size).to eq 3
103103
expect(assigns(:form_return_items).select(&:new_record?).size).to eq 3
104104
end
105+
106+
context 'with an order with currency other than the store default' do
107+
let!(:order) { create(:shipped_order, line_items_count: 3, currency: 'EUR') }
108+
109+
it 'sets the currency on the return items from the order' do
110+
subject
111+
expect(
112+
assigns(:form_return_items).all? { |ri|
113+
ri.display_amount.currency.iso_code == 'EUR'
114+
}
115+
).to be true
116+
end
117+
end
105118
end
106119
end
107120

0 commit comments

Comments
 (0)