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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Returns management (#12453)
Damian Kaczmarczyk57298a8b91be
diff --git a/admin/app/assets/stylesheets/spree/admin/shared/_base.scss b/admin/app/assets/stylesheets/spree/admin/shared/_base.scssindex 583b05c7dd..9858d0d275 100644--- a/admin/app/assets/stylesheets/spree/admin/shared/_base.scss+++ b/admin/app/assets/stylesheets/spree/admin/shared/_base.scss@@ -757,3 +757,7 @@ code {div.uppy-Root {z-index: 1050;}++.rounded-lg {+ border-radius: $border-radius-lg;+}diff --git a/admin/app/controllers/spree/admin/customer_returns_controller.rb b/admin/app/controllers/spree/admin/customer_returns_controller.rbnew file mode 100644index 0000000000..8716b276b8--- /dev/null+++ b/admin/app/controllers/spree/admin/customer_returns_controller.rb@@ -0,0 +1,20 @@+module Spree+ module Admin+ class CustomerReturnsController < ResourceController+ def index; end++ private++ def collection+ return @collection if @collection.present?++ params[:q] ||= {}++ # @search needs to be defined as this is passed to search_form_for+ @search = current_store.customer_returns.accessible_by(current_ability, :index).ransack(params[:q])+ per_page = params[:per_page]+ @collection = @search.result.order(created_at: :desc).page(params[:page]).per(per_page)+ end+ end+ end+enddiff --git a/admin/app/controllers/spree/admin/orders/customer_returns_controller.rb b/admin/app/controllers/spree/admin/orders/customer_returns_controller.rbnew file mode 100644index 0000000000..29b68de20e--- /dev/null+++ b/admin/app/controllers/spree/admin/orders/customer_returns_controller.rb@@ -0,0 +1,81 @@+module Spree+ module Admin+ module Orders+ class CustomerReturnsController < ResourceController+ include Spree::Admin::OrderConcern++ before_action :load_order+ before_action :load_form_data, only: [:new, :edit]++ create.before :build_return_items_from_params+ create.fails :load_form_data++ def edit+ returned_items = @customer_return.return_items+ @pending_return_items = returned_items.select(&:pending?)+ @accepted_return_items = returned_items.select(&:accepted?)+ @rejected_return_items = returned_items.select(&:rejected?)+ @manual_intervention_return_items = returned_items.select(&:manual_intervention_required?)+ @pending_reimbursements = @customer_return.reimbursements.select(&:pending?)++ super+ end++ private++ def location_after_save+ spree.edit_admin_order_path(@order)+ end++ def build_resource+ current_store.customer_returns.new+ end++ def find_resource+ current_store.customer_returns.accessible_by(current_ability, :show).find(params[:id])+ end++ def load_form_data+ return_items = @order.inventory_units.map(&:current_or_new_return_item).reject(&:customer_return_id)+ @rma_return_items = return_items.select(&:return_authorization_id)+ end++ def permitted_resource_params+ @permitted_resource_params ||= params.require(:customer_return).permit(permitted_customer_return_attributes)+ end++ def build_return_items_from_params+ return_items_params = permitted_resource_params.delete(:return_items_attributes).values++ @customer_return.return_items = return_items_params.map do |item_params|+ next unless item_params.delete('returned') == '1'++ return_item = item_params[:id] ? Spree::ReturnItem.find(item_params[:id]) : Spree::ReturnItem.new+ return_item.attributes = item_params+ return_item+ end.compact+ end++ def object_name+ 'customer_return'+ end++ def object_url(object = nil, options = {})+ target = object || @object++ spree.admin_order_customer_return_url(@order, target, options)+ end++ def edit_object_url(object, options = {})+ target = object || @object++ spree.edit_admin_order_customer_return_url(@order, target, options)+ end++ def model_class+ Spree::CustomerReturn+ end+ end+ end+ end+enddiff --git a/admin/app/controllers/spree/admin/orders/return_authorizations_controller.rb b/admin/app/controllers/spree/admin/orders/return_authorizations_controller.rbnew file mode 100644index 0000000000..531c8502f1--- /dev/null+++ b/admin/app/controllers/spree/admin/orders/return_authorizations_controller.rb@@ -0,0 +1,86 @@+module Spree+ module Admin+ module Orders+ class ReturnAuthorizationsController < ResourceController+ include Spree::Admin::OrderConcern++ before_action :load_order++ before_action :load_return_authorization+ before_action :load_form_data, only: [:new, :edit]+ before_action :load_refunds, only: :show+ create.fails :load_form_data+ update.fails :load_form_data++ private++ def load_form_data+ load_return_items+ load_reimbursement_types+ load_return_authorization_reasons+ end++ # To satisfy how nested attributes works we want to create placeholder ReturnItems for+ # any InventoryUnits that have not already been added to the ReturnAuthorization.+ def load_return_items+ all_inventory_units = @return_authorization.order.inventory_units+ 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, return_authorization: @return_authorization).tap(&:set_default_pre_tax_amount)+ end++ @form_return_items = (@return_authorization.return_items + new_return_items).sort_by(&:inventory_unit_id)+ end++ def load_reimbursement_types+ @reimbursement_types = Spree::ReimbursementType.accessible_by(current_ability).active+ end++ def load_return_authorization_reasons+ @reasons = Spree::ReturnAuthorizationReason.active.to_a+ # Only allow an inactive reason if it's already associated to the RMA+ if @return_authorization.reason && !@return_authorization.reason.active?+ @reasons << @return_authorization.reason+ end+ end++ def load_refunds+ reimbursements = @return_authorization.reimbursements+ refunds = @return_authorization.refunds++ @refunds = refunds.any? ? refunds : reimbursements.flat_map(&:simulate)+ end++ def load_return_authorization+ if @object.order.nil?+ @object.order = @order+ end++ @return_authorization = @object+ end++ def object_name+ 'return_authorization'+ end++ def object_url(object = nil, options = {})+ target = object || @object++ spree.admin_order_return_authorization_url(@order, target, options)+ end++ def edit_object_url(object, options = {})+ target = object || @object++ spree.edit_admin_order_return_authorization_url(@order, target, options)+ end++ def model_class+ Spree::ReturnAuthorization+ end+ end+ end+ end+enddiff --git a/admin/app/controllers/spree/admin/orders_controller.rb b/admin/app/controllers/spree/admin/orders_controller.rbindex 0d0f27ed4a..81ad4c4f99 100644--- a/admin/app/controllers/spree/admin/orders_controller.rb+++ b/admin/app/controllers/spree/admin/orders_controller.rb@@ -65,10 +65,12 @@ module Spreedef load_order_items@line_items = @order.line_items.includes(variant: [:product, :option_values])- @shipments = @order.shipments.includes(:inventory_units, :selected_shipping_rate, shipping_rates: [:shipping_method, :tax_rate]).order(:created_at)+ @shipments = @order.shipments.includes(:inventory_units, :selected_shipping_rate,+ shipping_rates: [:shipping_method, :tax_rate]).order(:created_at)@payments = @order.payments.includes(:payment_method, :source).order(:created_at)@refunds = @order.refunds+ @return_authorizations = @order.return_authorizations@customer_returns = @order.customer_returnsenddiff --git a/admin/app/controllers/spree/admin/reimbursement_types_controller.rb b/admin/app/controllers/spree/admin/reimbursement_types_controller.rbnew file mode 100644index 0000000000..59f25080d8--- /dev/null+++ b/admin/app/controllers/spree/admin/reimbursement_types_controller.rb@@ -0,0 +1,6 @@+module Spree+ module Admin+ class ReimbursementTypesController < ResourceController+ end+ end+enddiff --git a/admin/app/controllers/spree/admin/reimbursements_controller.rb b/admin/app/controllers/spree/admin/reimbursements_controller.rbnew file mode 100644index 0000000000..d3b7d4afcc--- /dev/null+++ b/admin/app/controllers/spree/admin/reimbursements_controller.rb@@ -0,0 +1,45 @@+module Spree+ module Admin+ class ReimbursementsController < ResourceController+ belongs_to 'spree/order', find_by: :number++ before_action :load_simulated_refunds, only: :edit++ rescue_from Spree::Core::GatewayError, with: :spree_core_gateway_error++ def perform+ @reimbursement.perform!(try_spree_current_user)+ redirect_to location_after_save+ end++ private++ def build_resource+ if params[:build_from_customer_return_id].present?+ customer_return = current_store.customer_returns.find(params[:build_from_customer_return_id])++ Reimbursement.build_from_customer_return(customer_return)+ else+ super+ end+ end++ def location_after_save+ if @reimbursement.reimbursed?+ spree.admin_order_reimbursement_path(parent, @reimbursement)+ else+ spree.edit_admin_order_reimbursement_path(parent, @reimbursement)+ end+ end++ def load_simulated_refunds+ @reimbursement_objects = @reimbursement.simulate+ end++ def spree_core_gateway_error(error)+ flash[:error] = error.message+ redirect_to spree.edit_admin_order_reimbursement_path(parent, @reimbursement)+ end+ end+ end+enddiff --git a/admin/app/controllers/spree/admin/return_authorizations_controller.rb b/admin/app/controllers/spree/admin/return_authorizations_controller.rbnew file mode 100644index 0000000000..21fd57b4af--- /dev/null+++ b/admin/app/controllers/spree/admin/return_authorizations_controller.rb@@ -0,0 +1,29 @@+module Spree+ module Admin+ class ReturnAuthorizationsController < ResourceController+ def index; end++ def cancel+ @return_authorization.cancel!+ flash[:success] = Spree.t(:return_authorization_canceled)+ redirect_back fallback_location: spree.edit_admin_order_path(@return_authorization.order)+ end++ private++ def location_after_destroy+ spree.edit_admin_order_path(@return_authorization.order)+ end++ def collection+ return @collection if @collection.present?++ params[:q] ||= {}++ # @search needs to be defined as this is passed to search_form_for+ @search = current_store.return_authorizations.accessible_by(current_ability, :index).ransack(params[:q])+ @collection = @search.result.order(created_at: :desc).page(params[:page]).per(params[:per_page])+ end+ end+ end+enddiff --git a/admin/app/controllers/spree/admin/return_items_controller.rb b/admin/app/controllers/spree/admin/return_items_controller.rbnew file mode 100644index 0000000000..285fa53278--- /dev/null+++ b/admin/app/controllers/spree/admin/return_items_controller.rb@@ -0,0 +1,9 @@+module Spree+ module Admin+ class ReturnItemsController < ResourceController+ def location_after_save+ spree.edit_admin_order_customer_return_path(@return_item.customer_return.order, @return_item.customer_return)+ end+ end+ end+enddiff --git a/admin/app/helpers/spree/admin/customer_returns_helper.rb b/admin/app/helpers/spree/admin/customer_returns_helper.rbnew file mode 100644index 0000000000..ecab7184dd--- /dev/null+++ b/admin/app/helpers/spree/admin/customer_returns_helper.rb@@ -0,0 +1,18 @@+module Spree+ module Admin+ module CustomerReturnsHelper+ def reimbursement_types+ @reimbursement_types ||= Spree::ReimbursementType.accessible_by(current_ability).active+ end++ def reimbursement_status_color(reimbursement)+ case reimbursement.reimbursement_status+ when 'reimbursed' then 'success'+ when 'pending' then 'notice'+ when 'errored' then 'error'+ else raise "unknown reimbursement status: #{reimbursement.reimbursement_status}"+ end+ end+ end+ end+enddiff --git a/admin/app/javascript/spree/admin/application.js b/admin/app/javascript/spree/admin/application.jsindex 65d84bdf63..8e7301cf46 100644--- a/admin/app/javascript/spree/admin/application.js+++ b/admin/app/javascript/spree/admin/application.js@@ -33,6 +33,7 @@ if (typeof Stimulus === 'undefined') {application = window.Stimulus}import AutoSubmit from '@stimulus-components/auto-submit'+import CheckboxSelectAll from 'stimulus-checkbox-select-all'import TextareaAutogrow from 'stimulus-textarea-autogrow'import Notification from 'stimulus-notification'import PasswordVisibility from 'stimulus-password-visibility'@@ -62,6 +63,7 @@ import PageBuilderController from 'spree/admin/controllers/page_builder_controllimport PasswordToggle from 'spree/admin/controllers/password_toggle_controller'import ProductFormController from 'spree/admin/controllers/product_form_controller'import RangeInputController from 'spree/admin/controllers/range_input_controller'+import ReturnItemsController from 'spree/admin/controllers/return_items_controller'import ReplaceController from 'spree/admin/controllers/replace_controller'import RowLinkController from 'spree/admin/controllers/row_link_controller'import RuleFormController from 'spree/admin/controllers/rule_form_controller'@@ -92,6 +94,7 @@ application.register('bootstrap-tabs', BootstrapTabs) // We should merge with taapplication.register('bulk-operation', BulkOperationController)application.register('calculator-fields', CalculatorFieldsController)application.register('calendar-range', CalendarRangeController)+application.register('checkbox-select-all', CheckboxSelectAll)application.register('clipboard', Clipboard)application.register('color-palette', ColorPaletteController)application.register('color-picker', ColorPickerController)@@ -109,6 +112,7 @@ application.register('password-visibility', PasswordVisibility)application.register('product-form', ProductFormController)application.register('range-input', RangeInputController)application.register('replace', ReplaceController)+application.register('return-items', ReturnItemsController)application.register('reveal', Reveal)application.register('row-link', RowLinkController)application.register('rule-form', RuleFormController)diff --git a/admin/app/javascript/spree/admin/controllers/return_items_controller.js b/admin/app/javascript/spree/admin/controllers/return_items_controller.jsnew file mode 100644index 0000000000..1433999786--- /dev/null+++ b/admin/app/javascript/spree/admin/controllers/return_items_controller.js@@ -0,0 +1,47 @@+import CheckboxSelectAll from 'stimulus-checkbox-select-all'++export default class extends CheckboxSelectAll {+ static targets = ['totalPreTaxRefund']++ connect() {+ this.updateTotalRefundAmount()+ }++ toggle(event) {+ super.toggle(event)+ this.updateTotalRefundAmount()+ }++ refresh() {+ super.refresh()+ this.updateTotalRefundAmount()+ }++ updateTotalRefundAmount() {+ var totalPretaxRefund = 0+ this.checked.forEach((checkbox) => {+ const returnItemRow = checkbox.closest('tr')+ const amount = parseFloat(returnItemRow.querySelector('.refund-amount-input').value)+ totalPretaxRefund += amount+ })++ const displayTotal = isNaN(totalPretaxRefund) ? '' : totalPretaxRefund.toFixed(2)+ this.totalPreTaxRefundTarget.innerText = displayTotal+ }++ updateSuggestedAmount = (event) => {+ const returnItemRow = event.target.closest('tr')+ const amount = this.calculateSuggestedAmount(returnItemRow)+ returnItemRow.querySelector('.refund-amount-input').value = amount.toFixed(2)++ this.updateTotalRefundAmount()+ }++ calculateSuggestedAmount = (row) => {+ const returnQuantity = parseInt(row.querySelector('.refund-quantity-input').value, 10)+ const purchasedQuantity = parseInt(row.querySelector('.purchased-quantity').innerText, 10)+ const chargedAmount = parseFloat(row.querySelector('.charged-amount').dataset.chargedAmount)+ const amount = (returnQuantity / purchasedQuantity) * chargedAmount+ return amount+ }+}diff --git a/admin/app/views/spree/admin/customer_returns/index.html.erb b/admin/app/views/spree/admin/customer_returns/index.html.erbnew file mode 100644index 0000000000..77ccd5c50c--- /dev/null+++ b/admin/app/views/spree/admin/customer_returns/index.html.erb@@ -0,0 +1,44 @@+<% content_for :title do %>+ <%= Spree.t(:customer_returns) %>+<% end %>++<% content_for :page_title do %>+ <%= Spree.t(:customer_returns) %>+<% end %>+<div class="card-lg p-0">++ <%= search_form_for [:admin, @search], url: spree.admin_customer_returns_path, class: "filter-wrap border-bottom", data: {controller: "filters reveal", reveal_hidden_class: "d-none"} do |f| %>+ <%= render "spree/admin/shared/filters_search_bar",+ param: :number_cont,+ label: Spree.t(:number) %>++ <%= render "spree/admin/shared/filter_badge_template" %>++ <div data-filters-target="badgesContainer" class="filter-badges-container"></div>+ <% end %>++ <% if @collection.any? %>+ <div class="table-responsive">+ <table class="table">+ <thead class="text-muted">+ <tr data-hook="rate_header">+ <th><%= Spree.t(:number) %></th>+ <th><%= Spree.t(:created_at) %></th>+ <th><%= Spree.t(:customer) %></th>+ <th><%= Spree.t(:order) %></th>+ <th><%= Spree.t(:reimbursement_status) %></th>+ <th><%= Spree.t(:pre_tax_total) %></th>+ </tr>+ </thead>+ <tbody>+ <%= render collection: @collection,+ partial: "spree/admin/orders/customer_returns/customer_return" %>+ </tbody>+ </table>+ </div>+ <% else %>+ <%= render "spree/admin/shared/no_resource_found" %>+ <% end %>++ <%= render partial: "spree/admin/shared/index_table_options", locals: { collection: @collection } %>+</div>diff --git a/admin/app/views/spree/admin/orders/_customer_returns.html.erb b/admin/app/views/spree/admin/orders/_customer_returns.html.erbindex 63297ffd67..64ae3e4ece 100644--- a/admin/app/views/spree/admin/orders/_customer_returns.html.erb+++ b/admin/app/views/spree/admin/orders/_customer_returns.html.erb@@ -1,23 +1,53 @@-<% if @customer_returns.any? %>+<% if @customer_returns.exists? && can?(:read, Spree::CustomerReturn) %><div class="card mb-4">- <div class="card-header">- <h5 class="card-title"><%= Spree.t(:customer_returns) %></h5>+ <div class="card-header justify-content-between">+ <h5 class="card-title">+ <%= Spree.t(:customer_returns) %></h5></div>- <div class="card-body">- <ul class="list-group">- <% @customer_returns.each do |customer_return| %>- <li class="list-group-item d-flex justify-content-between align-items-center">- <span class="text-muted"><%= local_time(customer_return.created_at) %></span>- <% if customer_return.fully_reimbursed? %>- <span class="badge badge-success"><%= Spree.t(:reimbursed) %></span>- <% else %>- <span class="badge badge-inactive"><%= Spree.t(:incomplete) %></span>+ <div class="card-body p-0">+ <div class="table-responsive bg-white">+ <table class="table">+ <thead class="border-bottom">+ <tr>+ <th><%= Spree.t(:date) %></th>+ <th><%= Spree.t(:status) %></th>+ <th><%= Spree.t(:pre_tax_total) %></th>+ </tr>+ </thead>+ <tbody>+ <% @customer_returns.each do |customer_return| %>+ <tr+ id="<%= spree_dom_id(customer_return) %>"+ data-controller="row-link"+ class="cursor-pointer"+ >+ <td data-action="click->row-link#openLink" class="font-weight-bolder">+ <%= link_to customer_return.number,+ (+ if can?(:edit, customer_return)+ spree.edit_admin_order_customer_return_path(@order, customer_return)+ else+ "#"+ end+ ),+ data: {+ row_link_target: "link",+ } %>+ </td>+ <td data-action="click->row-link#openLink">+ <% if customer_return.fully_reimbursed? %>+ <span class="badge badge-success"><%= Spree.t(:reimbursed) %></span>+ <% else %>+ <span class="badge badge-inactive"><%= Spree.t(:incomplete) %></span>+ <% end %>+ </td>+ <td data-action="click->row-link#openLink"><%= customer_return.display_pre_tax_total.to_html %></td>+ <td data-action="click->row-link#openLink"><%= local_time(customer_return.created_at) %></td>+ </tr><% end %>- <span><%= customer_return.display_pre_tax_total.to_html %></span>- <%= link_to_edit Spree.t(:edit), url: spree.edit_admin_order_customer_return_path(@order, customer_return), class: 'btn btn-light btn-sm' if can?(:edit, customer_return) %>- </li>- <% end %>- </ul>+ </tbody>+ </table>+ </div></div></div>-<% end %>\ No newline at end of file+<% end %>diff --git a/admin/app/views/spree/admin/orders/_header.html.erb b/admin/app/views/spree/admin/orders/_header.html.erbindex 38493bb13b..b0df3b0429 100644--- a/admin/app/views/spree/admin/orders/_header.html.erb+++ b/admin/app/views/spree/admin/orders/_header.html.erb@@ -5,25 +5,59 @@<%= page_header_back_button spree.edit_admin_order_path(@order) %><% end %><%= @order.number %>- <%= order_payment_state(@order, class: 'ml-3') %>- <%= order_shipment_state(@order, class: 'ml-3') %>- <%= local_time(@order.completed_at, class: 'badge badge-light with-tip ml-3') if @order.completed? %>+ <%= order_payment_state(@order, class: "ml-3") %>+ <%= order_shipment_state(@order, class: "ml-3") %>+ <%= if @order.completed?+ local_time(@order.completed_at, class: "badge badge-light with-tip ml-3")+ end %>+<% end %>++<%# TODO: Fix mobile %>+<% content_for :page_actions do %>+<% end %><% content_for(:page_actions_dropdown) do %><% if @order.completed? && spree.respond_to?(:order_path) %>- <%= link_to_with_icon 'eye',- Spree.t(:preview),- spree.order_path(@order, host: current_store.url, token: @order.token),- class: 'text-left dropdown-item',- target: '_blank' %>+ <%= link_to_with_icon "eye",+ Spree.t(:preview),+ spree.order_path(@order, host: current_store.url, token: @order.token),+ class: "text-left dropdown-item",+ target: "_blank" %><% end %><% if @order.completed? && can?(:resend, @order) %>- <%= link_to_with_icon 'send',- Spree.t(:resend),- resend_admin_order_path(@order),- data: { turbo_method: :post, turbo_confirm: Spree.t(:are_you_sure) },- class: 'btn btn text-left rounded-0 dropdown-item' %>+ <%= link_to_with_icon "send",+ Spree.t(:resend),+ spree.resend_admin_order_path(@order),+ data: {+ turbo_method: :post,+ turbo_confirm: Spree.t(:are_you_sure),+ },+ class: "btn text-left dropdown-item" %>+ <% end %>++ <% if @order.shipments.any?(&:shipped?) %>+ <% can_create_ra = can?(:create, Spree::ReturnAuthorization) %>+ <% can_create_cr =+ can?(:create, Spree::CustomerReturn) && @order.return_authorizations.exists? %>++ <% if can_create_ra || can_create_cr %>+ <div class="dropdown-divider"></div>++ <% if can_create_ra %>+ <%= link_to_with_icon "plus", Spree.t(:new_return_authorization),+ spree.new_admin_order_return_authorization_path(@order),+ class: "btn dropdown-item" %>+ <% end %>++ <% if can_create_cr && controller_name != "customer_returns" %>+ <%= link_to_with_icon "plus", Spree.t(:new_customer_return),+ spree.new_admin_order_customer_return_path(@order),+ class: "btn dropdown-item" %>+ <% end %>++ <div class="dropdown-divider"></div>+ <% end %><% end %><% if can?(:cancel, @order) %>@@ -31,7 +65,7 @@<%= link_to spree.cancel_admin_order_path(@order),class: 'text-left btn-danger dropdown-item',data: { turbo_method: :put, turbo_confirm: Spree.t(:are_you_sure) } do %>- <%= icon 'cancel' %>+ <%= icon "cancel" %><%= Spree.t(:cancel_order) %><% end %><div class="dropdown-divider"></div>diff --git a/admin/app/views/spree/admin/orders/_return_authorizations.html.erb b/admin/app/views/spree/admin/orders/_return_authorizations.html.erbnew file mode 100644index 0000000000..d46addedeb--- /dev/null+++ b/admin/app/views/spree/admin/orders/_return_authorizations.html.erb@@ -0,0 +1,52 @@+<% if @return_authorizations.exists? && can?(:read, Spree::ReturnAuthorization) %>+ <div class="card mb-4">+ <div class="card-header justify-content-between">+ <h5 class="card-title">+ <%= Spree.t(:return_authorizations) %></h5>+ </div>+ <div class="card-body p-0">+ <div class="table-responsive bg-white">+ <table class="table">+ <thead class="border-bottom">+ <tr>+ <th><%= Spree.t(:rma_number) %></th>+ <th><%= Spree.t(:status) %></th>+ <th><%= Spree.t(:pre_tax_total) %></th>+ <th><%= "#{Spree.t("date")}/#{Spree.t("time")}" %></th>+ </tr>+ </thead>+ <tbody>+ <% @return_authorizations.each do |return_authorization| %>+ <tr+ id="<%= spree_dom_id(return_authorization) %>"+ data-controller="row-link"+ class="cursor-pointer"+ >+ <td data-action="click->row-link#openLink" class="font-weight-bolder">+ <%= link_to return_authorization.number,+ (+ if can?(:edit, return_authorization)+ spree.edit_admin_order_return_authorization_path(@order, return_authorization)+ else+ spree.admin_order_return_authorization_path(@order, return_authorization)+ end+ ),+ data: {+ row_link_target: "link",+ } %>+ </td>+ <td data-action="click->row-link#openLink">+ <small class="badge badge-pill badge-<%= return_authorization.state %>">+ <%= Spree.t("return_authorization_states.#{return_authorization.state}") %>+ </small>+ </td>+ <td data-action="click->row-link#openLink"><%= return_authorization.display_pre_tax_total.to_html %></td>+ <td data-action="click->row-link#openLink"><%= local_time(return_authorization.created_at) %></td>+ </tr>+ <% end %>+ </tbody>+ </table>+ </div>+ </div>+ </div>+<% end %>diff --git a/admin/app/views/spree/admin/orders/customer_returns/_customer_return.html.erb b/admin/app/views/spree/admin/orders/customer_returns/_customer_return.html.erbnew file mode 100644index 0000000000..ab5aeaa4ed--- /dev/null+++ b/admin/app/views/spree/admin/orders/customer_returns/_customer_return.html.erb@@ -0,0 +1,31 @@+<% if customer_return.order.present? %>+ <tr+ id="<%= spree_dom_id customer_return %>"+ data-controller="row-link"+ class="cursor-pointer"+ >+ <td class="font-weight-bold" data-action="click->row-link#openLink">+ <% if can?(:edit, customer_return) %>+ <%= link_to customer_return.number,+ spree.edit_admin_order_customer_return_path( customer_return.order, customer_return),+ data: {+ row_link_target: "link",+ } %>+ <% else %>+ <%= customer_return.number %>+ <% end %>+ </td>+ <td data-action="click->row-link#openLink"><%= local_time(customer_return.created_at) %></td>+ <td data-action="click->row-link#openLink"><%= render "spree/admin/orders/customer_summary", order: customer_return.order %></td>+ <td data-action="click->row-link#openLink"><%= link_to customer_return.order.number,+ spree.edit_admin_order_path(customer_return.order) %></td>+ <td data-action="click->row-link#openLink">+ <% if customer_return.fully_reimbursed? %>+ <span class="badge badge-success"><%= Spree.t(:reimbursed) %></span>+ <% else %>+ <span class="badge badge-inactive"><%= Spree.t(:incomplete) %></span>+ <% end %>+ </td>+ <td data-action="click->row-link#openLink"><%= customer_return.display_pre_tax_total.to_html %></td>+ </tr>+<% end %>diff --git a/admin/app/views/spree/admin/orders/customer_returns/_reimbursements_table.html.erb b/admin/app/views/spree/admin/orders/customer_returns/_reimbursements_table.html.erbnew file mode 100644index 0000000000..996ae995f7--- /dev/null+++ b/admin/app/views/spree/admin/orders/customer_returns/_reimbursements_table.html.erb@@ -0,0 +1,40 @@+<table class="table table-condensed">+ <thead>+ <tr>+ <th><%= Spree.t(:number) %></th>+ <th><%= Spree.t(:total) %></th>+ <th><%= Spree.t(:status) %></th>+ <th><%= Spree.t(:date) %></th>+ </tr>+ </thead>+ <tbody>+ <% reimbursements.each do |reimbursement| %>+ <tr+ id="<%= spree_dom_id(reimbursement) %>"+ data-controller="row-link"+ class="cursor-pointer"+ >+ <td data-action="click->row-link#openLink" class="font-weight-bolder">+ <%= link_to reimbursement.number,+ (+ if reimbursement.reimbursed?+ url_for([:admin, @order, reimbursement])+ else+ url_for([:edit, :admin, @order, reimbursement])+ end+ ),+ data: {+ row_link_target: "link",+ } %>+ </td>+ <td data-action="click->row-link#openLink"><%= reimbursement.display_total %></td>+ <td data-action="click->row-link#openLink">+ <span class="badge badge-<%= reimbursement_status_color(reimbursement) %>">+ <%= reimbursement.reimbursement_status %>+ </span>+ </td>+ <td data-action="click->row-link#openLink"><%= local_time(reimbursement.created_at) %></td>+ </tr>+ <% end %>+ </tbody>+</table>diff --git a/admin/app/views/spree/admin/orders/customer_returns/_return_item_decision.html.erb b/admin/app/views/spree/admin/orders/customer_returns/_return_item_decision.html.erbnew file mode 100644index 0000000000..49197b32db--- /dev/null+++ b/admin/app/views/spree/admin/orders/customer_returns/_return_item_decision.html.erb@@ -0,0 +1,54 @@+<table class="show return-items-table table table-condensed index">+ <thead class="text-muted">+ <tr>+ <th><%= Spree.t(:product) %></th>+ <th><%= Spree.t(:pre_tax_amount) %></th>+ <th><%= Spree.t(:preferred_reimbursement_type) %></th>+ <th><%= Spree.t(:exchange_for) %></th>+ <th><%= Spree.t(:acceptance_errors) %></th>+ <% if show_decision %>+ <th></th>+ <% end %>+ </tr>+ </thead>+ <tbody>+ <% return_items.each do |return_item| %>+ <tr>+ <td>+ <%= if return_item.inventory_unit+ render "spree/admin/variants/variant",+ variant: return_item.inventory_unit.variant+ end %>+ </td>+ <td>+ <%= return_item.display_pre_tax_amount %>+ </td>+ <td>+ <%= reimbursement_type_name(return_item.preferred_reimbursement_type) %>+ </td>+ <td>+ <%= return_item.exchange_variant.try(:exchange_name) %>+ </td>+ <td>+ <%= if return_item.acceptance_status_errors.present?+ return_item.acceptance_status_errors+ end %>+ </td>+ <% if show_decision %>+ <td class='actions d-flex gap-2'>+ <% if can?(:accept, return_item) %>+ <%= button_to [:admin, return_item], { class: 'with-tip display-inline btn btn-primary btn-sm', params: { "return_item[acceptance_status]" => 'accepted' }, title: Spree.t(:accept), method: 'put' } do %>+ <%= Spree.t(:accept) %>+ <% end %>+ <% end %>+ <% if can?(:reject, return_item) %>+ <%= button_to [:admin, return_item], { class: 'with-tip display-inline btn btn-danger btn-sm', params: { "return_item[acceptance_status]" => 'rejected' }, title: Spree.t('actions.reject'), method: 'put' } do %>+ <%= Spree.t("actions.reject") %>+ <% end %>+ <% end %>+ </td>+ <% end %>+ </tr>+ <% end %>+ </tbody>+</table>diff --git a/admin/app/views/spree/admin/orders/customer_returns/_return_item_selection.html.erb b/admin/app/views/spree/admin/orders/customer_returns/_return_item_selection.html.erbnew file mode 100644index 0000000000..3ce2c8702e--- /dev/null+++ b/admin/app/views/spree/admin/orders/customer_returns/_return_item_selection.html.erb@@ -0,0 +1,72 @@+<div class="table-responsive bg-white rounded-lg">+ <table class="table">+ <thead class="border-bottom">+ <tr>+ <th>+ <div class="custom-control custom-checkbox ml-1">+ <input+ type="checkbox"+ class="custom-control-input"+ id="checkAllMasterCheckbox"+ data-checkbox-select-all-target="checkboxAll"+ >+ <label class="custom-control-label" for="checkAllMasterCheckbox"><span></span></label>+ </div>+ </th>+ <th><%= Spree.t(:product) %></th>+ <th><%= Spree.t(:sku) %></th>+ <th><%= Spree.t(:pre_tax_amount) %></th>+ <th><%= Spree.t(:exchange_for) %></th>+ <th><%= Spree.t(:resellable) %></th>+ </tr>+ </thead>+ <tbody>+ <%= f.fields_for :return_items, return_items do |item_fields| %>+ <% return_item = item_fields.object %>+ <tr>+ <td class="align-center">+ <div class="custom-control custom-checkbox ml-1">+ <%= item_fields.hidden_field :inventory_unit_id %>+ <%= item_fields.hidden_field :return_authorization_id %>+ <%= item_fields.hidden_field :pre_tax_amount %>++ <%= item_fields.check_box :returned,+ {+ checked: false,+ class: "add-item custom-control-input",+ data: {+ checkbox_select_all_target: "checkbox",+ price: return_item.pre_tax_amount,+ },+ },+ "1",+ "0" %>+ <%= item_fields.label :returned, class: "custom-control-label" do %>+ <span></span>+ <% end %>+ </div>+ </td>+ <td>+ <div class="variant-name">+ <%= link_to return_item.inventory_unit.variant.name,+ spree.edit_admin_product_path(return_item.inventory_unit.variant.product) %>+ </div>+ <div class="variant-options"><%= return_item.inventory_unit.variant.options_text %></div>+ </td>+ <td>+ <%= return_item.inventory_unit.variant.sku %>+ </td>+ <td class="align-center">+ <%= return_item.display_pre_tax_amount %>+ </td>+ <td class="align-center">+ <%= return_item.exchange_variant.try(:exchange_name) %>+ </td>+ <td class="align-center">+ <%= item_fields.check_box :resellable, { checked: return_item.resellable } %>+ </td>+ </tr>+ <% end %>+ </tbody>+ </table>+</div>diff --git a/admin/app/views/spree/admin/orders/customer_returns/edit.html.erb b/admin/app/views/spree/admin/orders/customer_returns/edit.html.erbnew file mode 100644index 0000000000..240c1a238d--- /dev/null+++ b/admin/app/views/spree/admin/orders/customer_returns/edit.html.erb@@ -0,0 +1,148 @@+<% content_for :page_title do %>+ <%= page_header_back_button spree.edit_admin_order_path(@order) %>+ <div class="d-flex gap-3 align-items-center">+ <span><%= Spree.t(:customer_return) %></span>+ <span><%= @customer_return.number %></span>++ <% if @customer_return.fully_reimbursed? %>+ <span class="badge badge-pill badge-success"><%= Spree.t(:reimbursed) %></span>+ <% else %>+ <span class="badge badge-pill badge-inactive"><%= Spree.t(:incomplete) %></span>+ <% end %>+ </div>+<% end %>++<ul class="list-group bg-white mb-4">+ <% if @customer_return.order %>+ <li class="list-group-item d-flex justify-content-between align-items-center">+ <%= Spree.t(:customer) %>+ <div>+ <%= render "spree/admin/orders/customer_summary", order: @customer_return.order %>+ </div>+ </li>+ <li class="list-group-item d-flex justify-content-between align-items-center">+ <%= Spree.t(:order) %>+ <strong><%= link_to @customer_return.order.number,+ spree.edit_admin_order_path(@customer_return.order) %></strong>+ </li>+ <% end %>+ <li class="list-group-item d-flex justify-content-between align-items-center">+ <%= Spree.t(:reimbursement_status) %>+ <% if @customer_return.fully_reimbursed? %>+ <span class="badge badge-success"><%= Spree.t(:reimbursed) %></span>+ <% else %>+ <span class="badge badge-inactive"><%= Spree.t(:incomplete) %></span>+ <% end %>+ </li>+ <li class="list-group-item d-flex justify-content-between align-items-center">+ <%= Spree.t(:pre_tax_total) %>+ <span><%= @customer_return.display_pre_tax_total.to_html %></span>+ </li>+</ul>+<% if @manual_intervention_return_items.any? %>+ <div class="card mb-4">+ <div class="card-header">+ <h5><%= Spree.t(:manual_intervention_required) %></h5>+ </div>+ <div class="card-body p-0">+ <%= render partial: "return_item_decision",+ locals: {+ return_items: @manual_intervention_return_items,+ show_decision: true,+ } %>+ </div>+ </div>+<% end %>++<% if @pending_return_items.any? %>+ <div class="card mb-4">+ <div class="card-header">+ <h5><%= Spree.t(:pending) %></h5>+ </div>+ <div class="card-body p-0">+ <%= render partial: "return_item_decision",+ locals: {+ return_items: @pending_return_items,+ show_decision: true,+ } %>+ </div>+ </div>+<% end %>++<% if @accepted_return_items.any? %>+ <div class="card mb-4">+ <div class="card-header">+ <h5><%= Spree.t(:accepted) %></h5>+ </div>+ <div class="card-body p-0">+ <%= render partial: "return_item_decision",+ locals: {+ return_items: @accepted_return_items,+ show_decision: false,+ } %>+ </div>+ </div>+<% end %>++<% if @rejected_return_items.any? %>+ <div class="card mb-4">+ <div class="card-header">+ <h5><%= Spree.t(:rejected) %></h5>+ </div>+ <div class="card-body p-0">+ <%= render partial: "return_item_decision",+ locals: {+ return_items: @rejected_return_items,+ show_decision: false,+ } %>+ </div>+ </div>+<% end %>++<div class="card mb-4">+ <div class="card-header">+ <h5><%= plural_resource_name(Spree::Reimbursement) %></h5>+ </div>+ <div class="card-body p-0">++ <% if @customer_return.reimbursements.any? %>+ <%= render partial: "reimbursements_table",+ locals: {+ reimbursements: @customer_return.reimbursements,+ } %>+ <% else %>+ <div+ class="+ text-muted p-5 d-flex align-items-center w-100 justify-content-center+ "+ >+ <%= Spree.t(+ :no_resource_found,+ resource: plural_resource_name(Spree::Reimbursement),+ ) %>+ </div>+ <% end %>+ </div>+</div>++<% if !@customer_return.fully_reimbursed? && @pending_reimbursements.empty? && can?(:create, Spree::Reimbursement) %>+ <fieldset class="mb-3">+ <% if @customer_return.completely_decided? %>+ <%= form_for [:admin, @order, Spree::Reimbursement.new] do |f| %>+ <%= hidden_field_tag :build_from_customer_return_id, @customer_return.id %>+ <%= f.button class: 'btn btn-primary' do %>+ <%= icon "plus" %>+ <%= Spree.t(:create_reimbursement) %>+ <% end %>+ <% end %>+ <% else %>+ <div+ class="+ text-muted p-5 d-flex align-items-center w-100 justify-content-center+ "+ >+ <%= Spree.t(:unable_to_create_reimbursements) %>+ </div>+ <% end %>+ </fieldset>+<% end %>diff --git a/admin/app/views/spree/admin/orders/customer_returns/new.html.erb b/admin/app/views/spree/admin/orders/customer_returns/new.html.erbnew file mode 100644index 0000000000..6709db6b8d--- /dev/null+++ b/admin/app/views/spree/admin/orders/customer_returns/new.html.erb@@ -0,0 +1,73 @@+<% content_for :page_title do %>+ <%= page_header_back_button spree.edit_admin_order_path(@order) %>+ <%= Spree.t(:new_customer_return) %>+<% end %>++<% if @rma_return_items.any? %>++ <%= render partial: "spree/admin/shared/error_messages",+ locals: {+ target: @customer_return,+ } %>++ <%= form_for [:admin, @order, @customer_return] do |f| %>+ <div class="card mb-4" data-controller="checkbox-select-all">+ <div class="card-header">+ <h6 class="card-title"><%= Spree.t(:items_in_rmas) %></h6>+ </div>+ <div class="card-body p-0">+ <% if @rma_return_items.any? %>+ <%= render partial: "return_item_selection",+ locals: {+ f: f,+ return_items: @rma_return_items,+ } %>+ <% else %>+ <div+ class="+ text-muted p-5 d-flex align-items-center w-100 justify-content-center+ "+ >+ <%= Spree.t(:none) %>+ </div>+ <% end %>+ </div>+ </div>++ <div class="card mb-4">+ <div class="card-body">+ <div class="form-group">+ <%= f.label :stock_location, raw(Spree.t(:stock_location) + required_span_tag) %>+ <%= f.select :stock_location_id,+ available_stock_locations_list,+ { include_blank: Spree.t(:select_a_stock_location) },+ class: "custom-select" %>+ <%= f.error_message_on :stock_location %>+ </div>+ </div>+ </div>++ <div class="form-actions">+ <%= button Spree.t(:create) %>+ <span class="or"><%= Spree.t(:or) %></span>+ <%= button_link_to Spree.t("actions.cancel"),+ spree.admin_order_customer_returns_path(@order),+ icon: "cancel" %>+ </div>+ <% end %>++<% else %>+ <div class="card">+ <div+ class="+ card-body text-muted d-flex align-items-center justify-content-center+ flex-column gap-2+ "+ >+ <%= Spree.t(:all_items_have_been_returned) %>,+ <%= link_to "#{Spree.t(:get_back_to_the)} #{Spree.t(:order)}",+ spree.edit_admin_order_path(@order) %>.+ </div>+ </div>++<% end %>diff --git a/admin/app/views/spree/admin/orders/edit.html.erb b/admin/app/views/spree/admin/orders/edit.html.erbindex 5243972e0c..a3c19c5384 100644--- a/admin/app/views/spree/admin/orders/edit.html.erb+++ b/admin/app/views/spree/admin/orders/edit.html.erb@@ -8,6 +8,7 @@<%= render 'line_items' %><%= render 'shipments' %><%= render 'customer_returns' %>+ <%= render 'return_authorizations' %><%= render 'payments'%><%= render 'body_custom' %>diff --git a/admin/app/views/spree/admin/orders/return_authorizations/_form.html.erb b/admin/app/views/spree/admin/orders/return_authorizations/_form.html.erbnew file mode 100644index 0000000000..fc0a17921b--- /dev/null+++ b/admin/app/views/spree/admin/orders/return_authorizations/_form.html.erb@@ -0,0 +1,176 @@+<% allow_return_item_changes = !@return_authorization.customer_returned_items? %>++<div data-controller="return-items">+ <div class="table-responsive card-lg p-0 mb-4">+ <table class="table table-condensed return-items-table">+ <thead class="text-muted">+ <tr>+ <th>+ <% if allow_return_item_changes %>+ <div class="custom-control custom-checkbox ml-1">+ <input+ type="checkbox"+ class="custom-control-input"+ id="checkAllMasterCheckbox"+ data-return-items-target="checkboxAll"+ >+ <label class="custom-control-label" for="checkAllMasterCheckbox"><span></span></label>+ </div>+ <% end %>+ </th>+ <th><%= Spree.t(:product) %></th>+ <th><%= Spree.t(:status) %></th>+ <th><%= Spree.t(:charged) %></th>+ <th><%= Spree.t(:purchased_quantity) %></th>+ <th style="min-width:130px;"><%= Spree.t(:return_quantity) %></th>+ <th style="min-width:150px;"><%= Spree.t(:pre_tax_refund_amount) %></th>+ <th><%= Spree.t(:reimbursement_type) %></th>+ <th><%= Spree.t(:exchange_for) %></th>+ </tr>+ </thead>+ <tbody>+ <%= f.fields_for :return_items, @form_return_items do |item_fields| %>+ <% return_item = item_fields.object %>+ <% inventory_unit = return_item.inventory_unit %>+ <% editable =+ inventory_unit.shipped? && allow_return_item_changes &&+ return_item.reimbursement.nil? %>+ <tr>+ <td class="inventory-unit-checkbox">+ <% if editable %>+ <div class="custom-control custom-checkbox ml-1">++ <%= item_fields.hidden_field :inventory_unit_id %>+ <%= item_fields.check_box :_destroy,+ {+ checked: return_item.persisted?,+ class: "add-item custom-control-input",+ data: {+ return_items_target: "checkbox",+ price: return_item.pre_tax_amount,+ },+ },+ "0",+ "1" %>+ <%= item_fields.label :_destroy, class: "custom-control-label" do %>+ <span></span>+ <% end %>+ </div>+ <% end %>+ </td>+ <td>+ <div class="variant-name">+ <%= link_to return_item.inventory_unit.variant.name,+ spree.edit_admin_product_path(return_item.inventory_unit.variant.product) %>+ </div>+ <div class="variant-options"><%= inventory_unit.variant.options_text %></div>+ </td>+ <td><%= inventory_unit.state.humanize %></td>+ <td+ class="charged-amount"+ data-charged-amount="<%= return_item.pre_tax_amount %>"+ >+ <%= return_item.display_pre_tax_amount %>+ </td>+ <td class="purchased-quantity">+ <%= inventory_unit.quantity %>+ </td>+ <td>+ <% if editable %>+ <%= item_fields.number_field :return_quantity,+ {+ class: "refund-quantity-input form-control",+ min: 0,+ data: {+ action: "return-items#updateSuggestedAmount",+ },+ max: return_item.return_quantity,+ } %>+ <% else %>+ <%= return_item.return_quantity %>+ <% end %>+ </td>+ <td>+ <% if editable %>+ <%= item_fields.text_field :pre_tax_amount,+ {+ class: "refund-amount-input form-control",+ data: {+ action: "return-items#updateTotalRefundAmount",+ },+ } %>+ <% else %>+ <%= return_item.display_pre_tax_amount %>+ <% end %>+ </td>+ <td>+ <% if editable %>+ <%= item_fields.select :preferred_reimbursement_type_id,+ @reimbursement_types.collect { |r| [r.name.humanize, r.id] },+ { include_blank: true },+ { class: "custom-select" } %>+ <% end %>+ </td>+ <td>+ <% if editable %>+ <% if return_item.exchange_processed? %>+ <%= return_item.exchange_variant.exchange_name %>+ <% else %>+ <%= item_fields.collection_select :exchange_variant_id,+ return_item.eligible_exchange_variants,+ :id,+ :exchange_name,+ { include_blank: true },+ {+ class:+ "custom-select return-item-exchange-selection",+ } %>+ <% end %>+ <% end %>+ </td>+ </tr>+ <% end %>+ </tbody>+ </table>+ </div>++ <div class="alert alert-info">+ <%= Spree.t(:total_pre_tax_refund) %>:+ <span data-return-items-target="totalPreTaxRefund">0.00</span>+ </div>++ <div class="card mb-4">+ <div class="card-body">+ <div class="form-group">+ <%= f.label :stock_location, raw(Spree.t(:stock_location) + required_span_tag) %>+ <%= f.select :stock_location_id,+ available_stock_locations_list,+ { include_blank: Spree.t(:select_a_stock_location) },+ { class: "custom-select" } %>+ <%= f.error_message_on :stock_location %>+ </div>++ <div class="form-group">+ <%= f.label :reason, raw(Spree.t(:reason) + required_span_tag) %>+ <%= f.select :return_authorization_reason_id,+ @reasons.collect { |r| [r.name, r.id] },+ { include_blank: Spree.t(:select_a_return_authorization_reason) },+ { class: "custom-select" } %>+ <%= f.error_message_on :reason %>+ </div>++ <div class="form-group">+ <%= f.label :memo, Spree.t(:memo) %>+ <%= f.text_area :memo, class: "form-control" %>+ <%= f.error_message_on :memo %>+ </div>+ </div>+ </div>+</div>++<% if Spree::Config[:expedited_exchanges] %>+ <div class="expedited-exchanges-warning"><%= Spree.t(+ :expedited_exchanges_warning,+ days_window: Spree::Config[:expedited_exchanges_days_window],+ ) %></div>+<% end %>diff --git a/admin/app/views/spree/admin/orders/return_authorizations/edit.html.erb b/admin/app/views/spree/admin/orders/return_authorizations/edit.html.erbnew file mode 100644index 0000000000..fdbaae59cf--- /dev/null+++ b/admin/app/views/spree/admin/orders/return_authorizations/edit.html.erb@@ -0,0 +1,45 @@+<% content_for :page_title do %>+ <%= page_header_back_button spree.edit_admin_order_path(@order) %>++ <div class="d-flex gap-3 align-items-center">+ <span><%= Spree.t(:return_authorization) %></span>+ <span><%= @return_authorization.number %></span>++ <span class="badge badge-pill badge-<%= @return_authorization.state %>">+ <%= Spree.t("return_authorization_states.#{@return_authorization.state}") %>+ </span>+ </div>+<% end %>++<%= render partial: "spree/admin/shared/error_messages",+locals: {+ target: @return_authorization,+} %>++<%= form_for [:admin, @order, @return_authorization] do |f| %>+ <%= render partial: "form", locals: { f: f } %>++ <div class="form-actions">+ <%= turbo_save_button_tag Spree.t("actions.update") %>+ <div class="ml-auto d-flex gap-3">+ <% if f.object.can_cancel? && can?(:cancel, f.object) %>+ <%= link_to Spree.t("actions.cancel"),+ spree.cancel_admin_return_authorization_path(f.object),+ class: "btn btn-danger",+ data: {+ turbo_method: :patch,+ turbo_confirm: Spree.t(:are_you_sure),+ } %>+ <% end %>+ <% if f.object.can_be_deleted? && can?(:delete, f.object) %>+ <%= link_to Spree.t("actions.destroy"),+ spree.admin_return_authorization_path(f.object),+ data: {+ turbo_method: :delete,+ turbo_confirm: Spree.t(:are_you_sure_delete),+ },+ class: "btn btn-danger" %>+ <% end %>+ </div>+ </div>+<% end %>diff --git a/admin/app/views/spree/admin/orders/return_authorizations/new.html.erb b/admin/app/views/spree/admin/orders/return_authorizations/new.html.erbnew file mode 100644index 0000000000..aac034fe91--- /dev/null+++ b/admin/app/views/spree/admin/orders/return_authorizations/new.html.erb@@ -0,0 +1,18 @@+<% content_for :page_title do %>+ <%= page_header_back_button spree.edit_admin_order_path(@order) %>+ <%= Spree.t(:new_return_authorization) %>+<% end %>++<%= render partial: 'spree/admin/shared/error_messages', locals: { target: @return_authorization } %>+<%= form_for [:admin, @order, @return_authorization] do |f| %>+ <fieldset>+ <%= render 'form', f: f %>++ <div class="form-actions">+ <%= button Spree.t(:create) %>+ <span class="or"><%= Spree.t(:or) %></span>+ <%= link_to Spree.t("actions.cancel"),+ spree.admin_order_return_authorizations_path(@order) %>+ </div>+ </fieldset>+<% end %>diff --git a/admin/app/views/spree/admin/orders/return_authorizations/show.html.erb b/admin/app/views/spree/admin/orders/return_authorizations/show.html.erbnew file mode 100644index 0000000000..473a9abd92--- /dev/null+++ b/admin/app/views/spree/admin/orders/return_authorizations/show.html.erb@@ -0,0 +1,128 @@+<% content_for :page_title do %>+ <%= page_header_back_button spree.edit_admin_order_path(@order) %>+ <div class="d-flex gap-3 align-items-center">+ <span><%= Spree.t(:return_authorization) %></span>+ <span><%= @return_authorization.number %></span>+ <span class="badge badge-pill badge-<%= @return_authorization.state %>">+ <%= Spree.t("return_authorization_states.#{@return_authorization.state}") %>+ </span>+ <%= local_time(+ @return_authorization.created_at,+ class: "badge badge-light with-tip",+ ) %>+ </div>+<% end %>++<%= render partial: "spree/admin/shared/error_messages",+locals: {+ target: @return_authorization,+} %>++<% if flash[:errors].present? %>+ <div class="alert alert-danger border-danger text-break">+ <%= flash[:errors].to_sentence %>+ </div>+<% end %>++<div class="table-responsive card-lg p-0 mb-4">+ <table class="table table-condensed return-items-table">+ <thead class="text-muted">+ <tr>+ <th><%= Spree.t(:product) %></th>+ <th><%= Spree.t(:status) %></th>+ <th><%= Spree.t(:purchased_quantity) %></th>+ <th><%= Spree.t(:return_quantity) %></th>+ <th><%= Spree.t(:total) %></th>+ <th><%= Spree.t(:refund_amount) %></th>+ <th><%= Spree.t(:reimbursement_type) %></th>+ <th><%= Spree.t(:exchange_for) %></th>+ </tr>+ </thead>+ <tbody>+ <% @return_authorization.return_items.each do |return_item| %>+ <tr>+ <td>+ <div class="variant-name">+ <%= link_to return_item.inventory_unit.variant.name,+ spree.edit_admin_product_path(return_item.inventory_unit.variant.product) %>+ </div>+ <div class="variant-options"><%= return_item.inventory_unit.variant.options_text %></div>+ </td>+ <td><%= return_item.inventory_unit.state.humanize %></td>+ <td class="purchased-quantity">+ <%= return_item.line_item.quantity %>+ </td>+ <td><%= return_item.return_quantity %></td>+ <td><%= return_item.pre_tax_amount %></td>+ <td><%= return_item.display_total %></td>+ <td><%= if return_item.preferred_reimbursement_type.present?+ return_item.preferred_reimbursement_type.name.humanize+ else+ "-"+ end %></td>+ <td><%= if return_item.exchange_processed?+ return_item.exchange_variant.exchange_name+ else+ "-"+ end %></td>+ </tr>+ <% end %>+ </tbody>+ </table>+</div>++<% if @return_authorization.reason.present? %>+ <div class="card mb-4">+ <div class="card-header">+ <h6 class="card-title"><%= Spree.t(:reason) %></h6>+ </div>+ <div class="card-body">+ <%= @return_authorization.reason.name %>+ </div>+ </div>+<% end %>++<% if @return_authorization.memo.present? %>+ <div class="card mb-4">+ <div class="card-header">+ <h6 class="card-title"><%= Spree.t(:memo) %></h6>+ </div>+ <div class="card-body">+ <%= @return_authorization.memo %>+ </div>+ </div>+<% end %>++<% if @refunds.any? %>+ <div class="card mb-4">+ <div class="card-header">+ <h5><%= Spree.t(:reimbursement) %></h5>+ </div>+ <div class="card-body p-0">+ <table class="table table-condensed">+ <thead class="text-muted">+ <tr>+ <th><%= Spree.t(:reimbursement_type) %></th>+ <th><%= Spree.t(:description) %></th>+ <th><%= Spree.t(:status) %></th>+ <th><%= Spree.t(:amount) %></th>+ </tr>+ </thead>+ <tbody>+ <% @refunds.each do |refund| %>+ <tr>+ <td><%= refund.class.name.demodulize %></td>+ <td><%= refund.description %></td>+ <td>+ <span class="badge badge-<%= refund.reimbursement.reimbursement_status %>">+ <%= Spree.t("reimbursement_states.#{refund.reimbursement.reimbursement_status}") %>+ </span>+ </td>+ <td><%= refund.display_amount %></td>+ </tr>+ <% end %>+ </tbody>+ </table>+ </div>+ </div>+<% end %>diff --git a/admin/app/views/spree/admin/payments/source_views/_storecredit.html.erb b/admin/app/views/spree/admin/payments/source_views/_storecredit.html.erbindex 12e22c9445..b1202a859d 100644--- a/admin/app/views/spree/admin/payments/source_views/_storecredit.html.erb+++ b/admin/app/views/spree/admin/payments/source_views/_storecredit.html.erb@@ -24,7 +24,7 @@</tr><tr><th><%= Spree.t(:issued_on) %>:</th>- <td><%= pretty_time(payment.source.created_at) %></td>+ <td><%= local_time(payment.source.created_at) %></td></tr></table></div>diff --git a/admin/app/views/spree/admin/reimbursements/edit.html.erb b/admin/app/views/spree/admin/reimbursements/edit.html.erbnew file mode 100644index 0000000000..6a3605aa7f--- /dev/null+++ b/admin/app/views/spree/admin/reimbursements/edit.html.erb@@ -0,0 +1,130 @@+<% content_for :page_title do %>+ <%= page_header_back_button spree.edit_admin_order_path(@reimbursement.order) %>+ <div class="d-flex gap-3 align-items-center">+ <span><%= Spree.t(:reimbursement) %></span>+ <span><%= @reimbursement.number %></span>++ <span class="badge badge-<%= reimbursement_status_color(@reimbursement) %>">+ <%= @reimbursement.reimbursement_status %>+ </span>+ </div>+<% end %>++<%= render partial: "spree/admin/shared/error_messages",+locals: {+ target: @reimbursement,+} %>++<%= form_for [:admin, @order, @reimbursement] do |f| %>+ <div class="card mb-4">+ <div class="card-header">+ <h5><%= Spree.t(:items_to_be_reimbursed) %></h5>+ </div>+ <div class="card-body p-0">+ <table class="table table-condensed reimbursement-return-items-table">+ <thead class="text-muted">+ <tr>+ <th><%= Spree.t(:product) %></th>+ <th><%= Spree.t(:preferred_reimbursement_type) %></th>+ <th><%= Spree.t(:reimbursement_type_override) %></th>+ <th><%= Spree.t(:pre_tax_refund_amount) %></th>+ <th><%= Spree.t(:total) %></th>+ <th><%= Spree.t(:exchange_for) %></th>+ </tr>+ </thead>+ <tbody>+ <%= f.fields_for :return_items, @reimbursement.return_items.sort_by(&:id) do |item_fields| %>+ <% return_item = item_fields.object %>+ <tr>+ <td>+ <%= render "spree/admin/variants/variant",+ variant: return_item.inventory_unit.variant %>+ </td>+ <td>+ <%= reimbursement_type_name(return_item.preferred_reimbursement_type) %>+ </td>+ <td>+ <%= item_fields.select(+ :override_reimbursement_type_id,+ reimbursement_types.collect { |r| [r.name.humanize, r.id] },+ { include_blank: true },+ { data: { controller: "autocomplete-select" } },+ ) %>+ </td>+ <td>+ <%= item_fields.text_field :pre_tax_amount,+ { class: "refund-amount-input form-control" } %>+ </td>+ <td>+ <%= return_item.display_total %>+ </td>+ <td>+ <% if return_item.exchange_processed? %>+ <%= return_item.exchange_variant.exchange_name %>+ <% else %>+ <%= item_fields.collection_select :exchange_variant_id,+ return_item.eligible_exchange_variants,+ :id,+ :exchange_name,+ { include_blank: true },+ {+ class:+ "custom-select return-item-exchange-selection",+ } %>+ <% end %>+ </td>+ </tr>+ <% end %>+ </tbody>+ </table>+ </div>+ </div>++ <div class="form-actions filter-actions actions mb-4">+ <%= turbo_save_button_tag Spree.t("actions.update"), class: "btn btn-primary" %>+ </div>+<% end %>++<div class="card mb-4">+ <div class="card-header">+ <h5><%= Spree.t(:calculated_reimbursements) %></h5>+ </div>+ <div class="card-body p-0">+ <table class="table table-condensed">+ <thead>+ <tr>+ <th><%= Spree.t(:reimbursement_type) %></th>+ <th><%= Spree.t(:description) %></th>+ <th><%= Spree.t(:amount) %></th>+ </tr>+ </thead>+ <tbody>+ <% @reimbursement_objects.each do |reimbursement_object| %>+ <tr data-hook="reimbursement_reimbursement_object_row">+ <td><%= reimbursement_object.class.name.demodulize %></td>+ <td><%= reimbursement_object.description %></td>+ <td><%= reimbursement_object.display_amount %></td>+ </tr>+ <% end %>+ </tbody>+ </table>+ </div>+</div>++<% if @order.has_non_reimbursement_related_refunds? %>+ <div class="alert alert-danger mb-2">+ <%= "#{Spree.t("note")}: #{Spree.t("this_order_has_already_received_a_refund")}. #{Spree.t("make_sure_the_above_reimbursement_amount_is_correct")}." %>+ </div>+<% end %>++<div class="form-actions fixed-form-actions">+ <% if [email protected]? %>+ <%= button_to [:perform, :admin, @order, @reimbursement], { class: 'btn btn-primary', method: 'post' } do %>+ <%= icon "money" %>+ <%= Spree.t(:reimburse) %>+ <% end %>+ <span class="or"><%= Spree.t(:or) %></span>+ <%= link_to Spree.t("actions.cancel"),+ url_for([:edit, :admin, @order, @reimbursement.customer_return]) %>+ <% end %>+</div>diff --git a/admin/app/views/spree/admin/reimbursements/show.html.erb b/admin/app/views/spree/admin/reimbursements/show.html.erbnew file mode 100644index 0000000000..834c985dc9--- /dev/null+++ b/admin/app/views/spree/admin/reimbursements/show.html.erb@@ -0,0 +1,113 @@+<% content_for :page_title do %>+ <%= page_header_back_button spree.edit_admin_order_path(@reimbursement.order) %>+ <div class="d-flex gap-3 align-items-center">+ <span><%= Spree.t(:reimbursement) %></span>+ <span><%= @reimbursement.number %></span>++ <span class="badge badge-<%= reimbursement_status_color(@reimbursement) %>">+ <%= @reimbursement.reimbursement_status %>+ </span>+ </div>+<% end %>++<%= render partial: "spree/admin/shared/error_messages",+locals: {+ target: @reimbursement,+} %>++<div class="card mb-4">+ <div class="card-header">+ <h5 class="card-title"><%= Spree.t(:items_reimbursed) %></h5>+ </div>+ <div class="card-body p-0">+ <table class="table reimbursement-reimbursement-items-table">+ <thead class="text-muted">+ <tr>+ <th><%= Spree.t(:product) %></th>+ <th><%= Spree.t(:preferred_reimbursement_type) %></th>+ <th><%= Spree.t(:reimbursement_type_override) %></th>+ <th><%= Spree.t(:exchange_for) %></th>+ <th><%= Spree.t(:pre_tax_amount) %></th>+ <th><%= Spree.t(:total) %></th>+ </tr>+ </thead>+ <tbody>+ <% @reimbursement.return_items.each do |return_item| %>+ <tr>+ <td>+ <%= render "spree/admin/variants/variant",+ variant: return_item.inventory_unit.variant %>+ </td>+ <td>+ <%= reimbursement_type_name(return_item.preferred_reimbursement_type) %>+ </td>+ <td>+ <%= reimbursement_type_name(return_item.override_reimbursement_type) %>+ </td>+ <td>+ <%= return_item.exchange_variant.try(:exchange_name) %>+ </td>+ <td>+ <%= return_item.display_pre_tax_amount %>+ </td>+ <td>+ <%= return_item.display_total %>+ </td>+ </tr>+ <% end %>+ </tbody>+ </table>+ </div>+</div>++<div class="card mb-4">+ <div class="card-header">+ <h5 class="card-title"><%= Spree.t(:refunds) %></h5>+ </div>+ <div class="card-body p-0">+ <table class="table table-condensed">+ <thead>+ <tr>+ <th><%= Spree.t(:amount) %></th>+ <th><%= Spree.t(:date) %></th>+ <th><%= Spree.t(:reason) %></th>+ </tr>+ </thead>+ <tbody>+ <% @reimbursement.refunds.includes(:reason).each do |refund| %>+ <tr id="<%= spree_dom_id(refund) %>">+ <td><%= refund.display_amount %></td>+ <td><%= local_time(refund.created_at) %></td>+ <td><%= refund.reason&.name %></td>+ </tr>+ <% end %>+ </tbody>+ </table>+ </div>+</div>++<% if @reimbursement.credits.any? %>+ <div class="card">+ <div class="card-header">+ <h5 class="card-title"><%= Spree.t(:credits) %></h5>+ </div>+ <div class="card-body p-0">+ <table class="table table-condensed">+ <thead>+ <tr>+ <th><%= Spree.t(:description) %></th>+ <th><%= Spree.t(:amount) %></th>+ </tr>+ </thead>+ <tbody>+ <% @reimbursement.credits.each do |credit| %>+ <tr id="<%= spree_dom_id(credit) %>">+ <td><%= credit.description %></td>+ <td><%= credit.display_amount %></td>+ </tr>+ <% end %>+ </tbody>+ </table>+ </div>+ </div>+<% end %>diff --git a/admin/app/views/spree/admin/return_authorizations/_filters.html.erb b/admin/app/views/spree/admin/return_authorizations/_filters.html.erbnew file mode 100644index 0000000000..787ac57a3a--- /dev/null+++ b/admin/app/views/spree/admin/return_authorizations/_filters.html.erb@@ -0,0 +1,39 @@+<%= search_form_for [:admin, @search], url: spree.admin_return_authorizations_path, class: "filter-wrap border-bottom", data: {controller: "filters reveal", reveal_hidden_class: "d-none"} do |f| %>+ <div class="d-flex flex-column flex-lg-row gap-2">+ <%= render "spree/admin/shared/filters_search_bar", param: :number_cont %>++ <div class="dropdown h-100 mr-2">+ <button+ class="btn btn-light h-100 dropdown-toggle"+ type="button"+ data-toggle="dropdown"+ aria-expanded="false"+ >+ <span class="text-muted font-weight-normal">+ <%= Spree.t(:show) %>:+ </span>+ <% if params.dig(:q, :state_eq).present? %>+ <%= Spree.t("return_authorization_states.#{params.dig(:q, :state_eq)}") %>+ <% else %>+ <%= Spree.t(:all) %>+ <% end %>+ </button>+ <div class="dropdown-menu dropdown-menu-right w-100" style="min-width: 200px">+ <%= active_link_to Spree.t(:all),+ params.to_unsafe_h.deep_merge({ q: { state_eq: "" } }),+ class: "dropdown-item",+ active: (params[:q] || {})[:state_eq].blank? %>+ <%= link_to Spree.t("return_authorization_states.authorized"),+ params.to_unsafe_h.deep_merge({ q: { state_eq: :authorized } }),+ class: "dropdown-item #{"active" if params.dig(:q, :state_eq) == "authorized"}" %>+ <%= link_to Spree.t("return_authorization_states.canceled"),+ params.to_unsafe_h.deep_merge({ q: { state_eq: :canceled } }),+ class: "dropdown-item #{"active" if params.dig(:q, :state_eq) == "canceled"}" %>+ </div>+ </div>+ </div>++ <%= render "spree/admin/shared/filter_badge_template" %>++ <div data-filters-target="badgesContainer" class="filter-badges-container"></div>+<% end %>diff --git a/admin/app/views/spree/admin/return_authorizations/_list.html.erb b/admin/app/views/spree/admin/return_authorizations/_list.html.erbnew file mode 100644index 0000000000..b73c64dcfd--- /dev/null+++ b/admin/app/views/spree/admin/return_authorizations/_list.html.erb@@ -0,0 +1,30 @@+<% if @collection.any? %>+ <div class="table-responsive">+ <table class="table">+ <thead class="text-muted">+ <tr>+ <th><%= Spree.t(:number) %></th>+ <th><%= Spree.t(:created_at) %></th>+ <th><%= Spree.t(:customer) %></th>+ <th class="text-center w-10"><%= Spree.t(:status) %></th>+ </tr>+ </thead>+ <tbody>+ <%= render partial: "spree/admin/return_authorizations/return_authorization",+ collection: @collection,+ cached: spree_base_cache_scope %>+ </tbody>+ </table>+ </div>+<% else %>+ <div+ class="+ text-muted p-5 d-flex align-items-center w-100 justify-content-center+ "+ >+ <%= Spree.t(+ :no_resource_found,+ resource: plural_resource_name(Spree::ReturnAuthorization),+ ) %>.+ </div>+<% end %>diff --git a/admin/app/views/spree/admin/return_authorizations/_return_authorization.html.erb b/admin/app/views/spree/admin/return_authorizations/_return_authorization.html.erbnew file mode 100644index 0000000000..9e0200c8a1--- /dev/null+++ b/admin/app/views/spree/admin/return_authorizations/_return_authorization.html.erb@@ -0,0 +1,40 @@+<% return_url =+ (+ if can?(:edit, return_authorization)+ spree.edit_admin_order_return_authorization_path(+ return_authorization,+ order_id: return_authorization.order,+ )+ else+ spree.admin_order_return_authorization_path(+ return_authorization,+ order_id: return_authorization.order,+ )+ end+ ) %>++<tr+ id="<%= spree_dom_id return_authorization %>"+ data-controller="row-link"+ class="cursor-pointer"+>+ <td data-action="click->row-link#openLink">+ <%= link_to return_authorization.number,+ return_url,+ class: "font-weight-bold",+ data: {+ row_link_target: :link,+ } %>+ </td>+ <td data-action="click->row-link#openLink">+ <%= link_to local_time_ago(return_authorization.created_at, class: "with-tip"),+ return_url,+ class: "text-dark" %>+ </td>+ <td data-action="click->row-link#openLink">+ <%= render "spree/admin/orders/customer_summary", order: return_authorization.order %>+ </td>+ <td class="text-center w-10" data-action="click->row-link#openLink">+ <span class="badge badge-<%= return_authorization.state %>"><%= Spree.t("return_authorization_states.#{return_authorization.state}") %></span>+ </td>+</tr>diff --git a/admin/app/views/spree/admin/return_authorizations/index.html.erb b/admin/app/views/spree/admin/return_authorizations/index.html.erbnew file mode 100644index 0000000000..a94adb1fea--- /dev/null+++ b/admin/app/views/spree/admin/return_authorizations/index.html.erb@@ -0,0 +1,14 @@+<% content_for :page_title do %>+ <%= Spree.t(:return_authorizations) %>+<% end %>++<div class="card-lg p-0">+ <%= render "spree/admin/return_authorizations/filters" %>+ <%= render "spree/admin/return_authorizations/list" %>++ <%= render partial: "spree/admin/shared/index_table_options",+ locals: {+ collection: @collection,+ per_page_action: :return_authorizations,+ } %>+</div>diff --git a/admin/app/views/spree/admin/shared/sidebar/_orders_nav.html.erb b/admin/app/views/spree/admin/shared/sidebar/_orders_nav.html.erbindex 5ee33ab0cf..b220bf59b0 100644--- a/admin/app/views/spree/admin/shared/sidebar/_orders_nav.html.erb+++ b/admin/app/views/spree/admin/shared/sidebar/_orders_nav.html.erb@@ -1,4 +1,4 @@-<% orders_active = %[orders checkouts return_index customer_returns].include?(controller_name) || @order %>+<% orders_active = %[orders checkouts].include?(controller_name) || @order %><li class="nav-item"><%= active_link_to spree.admin_orders_path, class: 'nav-link d-flex align-items-center', active: orders_active do %><%= icon 'inbox', class: 'mr-1' %>@@ -10,7 +10,7 @@</span><% end %><% end %>- <% if orders_active && (ready_to_ship_orders_count&.positive? || can?(:manage, :customer_returns) || can?(:manage, :checkouts)) %>+ <% if orders_active && (ready_to_ship_orders_count&.positive? || can?(:manage, :checkouts)) %><ul class="ml-4 pl-1 mb-2 nav-submenu flex-column mt-1"><% if ready_to_ship_orders_count&.positive? %><li class="nav-item">@@ -23,12 +23,6 @@</li><% end %>- <% if can?(:manage, :customer_returns) %>- <li class="nav-item">- <%= active_link_to Spree.t(:returns), spree.admin_customer_returns_path, class: 'nav-link' %>- </li>- <% end %>-<% if can?(:manage, :checkouts) %><li class="nav-item"><%= active_link_to Spree.t(:draft_orders), spree.admin_checkouts_path, class: 'nav-link' %>diff --git a/admin/app/views/spree/admin/shared/sidebar/_returns_nav.html.erb b/admin/app/views/spree/admin/shared/sidebar/_returns_nav.html.erbnew file mode 100644index 0000000000..49a32095f0--- /dev/null+++ b/admin/app/views/spree/admin/shared/sidebar/_returns_nav.html.erb@@ -0,0 +1,20 @@+<% returns_active = %[customer_returns return_authorizations].include?(controller_name) %>++<% if can?(:manage, :customer_returns) || can?(:manage, :return_authorizations) %>+ <li class="nav-item">+ <%= active_link_to spree.admin_customer_returns_path, class: 'nav-link d-flex align-items-center', active: returns_active do %>+ <%= icon 'receipt-refund', class: 'mr-1' %>+ <%= Spree.t(:returns) %>+ <% end %>++ <% if returns_active %>+ <ul class="ml-4 pl-1 mb-2 nav-submenu flex-column mt-1">+ <% if can?(:manage, :return_authorizations) %>+ <li class="nav-item">+ <%= active_link_to Spree.t(:return_authorizations), spree.admin_return_authorizations_path, class: 'nav-link' %>+ </li>+ <% end %>+ </ul>+ <% end %>+ </li>+<% end %>\ No newline at end of filediff --git a/admin/app/views/spree/admin/shared/sidebar/_store_nav.html.erb b/admin/app/views/spree/admin/shared/sidebar/_store_nav.html.erbindex dfd41fa9f5..fec0372f6e 100644--- a/admin/app/views/spree/admin/shared/sidebar/_store_nav.html.erb+++ b/admin/app/views/spree/admin/shared/sidebar/_store_nav.html.erb@@ -1,6 +1,6 @@<% settings_active = %w[stores zones shipping_methods oauth_applicationspayment_methods refund_reasons reimbursement_types- return_authorizations shipping_categories store_credit_categories+ shipping_categories store_credit_categoriessyncs tax_categories tax_rates webhooks accountscustom_domains audits exports imports return_authorization_reasonsdocuments stripe_tax_registrations members subscriptions stock_locations webhooks_subscribers].include?(controller_name) %>@@ -93,19 +93,9 @@</li><%= render 'spree/admin/shared/sidebar/orders_nav' %>+ <%= render 'spree/admin/shared/sidebar/returns_nav' %><%= render 'spree/admin/shared/sidebar/products_nav' %>- <% if enterprise_edition? %>- <%= render 'spree/admin/shared/sidebar/vendors_nav' %>- <% else%>- <li class="nav-item">- <%= external_link_to nil, 'https://spreecommerce.org/pricing', class: 'nav-link d-flex align-items-center w-100' do %>- <%= icon 'heart-handshake' %>- <%= Spree.t(:vendors) %>-- <span class="badge badge-dark ml-auto with-tip rounded-pill" title="This feature is part of the Enterprise Edition.">Enterprise</span>- <% end %>- </li>- <% end %>+ <%= render 'spree/admin/shared/sidebar/vendors_nav' %><% if can?(:manage, Spree.user_class) %><li class="nav-item">diff --git a/admin/app/views/spree/admin/shared/sidebar/_vendors_nav.html.erb b/admin/app/views/spree/admin/shared/sidebar/_vendors_nav.html.erbnew file mode 100644index 0000000000..84d4dd6c5c--- /dev/null+++ b/admin/app/views/spree/admin/shared/sidebar/_vendors_nav.html.erb@@ -0,0 +1,8 @@+<li class="nav-item">+ <%= external_link_to nil, 'https://spreecommerce.org/pricing', class: 'nav-link d-flex align-items-center w-100' do %>+ <%= icon 'heart-handshake' %>+ <%= Spree.t(:vendors) %>++ <span class="badge badge-dark ml-auto with-tip rounded-pill" title="This feature is part of the Enterprise Edition.">Enterprise</span>+ <% end %>+</li>\ No newline at end of filediff --git a/admin/config/routes.rb b/admin/config/routes.rbindex a913fc141b..3e49095909 100644--- a/admin/config/routes.rb+++ b/admin/config/routes.rb@@ -67,16 +67,8 @@ Spree::Core::Engine.add_routes doendendresources :line_items, except: :show- resources :customer_returns, only: [:index, :new, :edit, :create, :update] do- member do- put :refund- end- end- resources :return_authorizations do- member do- put :cancel- end- end+ resources :customer_returns, except: [:index, :destroy], controller: 'orders/customer_returns'+ resources :return_authorizations, except: [:index, :destroy], controller: 'orders/return_authorizations'resources :payments, except: [:index, :show] domember doput :capture@@ -85,7 +77,7 @@ Spree::Core::Engine.add_routes doresources :refunds, only: [:new, :create, :edit, :update]endresources :payment_links, only: [:create], controller: 'orders/payment_links'- resources :reimbursements, only: [:index, :create, :show, :edit, :update] do+ resources :reimbursements, except: [:destroy, :index] domember dopost :performend@@ -119,8 +111,12 @@ Spree::Core::Engine.add_routes doget 'promotion_rules/option_values_search', defaults: { format: :json }# returns- get '/return_authorizations', to: 'return_index#return_authorizations', as: :return_authorizations- get '/customer_returns', to: 'return_index#customer_returns', as: :customer_returns+ resources :return_authorizations, only: [:index, :destroy] do+ member do+ patch :cancel+ end+ end+ resources :customer_returns, only: :indexresources :return_items, only: [:update]# translationsdiff --git a/admin/spec/controllers/spree/admin/customer_returns_controller_spec.rb b/admin/spec/controllers/spree/admin/customer_returns_controller_spec.rbnew file mode 100644index 0000000000..e23c55c315--- /dev/null+++ b/admin/spec/controllers/spree/admin/customer_returns_controller_spec.rb@@ -0,0 +1,40 @@+require 'spec_helper'++RSpec.describe Spree::Admin::CustomerReturnsController do+ stub_authorization!+ render_views++ let(:order) { create(:shipped_order) }+ let!(:customer_return) { create(:customer_return) }++ describe '#index' do+ subject { get :index }++ before { subject }++ it 'is successful' do+ expect(response).to be_successful+ end+ end++ describe '#collection' do+ let!(:customer_returns) { create_list(:customer_return, 3) }++ it 'orders by created_at desc' do+ # Call the private method directly+ collection = controller.send(:collection)++ expect(collection).to eq [*customer_returns.reverse, customer_return]+ end++ it 'paginates the results' do+ allow(controller).to receive(:params).and_return({ per_page: '2', page: '1' })++ # Call the private method directly+ collection = controller.send(:collection)++ expect(collection.limit_value).to eq 2+ expect(collection.current_page).to eq 1+ end+ end+enddiff --git a/admin/spec/controllers/spree/admin/orders/customer_returns_controller_spec.rb b/admin/spec/controllers/spree/admin/orders/customer_returns_controller_spec.rbnew file mode 100644index 0000000000..c4cfb9c7ac--- /dev/null+++ b/admin/spec/controllers/spree/admin/orders/customer_returns_controller_spec.rb@@ -0,0 +1,107 @@+require 'spec_helper'++RSpec.describe Spree::Admin::Orders::CustomerReturnsController do+ stub_authorization!+ render_views++ let(:order) { create(:shipped_order) }+ let(:return_authorization) { create(:return_authorization, order: order) }+ let!(:return_item) { create(:return_item, return_authorization: return_authorization, inventory_unit: order.inventory_units.shipped.first) }++ describe '#new' do+ subject { get :new, params: { order_id: order.number } }++ before { subject }++ it 'is successful' do+ expect(response).to be_successful+ end++ it 'loads variables' do+ expect(assigns(:rma_return_items)).to eq [return_item]+ end+ end++ describe '#create' do+ subject do+ post :create, params: {+ order_id: order.number,+ customer_return: {+ stock_location_id: order.shipments.first.stock_location.id,+ return_items_attributes: {+ 1 => {+ id: return_item.id,+ returned: 1,+ pre_tax_amount: 10,+ resellable: 1+ }+ }+ }+ }+ end++ it 'creates a new customer return' do+ subject++ expect(order.customer_returns.count).to eq 1++ customer_return = order.customer_returns.first+ expect(customer_return.return_items.count).to eq 1+ expect(customer_return.return_items.first.pre_tax_amount).to eq 10+ expect(customer_return.return_items.first.resellable).to eq true+ end++ it 'redirects to order edit page' do+ subject++ expect(response).to redirect_to(edit_admin_order_path(order))+ end+ end++ describe '#edit' do+ subject { get :edit, params: { order_id: order.number, id: customer_return.id } }++ let(:customer_return) { create(:customer_return_without_return_items, return_items: [return_item]) }++ before { subject }++ it 'is successful' do+ expect(response).to be_successful+ end++ it 'loads variables' do+ expect(assigns(:rma_return_items)).to eq []+ expect(assigns(:pending_return_items)).to eq []+ expect(assigns(:accepted_return_items)).to eq [return_item]+ expect(assigns(:rejected_return_items)).to eq []+ expect(assigns(:manual_intervention_return_items)).to eq []+ expect(assigns(:pending_reimbursements)).to eq []+ end+ end++ describe '#update' do+ subject do+ put :update, params: {+ order_id: order.number,+ id: customer_return.id,+ customer_return: {+ return_items_attributes: {+ 1 => {+ id: return_item.id,+ pre_tax_amount: 12+ }+ }+ }+ }+ end++ let(:customer_return) { create(:customer_return_without_return_items, return_items: [return_item]) }++ it 'updates the return item' do+ subject++ return_item.reload+ expect(return_item.pre_tax_amount).to eq 12+ end+ end+enddiff --git a/admin/spec/controllers/spree/admin/orders/return_authorizations_controller_spec.rb b/admin/spec/controllers/spree/admin/orders/return_authorizations_controller_spec.rbnew file mode 100644index 0000000000..e9fc6d522c--- /dev/null+++ b/admin/spec/controllers/spree/admin/orders/return_authorizations_controller_spec.rb@@ -0,0 +1,146 @@+require 'spec_helper'++RSpec.describe Spree::Admin::Orders::ReturnAuthorizationsController do+ stub_authorization!+ render_views++ let(:order) { create(:shipped_order) }+ let(:return_authorization) { create(:return_authorization, order: order) }+ let!(:return_item) { create(:return_item, return_authorization: return_authorization, inventory_unit: order.inventory_units.shipped.first) }+ let!(:reimbursement_type) { create(:reimbursement_type) }++ describe '#new' do+ subject { get :new, params: { order_id: order.number } }++ before { subject }++ it 'is successful' do+ expect(response).to be_successful+ end++ it 'loads variables' do+ expect(assigns(:return_authorization)).to be_a_new(Spree::ReturnAuthorization)+ expect(assigns(:form_return_items)).to be_present+ expect(assigns(:reimbursement_types)).to be_present+ expect(assigns(:reasons)).to be_present+ end+ end++ describe '#create' do+ subject do+ post :create, params: {+ order_id: order.number,+ return_authorization: {+ memo: 'Test memo',+ return_authorization_reason_id: reason.id,+ stock_location_id: order.shipments.first.stock_location_id,+ return_items_attributes: {+ 0 => {+ inventory_unit_id: order.inventory_units.shipped.first.id,+ pre_tax_amount: 10+ }+ }+ }+ }+ end++ let(:reason) { create(:return_authorization_reason) }++ it 'creates a new return authorization' do+ expect { subject }.to change(Spree::ReturnAuthorization, :count).by(1)++ return_auth = order.return_authorizations.last+ expect(return_auth.memo).to eq 'Test memo'+ expect(return_auth.return_items.count).to eq 1+ expect(return_auth.return_items.first.pre_tax_amount).to eq 10+ end++ it 'redirects to the edit page of the return authorization' do+ subject+ expect(response).to redirect_to(spree.edit_admin_order_return_authorization_path(order, order.return_authorizations.last))+ end+ end++ describe '#edit' do+ subject { get :edit, params: { order_id: order.number, id: return_authorization.id } }++ before { subject }++ it 'is successful' do+ expect(response).to be_successful+ end++ it 'loads variables' do+ expect(assigns(:return_authorization)).to eq return_authorization+ expect(assigns(:form_return_items)).to be_present+ expect(assigns(:reimbursement_types)).to be_present+ expect(assigns(:reasons)).to be_present+ end+ end++ describe '#update' do+ subject do+ put :update, params: {+ order_id: order.number,+ id: return_authorization.id,+ return_authorization: {+ memo: 'Updated memo',+ return_items_attributes: {+ 0 => {+ id: return_item.id,+ pre_tax_amount: 15+ }+ }+ }+ }+ end++ it 'updates the return authorization' do+ subject++ return_authorization.reload+ expect(return_authorization.memo).to eq 'Updated memo'+ expect(return_authorization.return_items.first.pre_tax_amount).to eq 15+ end++ it 'redirects to the edit page of the return authorization' do+ subject+ expect(response).to redirect_to(spree.edit_admin_order_return_authorization_path(order, return_authorization))+ end+ end++ describe '#show' do+ subject { get :show, params: { order_id: order.number, id: return_authorization.id } }++ before { subject }++ it 'is successful' do+ expect(response).to be_successful+ end+ end++ describe '#load_return_authorization_reasons' do+ subject { get :new, params: { order_id: order.number } }++ let!(:active_reason) { create(:return_authorization_reason) }+ let!(:inactive_reason) { create(:return_authorization_reason, active: false) }++ it 'loads only active reasons for new RMAs' do+ subject+ expect(assigns(:reasons)).to include(active_reason)+ expect(assigns(:reasons)).not_to include(inactive_reason)+ end++ context 'with an inactive reason already assigned' do+ before do+ return_authorization.update(reason: inactive_reason)+ end++ it 'includes the inactive reason when editing' do+ get :edit, params: { order_id: order.number, id: return_authorization.id }+ expect(assigns(:reasons)).to include(active_reason)+ expect(assigns(:reasons)).to include(inactive_reason)+ end+ end+ end+enddiff --git a/admin/spec/controllers/spree/admin/reimbursements_controller_spec.rb b/admin/spec/controllers/spree/admin/reimbursements_controller_spec.rbnew file mode 100644index 0000000000..a68d6607ac--- /dev/null+++ b/admin/spec/controllers/spree/admin/reimbursements_controller_spec.rb@@ -0,0 +1,60 @@+require 'spec_helper'++describe Spree::Admin::ReimbursementsController, type: :controller do+ stub_authorization!+ render_views++ let(:user) { create(:admin_user) }++ before do+ Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false)+ end++ describe '#perform' do+ subject do+ post :perform, params: { order_id: order.to_param, id: reimbursement.to_param }+ end++ let(:reimbursement) { create(:reimbursement, performed_by: nil) }+ let(:customer_return) { reimbursement.customer_return }+ let(:order) { reimbursement.order }+ let(:return_items) { reimbursement.return_items }+ let(:payment) { order.payments.first }++ it 'redirects to customer return page' do+ subject+ expect(response).to redirect_to spree.admin_order_reimbursement_path(order, reimbursement)+ end++ it 'performs the reimbursement' do+ expect do+ subject+ end.to change { payment.refunds.count }.by(1)+ expect(payment.refunds.last.amount).to be > 0+ expect(payment.refunds.last.amount).to eq return_items.to_a.sum(&:total)+ end++ it 'assigns reimbursement performer' do+ expect { subject }.to change { reimbursement.reload.performed_by }.from(nil).to(user)+ end++ context 'a Spree::Core::GatewayError is raised' do+ before do+ def controller.perform+ raise Spree::Core::GatewayError, 'An error has occurred'+ end+ end++ it 'sets an error message with the correct text' do+ subject+ expect(flash[:error]).to eq 'An error has occurred'+ end++ it 'redirects to the edit page' do+ subject+ redirect_path = spree.edit_admin_order_reimbursement_path(order, assigns(:reimbursement))+ expect(response).to redirect_to(redirect_path)+ end+ end+ end+enddiff --git a/admin/spec/controllers/spree/admin/return_authorizations_controller_spec.rb b/admin/spec/controllers/spree/admin/return_authorizations_controller_spec.rbnew file mode 100644index 0000000000..23f3443a73--- /dev/null+++ b/admin/spec/controllers/spree/admin/return_authorizations_controller_spec.rb@@ -0,0 +1,86 @@+require 'spec_helper'++RSpec.describe Spree::Admin::ReturnAuthorizationsController do+ stub_authorization!+ render_views++ let(:order) { create(:shipped_order) }+ let(:return_authorization) { create(:return_authorization, order: order) }+ let!(:return_item) { create(:return_item, return_authorization: return_authorization, inventory_unit: order.inventory_units.shipped.first) }++ describe '#index' do+ subject { get :index }++ before { subject }++ it 'is successful' do+ expect(response).to be_successful+ end+ end++ describe '#cancel' do+ subject { put :cancel, params: { id: return_authorization.id } }++ it 'cancels the return authorization' do+ expect { subject }.to change { return_authorization.reload.state }.from('authorized').to('canceled')+ end++ it 'sets a flash message' do+ subject+ expect(flash[:success]).to eq Spree.t(:return_authorization_canceled)+ end++ it 'redirects to the order edit page' do+ subject+ expect(response).to redirect_to(spree.edit_admin_order_path(return_authorization.order))+ end+ end++ describe '#destroy' do+ subject { delete :destroy, params: { id: return_authorization.id } }++ it 'destroys the return authorization' do+ expect { subject }.to change(Spree::ReturnAuthorization, :count).by(-1)+ end++ it 'redirects to the order edit page' do+ subject+ expect(response).to redirect_to(spree.edit_admin_order_path(return_authorization.order))+ end+ end++ describe '#collection' do+ let!(:return_authorizations) { create_list(:return_authorization, 3) }++ before do+ # Create one for a different store to test store filtering+ other_store = create(:store)+ create(:return_authorization, order: create(:shipped_order, store: other_store))+ end++ it 'returns return authorizations for the current store' do+ # Call the private method directly+ collection = controller.send(:collection)++ expect(collection.count).to eq 4 # 3 created above + 1 from let+ expect(collection.all? { |ra| ra.order.store == Spree::Store.default }).to be true+ end++ it 'orders by created_at desc' do+ # Call the private method directly+ collection = controller.send(:collection)++ expect(collection).to eq [*return_authorizations.reverse, return_authorization]+ end++ it 'paginates the results' do+ allow(controller).to receive(:params).and_return({ per_page: '2', page: '1' })++ # Call the private method directly+ collection = controller.send(:collection)++ expect(collection.limit_value).to eq 2+ expect(collection.current_page).to eq 1+ end+ end+enddiff --git a/api/app/serializers/spree/api/v2/platform/reimbursement_serializer.rb b/api/app/serializers/spree/api/v2/platform/reimbursement_serializer.rbindex d215961358..b7e873a144 100644--- a/api/app/serializers/spree/api/v2/platform/reimbursement_serializer.rb+++ b/api/app/serializers/spree/api/v2/platform/reimbursement_serializer.rb@@ -7,6 +7,7 @@ module Spreebelongs_to :orderbelongs_to :customer_return+ belongs_to :performed_by, serializer: Spree::Api::V2::Platform::AdminUserSerializerhas_many :refundshas_many :reimbursement_credits, object_method_name: :credits, id_method_name: :credit_idsdiff --git a/api/spec/serializers/spree/api/v2/platform/reimbursement_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/reimbursement_serializer_spec.rbindex b3363f5a38..d657c7f951 100644--- a/api/spec/serializers/spree/api/v2/platform/reimbursement_serializer_spec.rb+++ b/api/spec/serializers/spree/api/v2/platform/reimbursement_serializer_spec.rb@@ -1,15 +1,16 @@require 'spec_helper'describe Spree::Api::V2::Platform::ReimbursementSerializer do- include_context 'API v2 serializers params'-subject { described_class.new(resource, params: serializer_params).serializable_hash }+ include_context 'API v2 serializers params'+let(:reimbursement_credit) { create(:reimbursement_credit, creditable: create(:store_credit)) }let(:payment) { create(:payment, state: 'completed') }let(:type) { :reimbursement }- let(:refund) { create(:refund, amount: payment.credit_allowed - 1) }- let(:resource) { create(type, refunds: [refund], credits: [reimbursement_credit]) }+ let(:refund) { create(:refund, amount: payment.credit_allowed - 1) }+ let(:user) { create(:admin_user) }+ let(:resource) { create(type, refunds: [refund], credits: [reimbursement_credit], performed_by: user) }it doexpect(subject).to eq(@@ -53,6 +54,12 @@ describe Spree::Api::V2::Platform::ReimbursementSerializer doid: resource.return_items.first.id.to_s,type: :return_item}]+ },+ performed_by: {+ data: {+ id: user.id.to_s,+ type: :admin_user+ }}},type: typediff --git a/core/app/models/spree/reimbursement.rb b/core/app/models/spree/reimbursement.rbindex 1fd3abff91..e1d8d98d06 100644--- a/core/app/models/spree/reimbursement.rb+++ b/core/app/models/spree/reimbursement.rb@@ -20,6 +20,8 @@ module Spreehas_many :return_itemsend+ belongs_to :performed_by, class_name: Spree.admin_user_class.to_s, optional: true+validates :order, presence: truevalidate :validate_return_items_belong_to_same_order@@ -104,10 +106,10 @@ module Spreetotal - paid_amountend- def perform!+ def perform!(performer = nil)reimbursement_tax_calculator.call(self)reload- update!(total: calculated_total)+ update!(total: calculated_total, performed_by: performer)reimbursement_performer.perform(self)diff --git a/core/app/models/spree/return_authorization.rb b/core/app/models/spree/return_authorization.rbindex 831b3066f8..1628df7c03 100644--- a/core/app/models/spree/return_authorization.rb+++ b/core/app/models/spree/return_authorization.rb@@ -14,6 +14,9 @@ module Spreehas_many :customer_returnsend+ has_many :reimbursements, through: :customer_returns+ has_many :refunds, through: :reimbursements+belongs_to :stock_locationbelongs_to :reason, class_name: 'Spree::ReturnAuthorizationReason', foreign_key: :return_authorization_reason_iddiff --git a/core/app/models/spree/return_item.rb b/core/app/models/spree/return_item.rbindex 28a16cd3e2..11212cc064 100644--- a/core/app/models/spree/return_item.rb+++ b/core/app/models/spree/return_item.rb@@ -35,6 +35,7 @@ module Spreebelongs_to :exchange_variant, class_name: 'Spree::Variant'belongs_to :preferred_reimbursement_type, class_name: 'Spree::ReimbursementType'belongs_to :override_reimbursement_type, class_name: 'Spree::ReimbursementType'+ has_one :line_item, through: :inventory_unitvalidate :eligible_exchange_variantvalidate :belongs_to_same_customer_orderdiff --git a/core/config/locales/en.yml b/core/config/locales/en.ymlindex cd00fe9016..f9e07a17d2 100644--- a/core/config/locales/en.yml+++ b/core/config/locales/en.yml@@ -1627,6 +1627,7 @@ en:reference: Referencereference_contains: Reference Containsrefund: Refund+ refund_amount: Refund Amountrefund_amount_must_be_greater_than_zero: Refund amount must be greater than zerorefund_reasons: Refund Reasonsrefunded_amount: Refunded Amount@@ -1656,6 +1657,7 @@ en:reimbursement_types: Reimbursement Typesreimbursements: Reimbursementsreject: Reject+ reject_reason: Reject Reasonrejected: Rejectedremember_me: Remember meremove: Removediff --git a/core/db/migrate/20250304115943_add_performed_by_to_spree_reimbursements.rb b/core/db/migrate/20250304115943_add_performed_by_to_spree_reimbursements.rbnew file mode 100644index 0000000000..9d1dd50e28--- /dev/null+++ b/core/db/migrate/20250304115943_add_performed_by_to_spree_reimbursements.rb@@ -0,0 +1,5 @@+class AddPerformedByToSpreeReimbursements < ActiveRecord::Migration[6.1]+ def change+ add_column :spree_reimbursements, :performed_by_id, :bigint, index: true, null: true, if_not_exists: true+ end+enddiff --git a/core/spec/models/spree/reimbursement_spec.rb b/core/spec/models/spree/reimbursement_spec.rbindex 462e2f896f..77f3e56cd2 100644--- a/core/spec/models/spree/reimbursement_spec.rb+++ b/core/spec/models/spree/reimbursement_spec.rb@@ -89,6 +89,27 @@ describe Spree::Reimbursement, type: :model doendend+ context 'when performer is provided' do+ let(:performer) { create(:admin_user) }++ it 'sets the performer' do+ reimbursement.perform!(performer)+ expect(reimbursement.performed_by).to eq performer+ end++ it 'refunds the total amount' do+ subject+ expect(reimbursement.unpaid_amount).to eq 0+ end++ it 'creates a refund' do+ expect do+ subject+ end.to change { Spree::Refund.count }.by(1)+ expect(Spree::Refund.last.amount).to eq order.total+ end+ end+context 'with included tax' dolet!(:tax_rate) { create(:tax_rate, name: 'VAT Tax', amount: 0.1, included_in_price: true, zone: tax_zone) }diff --git a/sample/db/samples/reimbursement_types.rb b/sample/db/samples/reimbursement_types.rbnew file mode 100644index 0000000000..e91e2580a9--- /dev/null+++ b/sample/db/samples/reimbursement_types.rb@@ -0,0 +1,9 @@+reasons = [+ ['Exchange', 'Spree::ReimbursementType::Exchange'],+ ['Original payment', 'Spree::ReimbursementType::OriginalPayment'],+ ['Store credit', 'Spree::ReimbursementType::StoreCredit'],+].map do |name, kind|+ { name: name, type: kind }+end++Spree::ReimbursementType.insert_all(reasons, unique_by: :name)