diff --git a/admin/app/components/solidus_admin/adjustment_reasons/index/component.html.erb b/admin/app/components/solidus_admin/adjustment_reasons/index/component.html.erb new file mode 100644 index 00000000000..15a034f1eeb --- /dev/null +++ b/admin/app/components/solidus_admin/adjustment_reasons/index/component.html.erb @@ -0,0 +1,31 @@ +<%= render component('refunds_and_returns').new(current_class: Spree::AdjustmentReason) do |layout| %> + <% layout.with_actions do %> + <%= render component("ui/button").new( + tag: :a, + text: t('.add'), + href: spree.new_admin_adjustment_reason_path, + icon: "add-line", + class: "align-self-end w-full", + ) %> + <% end %> + <%= render component('ui/table').new( + id: stimulus_id, + data: { + class: Spree::AdjustmentReason, + rows: @page.records, + url: ->(adjustment_reason) { spree.edit_admin_adjustment_reason_path(adjustment_reason) }, + prev: prev_page_path, + next: next_page_path, + columns: columns, + batch_actions: batch_actions, + }, + search: { + name: :q, + value: params[:q], + url: solidus_admin.adjustment_reasons_path, + searchbar_key: :name_or_code_cont, + filters: filters, + scopes: scopes, + }, + ) %> +<% end %> diff --git a/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb b/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb new file mode 100644 index 00000000000..e496b87ee65 --- /dev/null +++ b/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +class SolidusAdmin::AdjustmentReasons::Index::Component < SolidusAdmin::BaseComponent + include SolidusAdmin::Layout::PageHelpers + + def initialize(page:) + @page = page + end + + def title + Spree::AdjustmentReason.model_name.human.pluralize + end + + def prev_page_path + solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + end + + def next_page_path + solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + end + + def batch_actions + [ + { + display_name: t('.batch_actions.delete'), + action: solidus_admin.adjustment_reasons_path, + method: :delete, + icon: 'delete-bin-7-line', + }, + ] + end + + def filters + [] + end + + def scopes + [] + end + + def columns + [ + :name, + :code, + { + header: :active, + data: ->(adjustment_reason) do + adjustment_reason.active? ? component('ui/badge').yes : component('ui/badge').no + end + }, + ] + end +end diff --git a/admin/app/components/solidus_admin/adjustment_reasons/index/component.yml b/admin/app/components/solidus_admin/adjustment_reasons/index/component.yml new file mode 100644 index 00000000000..54418702ad3 --- /dev/null +++ b/admin/app/components/solidus_admin/adjustment_reasons/index/component.yml @@ -0,0 +1,4 @@ +en: + add: 'Add new' + batch_actions: + delete: 'Delete' diff --git a/admin/app/components/solidus_admin/refund_reasons/index/component.html.erb b/admin/app/components/solidus_admin/refund_reasons/index/component.html.erb new file mode 100644 index 00000000000..f08f077d39c --- /dev/null +++ b/admin/app/components/solidus_admin/refund_reasons/index/component.html.erb @@ -0,0 +1,31 @@ +<%= render component('refunds_and_returns').new(current_class: Spree::RefundReason) do |layout| %> + <% layout.with_actions do %> + <%= render component("ui/button").new( + tag: :a, + text: t('.add'), + href: spree.new_admin_refund_reason_path, + icon: "add-line", + class: "align-self-end w-full", + ) %> + <% end %> + <%= render component('ui/table').new( + id: stimulus_id, + data: { + class: Spree::RefundReason, + rows: @page.records, + url: ->(refund_reason) { spree.edit_admin_refund_reason_path(refund_reason) }, + prev: prev_page_path, + next: next_page_path, + columns: columns, + batch_actions: batch_actions, + }, + search: { + name: :q, + value: params[:q], + url: solidus_admin.refund_reasons_path, + searchbar_key: :name_or_code_cont, + filters: filters, + scopes: scopes, + }, + ) %> +<% end %> diff --git a/admin/app/components/solidus_admin/refund_reasons/index/component.rb b/admin/app/components/solidus_admin/refund_reasons/index/component.rb new file mode 100644 index 00000000000..7a039132cc9 --- /dev/null +++ b/admin/app/components/solidus_admin/refund_reasons/index/component.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +class SolidusAdmin::RefundReasons::Index::Component < SolidusAdmin::BaseComponent + include SolidusAdmin::Layout::PageHelpers + + def initialize(page:) + @page = page + end + + def title + Spree::RefundReason.model_name.human.pluralize + end + + def prev_page_path + solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + end + + def next_page_path + solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + end + + def batch_actions + [ + { + display_name: t('.batch_actions.delete'), + action: solidus_admin.refund_reasons_path, + method: :delete, + icon: 'delete-bin-7-line', + }, + ] + end + + def filters + [] + end + + def scopes + [] + end + + def columns + [ + :name, + :code, + { + header: :active, + data: ->(refund_reason) do + refund_reason.active? ? component('ui/badge').yes : component('ui/badge').no + end + }, + ] + end +end diff --git a/admin/app/components/solidus_admin/refund_reasons/index/component.yml b/admin/app/components/solidus_admin/refund_reasons/index/component.yml new file mode 100644 index 00000000000..54418702ad3 --- /dev/null +++ b/admin/app/components/solidus_admin/refund_reasons/index/component.yml @@ -0,0 +1,4 @@ +en: + add: 'Add new' + batch_actions: + delete: 'Delete' diff --git a/admin/app/components/solidus_admin/refunds_and_returns/component.html.erb b/admin/app/components/solidus_admin/refunds_and_returns/component.html.erb new file mode 100644 index 00000000000..b497f129ae3 --- /dev/null +++ b/admin/app/components/solidus_admin/refunds_and_returns/component.html.erb @@ -0,0 +1,26 @@ +<%= page do %> + <%= page_header do %> + <%= page_header_title safe_join([ + tag.div(t(".title")), + tag.div(t(".subtitle"), class: "body-small text-gray-500"), + ]) %> + <% end %> + <%= page_header do %> + <% title = capture do %> + <% tabs.each do |tab_class, href|%> + <%= render component('ui/button').new( + tag: :a, + scheme: :ghost, + href: href, + text: tab_class.model_name.human.pluralize, + "aria-current" => tab_class == @current_class, + ) %> + <% end %> + <% end %> + <%= page_header_title title %> + <%= page_header_actions do %> + <%= actions %> + <% end %> + <% end %> + <%= content %> +<% end %> diff --git a/admin/app/components/solidus_admin/refunds_and_returns/component.rb b/admin/app/components/solidus_admin/refunds_and_returns/component.rb new file mode 100644 index 00000000000..8d24892c73d --- /dev/null +++ b/admin/app/components/solidus_admin/refunds_and_returns/component.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class SolidusAdmin::RefundsAndReturns::Component < SolidusAdmin::BaseComponent + include SolidusAdmin::Layout::PageHelpers + renders_one :actions + + def initialize(current_class:) + @current_class = current_class + end + + def tabs + { + Spree::RefundReason => solidus_admin.refund_reasons_path, + Spree::ReimbursementType => solidus_admin.reimbursement_types_path, + Spree::ReturnReason => solidus_admin.return_reasons_path, + Spree::AdjustmentReason => solidus_admin.adjustment_reasons_path, + Spree::StoreCreditReason => solidus_admin.store_credit_reasons_path, + } + end +end diff --git a/admin/app/components/solidus_admin/refunds_and_returns/component.yml b/admin/app/components/solidus_admin/refunds_and_returns/component.yml new file mode 100644 index 00000000000..a9f68c94868 --- /dev/null +++ b/admin/app/components/solidus_admin/refunds_and_returns/component.yml @@ -0,0 +1,3 @@ +en: + title: "Refunds and Returns" + subtitle: "Configure refund reasons, reimbursement types, return reasons, adjustment reasons and store credit reasons" diff --git a/admin/app/components/solidus_admin/reimbursement_types/index/component.html.erb b/admin/app/components/solidus_admin/reimbursement_types/index/component.html.erb new file mode 100644 index 00000000000..2c55c0c0f62 --- /dev/null +++ b/admin/app/components/solidus_admin/reimbursement_types/index/component.html.erb @@ -0,0 +1,22 @@ +<%= render component('refunds_and_returns').new(current_class: Spree::ReimbursementType) do |layout| %> + <%= render component('ui/table').new( + id: stimulus_id, + data: { + class: Spree::ReimbursementType, + rows: @page.records, + url: nil, + prev: prev_page_path, + next: next_page_path, + columns: columns, + batch_actions: batch_actions, + }, + search: { + name: :q, + value: params[:q], + url: solidus_admin.reimbursement_types_path, + searchbar_key: :name_cont, + filters: filters, + scopes: scopes, + }, + ) %> +<% end %> diff --git a/admin/app/components/solidus_admin/reimbursement_types/index/component.rb b/admin/app/components/solidus_admin/reimbursement_types/index/component.rb new file mode 100644 index 00000000000..d2be4c44d92 --- /dev/null +++ b/admin/app/components/solidus_admin/reimbursement_types/index/component.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +class SolidusAdmin::ReimbursementTypes::Index::Component < SolidusAdmin::BaseComponent + include SolidusAdmin::Layout::PageHelpers + + def initialize(page:) + @page = page + end + + def title + Spree::ReimbursementType.model_name.human.pluralize + end + + def prev_page_path + solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + end + + def next_page_path + solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + end + + def batch_actions + [] + end + + def filters + [] + end + + def scopes + [] + end + + def columns + [ + :name, + { + header: :active, + data: ->(reimbursement_type) do + reimbursement_type.active? ? component('ui/badge').yes : component('ui/badge').no + end + }, + ] + end +end diff --git a/admin/app/components/solidus_admin/reimbursement_types/index/component.yml b/admin/app/components/solidus_admin/reimbursement_types/index/component.yml new file mode 100644 index 00000000000..54418702ad3 --- /dev/null +++ b/admin/app/components/solidus_admin/reimbursement_types/index/component.yml @@ -0,0 +1,4 @@ +en: + add: 'Add new' + batch_actions: + delete: 'Delete' diff --git a/admin/app/components/solidus_admin/return_reasons/index/component.html.erb b/admin/app/components/solidus_admin/return_reasons/index/component.html.erb new file mode 100644 index 00000000000..9bb9c158696 --- /dev/null +++ b/admin/app/components/solidus_admin/return_reasons/index/component.html.erb @@ -0,0 +1,31 @@ +<%= render component('refunds_and_returns').new(current_class: Spree::ReturnReason) do |layout| %> + <% layout.with_actions do %> + <%= render component("ui/button").new( + tag: :a, + text: t('.add'), + href: spree.new_admin_return_reason_path, + icon: "add-line", + class: "align-self-end w-full", + ) %> + <% end %> + <%= render component('ui/table').new( + id: stimulus_id, + data: { + class: Spree::ReturnReason, + rows: @page.records, + url: ->(return_reason) { spree.edit_admin_return_reason_path(return_reason) }, + prev: prev_page_path, + next: next_page_path, + columns: columns, + batch_actions: batch_actions, + }, + search: { + name: :q, + value: params[:q], + url: solidus_admin.return_reasons_path, + searchbar_key: :name_cont, + filters: filters, + scopes: scopes, + }, + ) %> +<% end %> diff --git a/admin/app/components/solidus_admin/return_reasons/index/component.rb b/admin/app/components/solidus_admin/return_reasons/index/component.rb new file mode 100644 index 00000000000..ae709ce96da --- /dev/null +++ b/admin/app/components/solidus_admin/return_reasons/index/component.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +class SolidusAdmin::ReturnReasons::Index::Component < SolidusAdmin::BaseComponent + include SolidusAdmin::Layout::PageHelpers + + def initialize(page:) + @page = page + end + + def title + Spree::ReturnReason.model_name.human.pluralize + end + + def prev_page_path + solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + end + + def next_page_path + solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + end + + def batch_actions + [ + { + display_name: t('.batch_actions.delete'), + action: solidus_admin.return_reasons_path, + method: :delete, + icon: 'delete-bin-7-line', + }, + ] + end + + def filters + [] + end + + def scopes + [] + end + + def columns + [ + :name, + { + header: :active, + data: ->(return_reason) do + return_reason.active? ? component('ui/badge').yes : component('ui/badge').no + end + }, + ] + end +end diff --git a/admin/app/components/solidus_admin/return_reasons/index/component.yml b/admin/app/components/solidus_admin/return_reasons/index/component.yml new file mode 100644 index 00000000000..54418702ad3 --- /dev/null +++ b/admin/app/components/solidus_admin/return_reasons/index/component.yml @@ -0,0 +1,4 @@ +en: + add: 'Add new' + batch_actions: + delete: 'Delete' diff --git a/admin/app/components/solidus_admin/store_credit_reasons/index/component.html.erb b/admin/app/components/solidus_admin/store_credit_reasons/index/component.html.erb new file mode 100644 index 00000000000..a4e56ee9501 --- /dev/null +++ b/admin/app/components/solidus_admin/store_credit_reasons/index/component.html.erb @@ -0,0 +1,31 @@ +<%= render component('refunds_and_returns').new(current_class: Spree::StoreCreditReason) do |layout| %> + <% layout.with_actions do %> + <%= render component("ui/button").new( + tag: :a, + text: t('.add'), + href: spree.new_admin_store_credit_reason_path, + icon: "add-line", + class: "align-self-end w-full", + ) %> + <% end %> + <%= render component('ui/table').new( + id: stimulus_id, + data: { + class: Spree::StoreCreditReason, + rows: @page.records, + url: ->(store_credit_reason) { spree.edit_admin_store_credit_reason_path(store_credit_reason) }, + prev: prev_page_path, + next: next_page_path, + columns: columns, + batch_actions: batch_actions, + }, + search: { + name: :q, + value: params[:q], + url: solidus_admin.store_credit_reasons_path, + searchbar_key: :name_cont, + filters: filters, + scopes: scopes, + }, + ) %> +<% end %> diff --git a/admin/app/components/solidus_admin/store_credit_reasons/index/component.rb b/admin/app/components/solidus_admin/store_credit_reasons/index/component.rb new file mode 100644 index 00000000000..18898313bac --- /dev/null +++ b/admin/app/components/solidus_admin/store_credit_reasons/index/component.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +class SolidusAdmin::StoreCreditReasons::Index::Component < SolidusAdmin::BaseComponent + include SolidusAdmin::Layout::PageHelpers + + def initialize(page:) + @page = page + end + + def title + Spree::StoreCreditReason.model_name.human.pluralize + end + + def prev_page_path + solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + end + + def next_page_path + solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + end + + def batch_actions + [ + { + display_name: t('.batch_actions.delete'), + action: solidus_admin.store_credit_reasons_path, + method: :delete, + icon: 'delete-bin-7-line', + }, + ] + end + + def filters + [] + end + + def scopes + [] + end + + def columns + [ + :name, + { + header: :active, + data: ->(store_credit_reason) do + store_credit_reason.active? ? component('ui/badge').yes : component('ui/badge').no + end + }, + ] + end +end diff --git a/admin/app/components/solidus_admin/store_credit_reasons/index/component.yml b/admin/app/components/solidus_admin/store_credit_reasons/index/component.yml new file mode 100644 index 00000000000..54418702ad3 --- /dev/null +++ b/admin/app/components/solidus_admin/store_credit_reasons/index/component.yml @@ -0,0 +1,4 @@ +en: + add: 'Add new' + batch_actions: + delete: 'Delete' diff --git a/admin/app/controllers/solidus_admin/adjustment_reasons_controller.rb b/admin/app/controllers/solidus_admin/adjustment_reasons_controller.rb new file mode 100644 index 00000000000..6957634863d --- /dev/null +++ b/admin/app/controllers/solidus_admin/adjustment_reasons_controller.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +module SolidusAdmin + class AdjustmentReasonsController < SolidusAdmin::BaseController + include SolidusAdmin::ControllerHelpers::Search + + def index + adjustment_reasons = apply_search_to( + Spree::AdjustmentReason.order(id: :desc), + param: :q, + ) + + set_page_and_extract_portion_from(adjustment_reasons) + + respond_to do |format| + format.html { render component('adjustment_reasons/index').new(page: @page) } + end + end + + def destroy + @adjustment_reason = Spree::AdjustmentReason.find_by!(id: params[:id]) + + Spree::AdjustmentReason.transaction { @adjustment_reason.destroy } + + flash[:notice] = t('.success') + redirect_back_or_to adjustment_reasons_path, status: :see_other + end + + private + + def load_adjustment_reason + @adjustment_reason = Spree::AdjustmentReason.find_by!(id: params[:id]) + authorize! action_name, @adjustment_reason + end + + def adjustment_reason_params + params.require(:adjustment_reason).permit(:adjustment_reason_id, permitted_adjustment_reason_attributes) + end + end +end diff --git a/admin/app/controllers/solidus_admin/refund_reasons_controller.rb b/admin/app/controllers/solidus_admin/refund_reasons_controller.rb new file mode 100644 index 00000000000..55a78bbb1da --- /dev/null +++ b/admin/app/controllers/solidus_admin/refund_reasons_controller.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +module SolidusAdmin + class RefundReasonsController < SolidusAdmin::BaseController + include SolidusAdmin::ControllerHelpers::Search + + def index + refund_reasons = apply_search_to( + Spree::RefundReason.unscoped.order(id: :desc), + param: :q, + ) + + set_page_and_extract_portion_from(refund_reasons) + + respond_to do |format| + format.html { render component('refund_reasons/index').new(page: @page) } + end + end + + def destroy + @refund_reason = Spree::RefundReason.find_by!(id: params[:id]) + + Spree::RefundReason.transaction { @refund_reason.destroy } + + flash[:notice] = t('.success') + redirect_back_or_to refund_reasons_path, status: :see_other + end + + private + + def load_refund_reason + @refund_reason = Spree::RefundReason.find_by!(id: params[:id]) + authorize! action_name, @refund_reason + end + + def refund_reason_params + params.require(:refund_reason).permit(:refund_reason_id, permitted_refund_reason_attributes) + end + end +end diff --git a/admin/app/controllers/solidus_admin/reimbursement_types_controller.rb b/admin/app/controllers/solidus_admin/reimbursement_types_controller.rb new file mode 100644 index 00000000000..67eba73f73e --- /dev/null +++ b/admin/app/controllers/solidus_admin/reimbursement_types_controller.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module SolidusAdmin + class ReimbursementTypesController < SolidusAdmin::BaseController + include SolidusAdmin::ControllerHelpers::Search + + def index + reimbursement_types = apply_search_to( + Spree::ReimbursementType.unscoped.order(id: :desc), + param: :q, + ) + + set_page_and_extract_portion_from(reimbursement_types) + + respond_to do |format| + format.html { render component('reimbursement_types/index').new(page: @page) } + end + end + + private + + def load_reimbursement_type + @reimbursement_type = Spree::ReimbursementType.find_by!(id: params[:id]) + authorize! action_name, @reimbursement_type + end + + def reimbursement_type_params + params.require(:reimbursement_type).permit(:reimbursement_type_id, permitted_reimbursement_type_attributes) + end + end +end diff --git a/admin/app/controllers/solidus_admin/return_reasons_controller.rb b/admin/app/controllers/solidus_admin/return_reasons_controller.rb new file mode 100644 index 00000000000..ad3a7883218 --- /dev/null +++ b/admin/app/controllers/solidus_admin/return_reasons_controller.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +module SolidusAdmin + class ReturnReasonsController < SolidusAdmin::BaseController + include SolidusAdmin::ControllerHelpers::Search + + def index + return_reasons = apply_search_to( + Spree::ReturnReason.unscoped.order(id: :desc), + param: :q, + ) + + set_page_and_extract_portion_from(return_reasons) + + respond_to do |format| + format.html { render component('return_reasons/index').new(page: @page) } + end + end + + def destroy + @return_reason = Spree::ReturnReason.find_by!(id: params[:id]) + + Spree::ReturnReason.transaction { @return_reason.destroy } + + flash[:notice] = t('.success') + redirect_back_or_to return_reasons_path, status: :see_other + end + + private + + def load_return_reason + @return_reason = Spree::ReturnReason.find_by!(id: params[:id]) + authorize! action_name, @return_reason + end + + def return_reason_params + params.require(:return_reason).permit(:return_reason_id, permitted_return_reason_attributes) + end + end +end diff --git a/admin/app/controllers/solidus_admin/store_credit_reasons_controller.rb b/admin/app/controllers/solidus_admin/store_credit_reasons_controller.rb new file mode 100644 index 00000000000..db2f088ab9d --- /dev/null +++ b/admin/app/controllers/solidus_admin/store_credit_reasons_controller.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +module SolidusAdmin + class StoreCreditReasonsController < SolidusAdmin::BaseController + include SolidusAdmin::ControllerHelpers::Search + + def index + store_credit_reasons = apply_search_to( + Spree::StoreCreditReason.unscoped.order(id: :desc), + param: :q, + ) + + set_page_and_extract_portion_from(store_credit_reasons) + + respond_to do |format| + format.html { render component('store_credit_reasons/index').new(page: @page) } + end + end + + def destroy + @store_credit_reason = Spree::StoreCreditReason.find_by!(id: params[:id]) + + Spree::StoreCreditReason.transaction { @store_credit_reason.destroy } + + flash[:notice] = t('.success') + redirect_back_or_to store_credit_reasons_path, status: :see_other + end + + private + + def load_store_credit_reason + @store_credit_reason = Spree::StoreCreditReason.find_by!(id: params[:id]) + authorize! action_name, @store_credit_reason + end + + def store_credit_reason_params + params.require(:store_credit_reason).permit(:store_credit_reason_id, permitted_store_credit_reason_attributes) + end + end +end diff --git a/admin/config/locales/adjustment_reasons.en.yml b/admin/config/locales/adjustment_reasons.en.yml new file mode 100644 index 00000000000..90b05a067ce --- /dev/null +++ b/admin/config/locales/adjustment_reasons.en.yml @@ -0,0 +1,6 @@ +en: + solidus_admin: + adjustment_reasons: + title: "Adjustment Reasons" + destroy: + success: "Adjustment Reasons were successfully removed." diff --git a/admin/config/locales/refund_reasons_.en.yml b/admin/config/locales/refund_reasons_.en.yml new file mode 100644 index 00000000000..26bfae7ee8e --- /dev/null +++ b/admin/config/locales/refund_reasons_.en.yml @@ -0,0 +1,6 @@ +en: + solidus_admin: + refund_reasons: + title: "Refund Reasons" + destroy: + success: "Refund Reasons were successfully removed." diff --git a/admin/config/locales/reimbursement_types.en.yml b/admin/config/locales/reimbursement_types.en.yml new file mode 100644 index 00000000000..1fecb0d9e50 --- /dev/null +++ b/admin/config/locales/reimbursement_types.en.yml @@ -0,0 +1,4 @@ +en: + solidus_admin: + reimbursement_types: + title: "Reimbursement Types" diff --git a/admin/config/locales/return_reasons.en.yml b/admin/config/locales/return_reasons.en.yml new file mode 100644 index 00000000000..248dc9769d7 --- /dev/null +++ b/admin/config/locales/return_reasons.en.yml @@ -0,0 +1,6 @@ +en: + solidus_admin: + return_reasons: + title: "Return Reasons" + destroy: + success: "Return Reasons were successfully removed." diff --git a/admin/config/locales/store_credit_reasons.en.yml b/admin/config/locales/store_credit_reasons.en.yml new file mode 100644 index 00000000000..7d4812eacc4 --- /dev/null +++ b/admin/config/locales/store_credit_reasons.en.yml @@ -0,0 +1,6 @@ +en: + solidus_admin: + store_credit_reasons: + title: "Store Credit Reasons" + destroy: + success: "Store Credit Reasons were successfully removed." diff --git a/admin/config/routes.rb b/admin/config/routes.rb index cb6a4ff4b20..09383559475 100644 --- a/admin/config/routes.rb +++ b/admin/config/routes.rb @@ -46,4 +46,9 @@ admin_resources :stock_locations, only: [:index, :destroy] admin_resources :stores, only: [:index, :destroy] admin_resources :zones, only: [:index, :destroy] + admin_resources :refund_reasons, only: [:index, :destroy] + admin_resources :reimbursement_types, only: [:index] + admin_resources :return_reasons, only: [:index, :destroy] + admin_resources :adjustment_reasons, only: [:index, :destroy] + admin_resources :store_credit_reasons, only: [:index, :destroy] end diff --git a/admin/spec/features/adjustment_reasons_spec.rb b/admin/spec/features/adjustment_reasons_spec.rb new file mode 100644 index 00000000000..4f0dc85a3fb --- /dev/null +++ b/admin/spec/features/adjustment_reasons_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe "Adjustment Reasons", :js, type: :feature do + before { sign_in create(:admin_user, email: 'admin@example.com') } + + it "lists adjustment reasons and allows deleting them" do + create(:adjustment_reason, name: "Default-adjustment-reason") + + visit "/admin/adjustment_reasons" + expect(page).to have_content("Default-adjustment-reason") + expect(page).to be_axe_clean + + select_row("Default-adjustment-reason") + click_on "Delete" + expect(page).to have_content("Adjustment Reasons were successfully removed.") + expect(page).not_to have_content("Default-adjustment-reason") + expect(Spree::AdjustmentReason.count).to eq(0) + expect(page).to be_axe_clean + end +end diff --git a/admin/spec/features/refund_reasons_spec.rb b/admin/spec/features/refund_reasons_spec.rb new file mode 100644 index 00000000000..551035387d1 --- /dev/null +++ b/admin/spec/features/refund_reasons_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe "Refund Reasons", :js, type: :feature do + before { sign_in create(:admin_user, email: 'admin@example.com') } + + it "lists refund reasons and allows deleting them" do + create(:refund_reason, name: "Default-refund-reason") + + visit "/admin/refund_reasons" + expect(page).to have_content("Default-refund-reason") + expect(page).to be_axe_clean + + select_row("Default-refund-reason") + click_on "Delete" + expect(page).to have_content("Refund Reasons were successfully removed.") + expect(page).not_to have_content("Default-refund-reason") + expect(Spree::RefundReason.count).to eq(0) + expect(page).to be_axe_clean + end +end diff --git a/admin/spec/features/reimbursement_types_spec.rb b/admin/spec/features/reimbursement_types_spec.rb new file mode 100644 index 00000000000..76cc25edadc --- /dev/null +++ b/admin/spec/features/reimbursement_types_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe "Reimbursement Types", :js, type: :feature do + before { sign_in create(:admin_user, email: 'admin@example.com') } + + it "lists Reimbursement Types and allows deleting them" do + create(:reimbursement_type, name: "Default-reimbursement-type") + + visit "/admin/reimbursement_types" + expect(page).to have_content("Default-reimbursement-type") + expect(page).to be_axe_clean + end +end diff --git a/admin/spec/features/return_reasons_spec.rb b/admin/spec/features/return_reasons_spec.rb new file mode 100644 index 00000000000..3e929cd1dd4 --- /dev/null +++ b/admin/spec/features/return_reasons_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe "Return Reasons", :js, type: :feature do + before { sign_in create(:admin_user, email: 'admin@example.com') } + + it "lists Return Reasons and allows deleting them" do + create(:return_reason, name: "Default-return-reason") + + visit "/admin/return_reasons" + expect(page).to have_content("Default-return-reason") + expect(page).to be_axe_clean + + select_row("Default-return-reason") + click_on "Delete" + expect(page).to have_content("Return Reasons were successfully removed.") + expect(page).not_to have_content("Default-return-reason") + expect(Spree::ReturnReason.count).to eq(0) + expect(page).to be_axe_clean + end +end diff --git a/admin/spec/features/store_credit_reasons_spec.rb b/admin/spec/features/store_credit_reasons_spec.rb new file mode 100644 index 00000000000..5a8ffff0e20 --- /dev/null +++ b/admin/spec/features/store_credit_reasons_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe "Store Credit Reasons", :js, type: :feature do + before { sign_in create(:admin_user, email: 'admin@example.com') } + + it "lists Store Credit Reasons and allows deleting them" do + create(:store_credit_reason, name: "Default-store-credit-reason") + + visit "/admin/store_credit_reasons" + expect(page).to have_content("Default-store-credit-reason") + expect(page).to be_axe_clean + + select_row("Default-store-credit-reason") + click_on "Delete" + expect(page).to have_content("Store Credit Reasons were successfully removed.") + expect(page).not_to have_content("Default-store-credit-reason") + expect(Spree::StoreCreditReason.count).to eq(0) + expect(page).to be_axe_clean + end +end diff --git a/core/app/models/spree/adjustment_reason.rb b/core/app/models/spree/adjustment_reason.rb index 1bf4daa31ff..81d74c1044f 100644 --- a/core/app/models/spree/adjustment_reason.rb +++ b/core/app/models/spree/adjustment_reason.rb @@ -8,5 +8,7 @@ class AdjustmentReason < Spree::Base validates :code, presence: true, uniqueness: { case_sensitive: false, allow_blank: true } scope :active, -> { where(active: true) } + + self.allowed_ransackable_attributes = %w[name code] end end diff --git a/core/app/models/spree/refund_reason.rb b/core/app/models/spree/refund_reason.rb index 9247ae95929..a397a8ef61a 100644 --- a/core/app/models/spree/refund_reason.rb +++ b/core/app/models/spree/refund_reason.rb @@ -8,6 +8,8 @@ class RefundReason < Spree::Base has_many :refunds + self.allowed_ransackable_attributes = %w[name code] + def self.return_processing_reason find_by!(name: RETURN_PROCESSING_REASON, mutable: false) end diff --git a/core/app/models/spree/reimbursement_type.rb b/core/app/models/spree/reimbursement_type.rb index a669b9a37ba..acfce54618c 100644 --- a/core/app/models/spree/reimbursement_type.rb +++ b/core/app/models/spree/reimbursement_type.rb @@ -8,6 +8,8 @@ class ReimbursementType < Spree::Base has_many :return_items + self.allowed_ransackable_attributes = %w[name] + # This method will reimburse the return items based on however it child implements it # By default it takes a reimbursement, the return items it needs to reimburse, and if # it is a simulation or a real reimbursement. This should return an array diff --git a/core/app/models/spree/return_reason.rb b/core/app/models/spree/return_reason.rb index aa41cdcdf42..b1fc513c125 100644 --- a/core/app/models/spree/return_reason.rb +++ b/core/app/models/spree/return_reason.rb @@ -6,6 +6,8 @@ class ReturnReason < Spree::Base has_many :return_authorizations + self.allowed_ransackable_attributes = %w[name] + def self.reasons_for_return_items(return_items) # Only allow an inactive reason if it's already associated to a return item active | return_items.map(&:return_reason).compact diff --git a/core/app/models/spree/store_credit_reason.rb b/core/app/models/spree/store_credit_reason.rb index c0b7b5e6abf..1578506bd5e 100644 --- a/core/app/models/spree/store_credit_reason.rb +++ b/core/app/models/spree/store_credit_reason.rb @@ -4,4 +4,6 @@ class Spree::StoreCreditReason < Spree::Base include Spree::NamedType has_many :store_credit_events, inverse_of: :store_credit_reason + + self.allowed_ransackable_attributes = %w[name] end