Skip to content

armgit / spree

Public Imported from GitHub
0

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

Returns management fixes

Damian Kaczmarczyk63ddb51e8199
diff --git a/admin/app/assets/stylesheets/spree/admin/components/_tables.scss b/admin/app/assets/stylesheets/spree/admin/components/_tables.scss
index 0be31f5b6a..693097985b 100644
--- a/admin/app/assets/stylesheets/spree/admin/components/_tables.scss
+++ b/admin/app/assets/stylesheets/spree/admin/components/_tables.scss
@@ -118,6 +118,10 @@ table.table {
border-color: $table-border-color !important;
}
+.table-responsive:has(.dropdown.show) {
+ overflow: visible;
+}
+
.sortable-drag-v {
border: 1px solid theme-color('info');
border-radius: $border-radius;
diff --git a/admin/app/controllers/spree/admin/orders/return_authorizations_controller.rb b/admin/app/controllers/spree/admin/orders/return_authorizations_controller.rb
index 531c8502f1..5f5752d6f5 100644
--- a/admin/app/controllers/spree/admin/orders/return_authorizations_controller.rb
+++ b/admin/app/controllers/spree/admin/orders/return_authorizations_controller.rb
@@ -14,6 +14,10 @@ module Spree
private
+ def location_after_save
+ spree.edit_admin_order_path(@order)
+ end
+
def load_form_data
load_return_items
load_reimbursement_types
diff --git a/admin/app/controllers/spree/admin/orders_controller.rb b/admin/app/controllers/spree/admin/orders_controller.rb
index 81ad4c4f99..c97a2ec1c0 100644
--- a/admin/app/controllers/spree/admin/orders_controller.rb
+++ b/admin/app/controllers/spree/admin/orders_controller.rb
@@ -71,7 +71,7 @@ module Spree
@refunds = @order.refunds
@return_authorizations = @order.return_authorizations
- @customer_returns = @order.customer_returns
+ @customer_returns = @order.customer_returns.distinct
end
# Used for extensions which need to provide their own custom event links on the order details view.
diff --git a/admin/app/views/spree/admin/customer_returns/_customer_return.html.erb b/admin/app/views/spree/admin/customer_returns/_customer_return.html.erb
new file mode 100644
index 0000000000..ab5aeaa4ed
--- /dev/null
+++ b/admin/app/views/spree/admin/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/customer_returns/index.html.erb b/admin/app/views/spree/admin/customer_returns/index.html.erb
index a66c7c0250..1366c895de 100644
--- a/admin/app/views/spree/admin/customer_returns/index.html.erb
+++ b/admin/app/views/spree/admin/customer_returns/index.html.erb
@@ -32,7 +32,8 @@
</thead>
<tbody>
<%= render collection: @collection,
- partial: "spree/admin/orders/customer_returns/customer_return" %>
+ partial: "spree/admin/customer_returns/customer_return",
+ cached: spree_base_cache_scope %>
</tbody>
</table>
</div>
diff --git a/admin/app/views/spree/admin/orders/_customer_returns.html.erb b/admin/app/views/spree/admin/orders/_customer_returns.html.erb
index 64ae3e4ece..2855e3ac15 100644
--- a/admin/app/views/spree/admin/orders/_customer_returns.html.erb
+++ b/admin/app/views/spree/admin/orders/_customer_returns.html.erb
@@ -12,39 +12,13 @@
<th><%= Spree.t(:date) %></th>
<th><%= Spree.t(:status) %></th>
<th><%= Spree.t(:pre_tax_total) %></th>
+ <th></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 %>
+ <%= render partial: "spree/admin/orders/customer_returns/customer_return",
+ collection: @customer_returns,
+ cached: spree_base_cache_scope %>
</tbody>
</table>
</div>
diff --git a/admin/app/views/spree/admin/orders/_return_authorizations.html.erb b/admin/app/views/spree/admin/orders/_return_authorizations.html.erb
index d46addedeb..ec81d311b8 100644
--- a/admin/app/views/spree/admin/orders/_return_authorizations.html.erb
+++ b/admin/app/views/spree/admin/orders/_return_authorizations.html.erb
@@ -13,37 +13,11 @@
<th><%= Spree.t(:status) %></th>
<th><%= Spree.t(:pre_tax_total) %></th>
<th><%= "#{Spree.t("date")}/#{Spree.t("time")}" %></th>
+ <th></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 %>
+ <%= render partial: 'spree/admin/orders/return_authorizations/return_authorization', collection: @return_authorizations, cached: spree_base_cache_scope %>
</tbody>
</table>
</div>
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.erb
index ab5aeaa4ed..73bd1d2e5d 100644
--- 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.erb
@@ -1,24 +1,22 @@
-<% if customer_return.order.present? %>
+<% edit_link =
+ if can?(:edit, customer_return)
+ spree.edit_admin_order_customer_return_path(@order, customer_return)
+ else
+ "#"
+ end %>
+
+<% can_create_reimbursement =
+ customer_return.can_create_reimbursement? &&
+ can?(:create, Spree::Reimbursement) %>
+
<tr
- id="<%= spree_dom_id customer_return %>"
+ 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 data-action="click->row-link#openLink" class="font-weight-bolder">
+ <%= link_to customer_return.number, edit_link %>
</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>
@@ -27,5 +25,46 @@
<% 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>
+ <td>
+ <% if can_create_reimbursement %>
+ <span class="dropdown">
+ <button
+ class="btn btn-light btn-sm"
+ type="button"
+ data-toggle="dropdown"
+ aria-expanded="false"
+ >
+ <%= icon("dots", class: "mr-0") %>
+ </button>
+ <div class="dropdown-menu">
+ <%= link_to_edit(
+ customer_return,
+ data: {
+ row_link_target: :link,
+ },
+ class: "dropdown-item",
+ url: edit_link,
+ ) %>
+ <%= form_for [:admin, @order, Spree::Reimbursement.new] do |f| %>
+ <%= hidden_field_tag :build_from_customer_return_id, customer_return.id %>
+ <%= f.button class: 'dropdown-item' do %>
+ <%= icon "plus" %>
+ <%= Spree.t(:create_reimbursement) %>
+ <% end %>
+ <% end %>
+ </div>
+ </span>
+ <% else %>
+ <%= link_to_edit(
+ customer_return,
+ no_text: true,
+ data: {
+ row_link_target: :link,
+ },
+ class: "btn btn-light btn-sm",
+ url: edit_link,
+ ) %>
+ <% end %>
+ </td>
</tr>
-<% end %>
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.erb
index 240c1a238d..caead0c1fa 100644
--- a/admin/app/views/spree/admin/orders/customer_returns/edit.html.erb
+++ b/admin/app/views/spree/admin/orders/customer_returns/edit.html.erb
@@ -125,24 +125,21 @@
</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>
+<% if @customer_return.can_create_reimbursement? && can?(:create, Spree::Reimbursement) %>
+ <%= 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 %>
- </fieldset>
+ <% end %>
+<% end %>
+<% if !@customer_return.fully_reimbursed? && @customer_return.no_pending_reimbursements? && !@customer_return.completely_decided? %>
+ <div
+ class="
+ text-muted p-5 d-flex align-items-center w-100 justify-content-center
+ "
+ >
+ <%= Spree.t(:unable_to_create_reimbursements) %>
+ </div>
<% 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.erb
index 6709db6b8d..5809892550 100644
--- a/admin/app/views/spree/admin/orders/customer_returns/new.html.erb
+++ b/admin/app/views/spree/admin/orders/customer_returns/new.html.erb
@@ -47,13 +47,7 @@
</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>
+ <%= render "spree/admin/shared/new_resource_links" %>
<% end %>
<% else %>
@@ -66,7 +60,7 @@
>
<%= Spree.t(:all_items_have_been_returned) %>,
<%= link_to "#{Spree.t(:get_back_to_the)} #{Spree.t(:order)}",
- spree.edit_admin_order_path(@order) %>.
+ spree.edit_admin_order_path(@order) %>
</div>
</div>
diff --git a/admin/app/views/spree/admin/orders/return_authorizations/_return_authorization.html.erb b/admin/app/views/spree/admin/orders/return_authorizations/_return_authorization.html.erb
new file mode 100644
index 0000000000..87416f491b
--- /dev/null
+++ b/admin/app/views/spree/admin/orders/return_authorizations/_return_authorization.html.erb
@@ -0,0 +1,36 @@
+<% edit_link =
+ 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 %>
+
+<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, edit_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>
+ <td data-action="click->row-link#openLink">
+ <%= link_to_edit(
+ return_authorization,
+ no_text: true,
+ data: {
+ row_link_target: :link,
+ },
+ url: edit_link,
+ ) %>
+ </td>
+</tr>
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.erb
index aac034fe91..20d40a2cc6 100644
--- a/admin/app/views/spree/admin/orders/return_authorizations/new.html.erb
+++ b/admin/app/views/spree/admin/orders/return_authorizations/new.html.erb
@@ -8,11 +8,6 @@
<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>
+ <%= render 'spree/admin/shared/new_resource_links' %>
</fieldset>
<% end %>
diff --git a/admin/app/views/spree/admin/refund_reasons/index.html.erb b/admin/app/views/spree/admin/refund_reasons/index.html.erb
index dffb43b009..2284ef6225 100644
--- a/admin/app/views/spree/admin/refund_reasons/index.html.erb
+++ b/admin/app/views/spree/admin/refund_reasons/index.html.erb
@@ -17,20 +17,18 @@
</thead>
<tbody>
<% @collection.each do |refund_reason| %>
- <tr id="<%= spree_dom_id refund_reason %>">
- <td class="w-40 align-center">
+ <tr id="<%= spree_dom_id refund_reason %>" data-controller="row-link" class="cursor-pointer">
+ <td class="w-40 align-center" data-action="click->row-link#openLink">
<%= refund_reason.name %>
</td>
- <td class="w-20 align-center">
+ <td class="w-20 align-center" data-action="click->row-link#openLink">
<%= active_badge(refund_reason.active, label: Spree.t(refund_reason.active? ? :active : :inactive)) %>
</td>
- <td class="w-10 align-center">
+ <td class="w-10 align-center" data-action="click->row-link#openLink">
<%= active_badge(refund_reason.mutable) %>
</td>
- <td class="actions w-10">
- <% if refund_reason.mutable? %>
- <%= link_to_edit(refund_reason, no_text: true, data: { row_link_target: :link }) if can? :edit, refund_reason %>
- <% end %>
+ <td class="actions w-10" data-action="click->row-link#openLink">
+ <%= link_to_edit(refund_reason, no_text: true, data: { row_link_target: :link }) if can? :edit, refund_reason %>
</td>
</tr>
<% end %>
diff --git a/admin/app/views/spree/admin/reimbursement_types/_form.html.erb b/admin/app/views/spree/admin/reimbursement_types/_form.html.erb
index dc3191a33e..4cd23e7d4c 100644
--- a/admin/app/views/spree/admin/reimbursement_types/_form.html.erb
+++ b/admin/app/views/spree/admin/reimbursement_types/_form.html.erb
@@ -2,29 +2,29 @@
<div class="card-body">
<div class="form-group">
<%= f.label :name, Spree.t(:name) %>
- <%= f.text_field :name, class:'form-control' %>
+ <%= f.text_field :name, class: "form-control" %>
<%= f.error_message_on :name %>
</div>
<%- if @reimbursement_type.new_record? %>
<div class="form-group">
<%= f.label :type, Spree.t(:type) %>
- <%= f.select :type, options_for_select(Spree::ReimbursementType::KINDS.map { |kind| [kind.demodulize.titleize, kind] }), { include_blank: false}, { class: 'custom-select' } %>
+ <%= f.select :type,
+ options_for_select(
+ Spree::ReimbursementType::KINDS.map do |kind|
+ [kind.demodulize.titleize, kind]
+ end,
+ ),
+ { include_blank: false },
+ { class: "custom-select" } %>
<%= f.error_message_on :type %>
- </div>
+ </div>
<% end %>
<div class="form-group">
<div class="custom-control custom-checkbox">
- <%= f.check_box :active, class: 'custom-control-input' %>
- <%= f.label :active, Spree.t(:active), class: 'custom-control-label' %>
+ <%= f.check_box :active, class: "custom-control-input" %>
+ <%= f.label :active, Spree.t(:active), class: "custom-control-label" %>
</div>
<%= f.error_message_on :active %>
</div>
- <div class="form-group">
- <div class="custom-control custom-checkbox">
- <%= f.check_box :mutable, class: 'custom-control-input' %>
- <%= f.label :mutable, Spree.t(:mutable), class: 'custom-control-label' %>
- </div>
- <%= f.error_message_on :mutable %>
- </div>
</div>
</div>
diff --git a/admin/app/views/spree/admin/reimbursement_types/edit.html.erb b/admin/app/views/spree/admin/reimbursement_types/edit.html.erb
index 5357d5f7c8..d6c66783f1 100644
--- a/admin/app/views/spree/admin/reimbursement_types/edit.html.erb
+++ b/admin/app/views/spree/admin/reimbursement_types/edit.html.erb
@@ -7,7 +7,7 @@
<div class="row">
<div class="col-lg-6">
- <%= form_for @reimbursement_type, :url => object_url, :method => :put do |reimbursement_form| %>
+ <%= form_with model: @reimbursement_type, :url => object_url, :method => :put, scope: :reimbursement_type do |reimbursement_form| %>
<%= render partial: 'form', locals: { f: reimbursement_form } %>
<%= render 'spree/admin/shared/edit_resource_links', f: reimbursement_form %>
<% end %>
diff --git a/core/app/models/spree/ability.rb b/core/app/models/spree/ability.rb
index 1aaa2d66a0..3aa75707eb 100644
--- a/core/app/models/spree/ability.rb
+++ b/core/app/models/spree/ability.rb
@@ -58,6 +58,8 @@ module Spree
def apply_admin_permissions(user)
can :manage, :all
+ cannot [:edit, :update], Spree::RefundReason, mutable: false
+ cannot [:edit, :update], Spree::ReimbursementType, mutable: false
end
def apply_user_permissions(user)
diff --git a/core/app/models/spree/customer_return.rb b/core/app/models/spree/customer_return.rb
index 39af2def89..e6bfc128fe 100644
--- a/core/app/models/spree/customer_return.rb
+++ b/core/app/models/spree/customer_return.rb
@@ -54,6 +54,18 @@ module Spree
return_items.sum(:pre_tax_amount)
end
+ def can_create_reimbursement?
+ !fully_reimbursed? && completely_decided? && no_pending_reimbursements?
+ end
+
+ def no_pending_reimbursements?
+ if association(:reimbursements).loaded?
+ reimbursements.select(&:pending?).empty?
+ else
+ reimbursements.where(reimbursement_status: :pending).none?
+ end
+ end
+
private
def inventory_units