Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fixed admin reimbursement types management (#12770)

Damian Legawiec1d55de2aef71
diff --git a/admin/app/views/spree/admin/reimbursement_types/_form.html.erb b/admin/app/views/spree/admin/reimbursement_types/_form.html.erb
index 540333daf0..0bb3769387 100644
--- a/admin/app/views/spree/admin/reimbursement_types/_form.html.erb
+++ b/admin/app/views/spree/admin/reimbursement_types/_form.html.erb
@@ -5,20 +5,20 @@
<%= f.text_field :name, class: "form-control", autofocus: f.object.new_record?, required: true %>
<%= f.error_message_on :name %>
</div>
- <%- if @reimbursement_type.new_record? %>
- <div class="form-group">
- <%= f.label :type, Spree.t(:type) %>
- <%= f.select :type,
- options_for_select(
- Spree::ReimbursementType::KINDS.map do |kind|
- [kind.demodulize.titleize, kind]
- end,
- ),
- { include_blank: false },
- { class: "custom-select" } %>
- <%= f.error_message_on :type %>
- </div>
- <% end %>
+
+ <div class="form-group">
+ <%= f.label :type, Spree.t(:type) %>
+ <%= f.select :type,
+ options_for_select(
+ Spree::ReimbursementType::KINDS.map do |kind|
+ [kind.demodulize.titleize, kind]
+ end,
+ ),
+ { include_blank: false },
+ { class: "custom-select" } %>
+ <%= f.error_message_on :type %>
+ </div>
+
<div class="form-group">
<div class="custom-control custom-checkbox">
<%= f.check_box :active, class: "custom-control-input" %>
@@ -26,5 +26,13 @@
</div>
<%= f.error_message_on :active %>
</div>
+
+ <div class="form-group">
+ <div class="custom-control custom-checkbox">
+ <%= f.check_box :mutable, class: "custom-control-input" %>
+ <%= f.label :mutable, Spree.t(:mutable), class: "custom-control-label" %>
+ </div>
+ <%= f.error_message_on :mutable %>
+ </div>
</div>
</div>
diff --git a/admin/spec/controllers/spree/admin/reimbursement_types_controller_spec.rb b/admin/spec/controllers/spree/admin/reimbursement_types_controller_spec.rb
index 39b0b6e66a..a88fd5c0f3 100644
--- a/admin/spec/controllers/spree/admin/reimbursement_types_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/reimbursement_types_controller_spec.rb
@@ -5,7 +5,7 @@ RSpec.describe Spree::Admin::ReimbursementTypesController, type: :controller do
render_views
let(:reimbursement_type) { create(:reimbursement_type) }
- let(:valid_attributes) { { name: 'Test Type', active: true } }
+ let(:valid_attributes) { { name: 'Test Type', active: true, mutable: true, type: 'Spree::ReimbursementType::Credit' } }
let(:invalid_attributes) { { name: '', active: nil } }
describe 'GET #index' do
@@ -28,6 +28,12 @@ RSpec.describe Spree::Admin::ReimbursementTypesController, type: :controller do
expect {
post :create, params: { reimbursement_type: valid_attributes }
}.to change(Spree::ReimbursementType, :count).by(1)
+
+ reimbursement_type = Spree::ReimbursementType.last
+ expect(reimbursement_type.name).to eq('Test Type')
+ expect(reimbursement_type.active).to be true
+ expect(reimbursement_type.mutable).to be true
+ expect(reimbursement_type.type).to eq('Spree::ReimbursementType::Credit')
end
it 'redirects to the reimbursement types edit screen' do
@@ -60,13 +66,15 @@ RSpec.describe Spree::Admin::ReimbursementTypesController, type: :controller do
describe 'PUT #update' do
context 'with valid params' do
- let(:new_attributes) { { name: 'Updated Type', active: false } }
+ let(:new_attributes) { { name: 'Updated Type', active: false, mutable: false, type: 'Spree::ReimbursementType::OriginalPayment' } }
it 'updates the requested reimbursement type' do
put :update, params: { id: reimbursement_type.to_param, reimbursement_type: new_attributes }
reimbursement_type.reload
expect(reimbursement_type.name).to eq('Updated Type')
expect(reimbursement_type.active).to be false
+ expect(reimbursement_type.mutable).to be false
+ expect(reimbursement_type.type).to eq('Spree::ReimbursementType::OriginalPayment')
end
it 'redirects to the reimbursement type edit screen' do
diff --git a/core/lib/spree/permitted_attributes.rb b/core/lib/spree/permitted_attributes.rb
index 2642b6eafb..f972f32f31 100644
--- a/core/lib/spree/permitted_attributes.rb
+++ b/core/lib/spree/permitted_attributes.rb
@@ -170,7 +170,7 @@ module Spree
@@reimbursement_attributes = [return_items_attributes: [:id, :override_reimbursement_type_id, :pre_tax_amount, :exchange_variant_id]]
- @@reimbursement_type_attributes = [:name, :active]
+ @@reimbursement_type_attributes = [:name, :type, :active, :mutable]
@@report_attributes = [:type, :date_from, :date_to, :currency]