From 0fb9cc0f2a0631746d49621acfb2efd1dfd51076 Mon Sep 17 00:00:00 2001 From: Arthur Vieira Date: Thu, 19 May 2022 16:03:23 -0300 Subject: [PATCH 1/3] Remove associated adjustments radio button Removes the 'Associated Adjustment Closed' options from the order edit page (/admin/orders/XXXXX/edit). --- app/views/spree/admin/orders/_shipment.html.haml | 12 ------------ spec/views/spree/admin/orders/edit.html.haml_spec.rb | 12 ++++++++++++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/views/spree/admin/orders/_shipment.html.haml b/app/views/spree/admin/orders/_shipment.html.haml index 72ef176c85..e3455ab872 100644 --- a/app/views/spree/admin/orders/_shipment.html.haml +++ b/app/views/spree/admin/orders/_shipment.html.haml @@ -40,18 +40,6 @@ = label_tag 'selected_shipping_rate_id', Spree.t(:shipping_method) = select_tag :selected_shipping_rate_id, options_for_select(shipment.shipping_rates.backend.map { |sr| ["#{sr.name} #{sr.display_price}", sr.id] }, shipment.selected_shipping_rate_id), { :class => 'select2 fullwidth', :data => { 'shipment-number' => shipment.number } } - - if shipment.fee_adjustment&.closed? - %div.field.omega.four.columns - %label - = Spree.t(:associated_adjustment_closed) - %ul - %li - = radio_button_tag :open_adjustment, 'yes', false, :data => { 'shipment-number' => shipment.number } - = "Yes" - %li - = radio_button_tag :open_adjustment, 'no', true, :data => {'shipment-number' => shipment.number } - = "No" - %td.actions - if can? :update, shipment = link_to '', '', :class => 'save-method icon_link icon-ok no-text with-tip', :data => { 'shipment-number' => shipment.number, :action => 'save' }, title: I18n.t('actions.save') diff --git a/spec/views/spree/admin/orders/edit.html.haml_spec.rb b/spec/views/spree/admin/orders/edit.html.haml_spec.rb index 96c4f404af..267ab455eb 100644 --- a/spec/views/spree/admin/orders/edit.html.haml_spec.rb +++ b/spec/views/spree/admin/orders/edit.html.haml_spec.rb @@ -59,6 +59,12 @@ describe "spree/admin/orders/edit.html.haml" do text: out_of_stock_line_item.variant.display_name end end + + it "doesn't display closed associated adjustments" do + render + + expect(rendered).to_not have_content "Associated adjustment closed" + end end context "when order is incomplete" do @@ -93,5 +99,11 @@ describe "spree/admin/orders/edit.html.haml" do expect(rendered).to_not have_content "Out of Stock" end end + + it "doesn't display closed associated adjustments" do + render + + expect(rendered).to_not have_content "Associated adjustment closed" + end end end From 95010fcd125add9f4904fc46205556c9eee319db Mon Sep 17 00:00:00 2001 From: Arthur Vieira Date: Thu, 26 May 2022 09:13:26 -0300 Subject: [PATCH 2/3] Remove the unlock condition in shipment controller This assumes unlock is always true so the shipment's fee adjustments always opens and closes. --- .../javascripts/admin/spree/orders/shipments.js.erb | 3 +-- app/controllers/api/v0/shipments_controller.rb | 9 ++------- spec/views/spree/admin/orders/edit.html.haml_spec.rb | 4 ++-- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/admin/spree/orders/shipments.js.erb b/app/assets/javascripts/admin/spree/orders/shipments.js.erb index cf3d4d6803..75fcdcb93a 100644 --- a/app/assets/javascripts/admin/spree/orders/shipments.js.erb +++ b/app/assets/javascripts/admin/spree/orders/shipments.js.erb @@ -25,13 +25,12 @@ $(document).ready(function() { var link = $(this); var shipment_number = link.data('shipment-number'); var selected_shipping_rate_id = link.parents('tbody').find("select#selected_shipping_rate_id[data-shipment-number='" + shipment_number + "']").val(); - var unlock = link.parents('tbody').find("input[name='open_adjustment'][data-shipment-number='" + shipment_number + "']:checked").val(); var url = Spree.url( Spree.routes.orders_api + "/" + order_number + "/shipments/" + shipment_number + ".json"); $.ajax({ type: "PUT", url: url, - data: { shipment: { selected_shipping_rate_id: selected_shipping_rate_id, unlock: unlock } } + data: { shipment: { selected_shipping_rate_id: selected_shipping_rate_id } } }).done(function( msg ) { window.location.reload(); }).error(function( msg ) { diff --git a/app/controllers/api/v0/shipments_controller.rb b/app/controllers/api/v0/shipments_controller.rb index af59069627..0905abe954 100644 --- a/app/controllers/api/v0/shipments_controller.rb +++ b/app/controllers/api/v0/shipments_controller.rb @@ -28,19 +28,14 @@ module Api authorize! :read, Spree::Shipment @shipment = @order.shipments.find_by!(number: params[:id]) params[:shipment] ||= [] - unlock = params[:shipment].delete(:unlock) - if unlock == 'yes' - @shipment.fee_adjustment.fire_events(:open) - end + @shipment.fee_adjustment.fire_events(:open) if @shipment.update(shipment_params) @order.updater.update_totals_and_states end - if unlock == 'yes' - @shipment.fee_adjustment.close - end + @shipment.fee_adjustment.close render json: @shipment.reload, serializer: Api::ShipmentSerializer, status: :ok end diff --git a/spec/views/spree/admin/orders/edit.html.haml_spec.rb b/spec/views/spree/admin/orders/edit.html.haml_spec.rb index 267ab455eb..c1417cf7b2 100644 --- a/spec/views/spree/admin/orders/edit.html.haml_spec.rb +++ b/spec/views/spree/admin/orders/edit.html.haml_spec.rb @@ -62,7 +62,7 @@ describe "spree/admin/orders/edit.html.haml" do it "doesn't display closed associated adjustments" do render - + expect(rendered).to_not have_content "Associated adjustment closed" end end @@ -102,7 +102,7 @@ describe "spree/admin/orders/edit.html.haml" do it "doesn't display closed associated adjustments" do render - + expect(rendered).to_not have_content "Associated adjustment closed" end end From e0241b686681c2ed31bba4b08e2fd52b7cd24d3f Mon Sep 17 00:00:00 2001 From: Arthur Vieira Date: Thu, 26 May 2022 09:47:12 -0300 Subject: [PATCH 3/3] Remove test associated without 'unlock' selected Leaves the other test that should be the default behaviour and renames it accordingly. --- .../api/v0/shipments_controller_spec.rb | 27 ++++--------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/spec/controllers/api/v0/shipments_controller_spec.rb b/spec/controllers/api/v0/shipments_controller_spec.rb index 233a13560e..abdb5ea2bc 100644 --- a/spec/controllers/api/v0/shipments_controller_spec.rb +++ b/spec/controllers/api/v0/shipments_controller_spec.rb @@ -273,28 +273,11 @@ describe Api::V0::ShipmentsController, type: :controller do expect(order.payment_state).to eq "balance_due" # total changed, payment is due end - context "using the 'unlock' parameter with closed adjustments" do - before do - order.shipment_adjustments.each(&:close) - end - - it "does not update closed adjustments without unlock option" do - params[:shipment][:unlock] = "no" - - expect { - api_put :update, params - expect(response.status).to eq 200 - }.to_not change { order.reload.shipment.fee_adjustment.amount } - end - - it "updates closed adjustments with unlock option selected" do - params[:shipment][:unlock] = "yes" - - expect { - api_put :update, params - expect(response.status).to eq 200 - }.to change { order.reload.shipment.fee_adjustment.amount } - end + it "updates closed adjustments" do + expect { + api_put :update, params + expect(response.status).to eq 200 + }.to change { order.reload.shipment.fee_adjustment.amount } end end end