diff --git a/api/app/controllers/spree/api/stock_transfers_controller.rb b/api/app/controllers/spree/api/stock_transfers_controller.rb deleted file mode 100644 index f57d5017f16..00000000000 --- a/api/app/controllers/spree/api/stock_transfers_controller.rb +++ /dev/null @@ -1,20 +0,0 @@ -module Spree - module Api - class StockTransfersController < Spree::Api::BaseController - def receive - authorize! :update, TransferItem - @stock_transfer = Spree::StockTransfer.accessible_by(current_ability, :update).find_by!(number: params[:id]) - variant = Spree::Variant.accessible_by(current_ability, :show).find(params[:variant_id]) - @transfer_item = @stock_transfer.transfer_items.find_by(variant: variant) - if @transfer_item.nil? - logger.error("variant_not_in_stock_transfer") - render "spree/api/errors/variant_not_in_stock_transfer", status: 422 - elsif @transfer_item.update_attributes(received_quantity: @transfer_item.received_quantity + 1) - render 'spree/api/stock_transfers/receive', status: 200 - else - invalid_resource!(@transfer_item) - end - end - end - end -end diff --git a/api/app/controllers/spree/api/transfer_items_controller.rb b/api/app/controllers/spree/api/transfer_items_controller.rb deleted file mode 100644 index 15ae47a2f1b..00000000000 --- a/api/app/controllers/spree/api/transfer_items_controller.rb +++ /dev/null @@ -1,42 +0,0 @@ -module Spree - module Api - class TransferItemsController < Spree::Api::BaseController - def create - authorize! :create, TransferItem - stock_transfer = Spree::StockTransfer.accessible_by(current_ability, :update).find_by(number: params[:stock_transfer_id]) - @transfer_item = stock_transfer.transfer_items.build(transfer_item_params) - if @transfer_item.save - respond_with(@transfer_item, status: 201, default_template: :show) - else - invalid_resource!(@transfer_item) - end - end - - def update - authorize! :update, TransferItem - @transfer_item = Spree::TransferItem.accessible_by(current_ability, :update).find(params[:id]) - if @transfer_item.update_attributes(transfer_item_params) - respond_with(@transfer_item, status: 200, default_template: :show) - else - invalid_resource!(@transfer_item) - end - end - - def destroy - authorize! :destroy, TransferItem - @transfer_item = Spree::TransferItem.accessible_by(current_ability, :destroy).find(params[:id]) - if @transfer_item.paranoia_destroy - respond_with(@transfer_item, status: 200, default_template: :show) - else - invalid_resource!(@transfer_item) - end - end - - private - - def transfer_item_params - params.require(:transfer_item).permit(permitted_transfer_item_attributes) - end - end - end -end diff --git a/api/app/helpers/spree/api/api_helpers.rb b/api/app/helpers/spree/api/api_helpers.rb index 67c0ba84c5f..709c6215e61 100644 --- a/api/app/helpers/spree/api/api_helpers.rb +++ b/api/app/helpers/spree/api/api_helpers.rb @@ -31,9 +31,6 @@ module ApiHelpers :promotion_attributes, :store_attributes, :store_credit_history_attributes, - :stock_transfer_attributes, - :transfer_item_attributes, - :transfer_item_variant_attributes, :variant_property_attributes ] @@ -177,12 +174,6 @@ def required_fields_for(model) :display_event_date ] - @@stock_transfer_attributes = [:id, :number] - - @@transfer_item_attributes = [:id, :expected_quantity, :received_quantity] - - @@transfer_item_variant_attributes = [] - def variant_attributes if @current_user_roles && @current_user_roles.include?("admin") @@variant_attributes + [:cost_price] diff --git a/api/app/views/spree/api/errors/variant_not_in_stock_transfer.json.jbuilder b/api/app/views/spree/api/errors/variant_not_in_stock_transfer.json.jbuilder deleted file mode 100644 index 9b894feeda8..00000000000 --- a/api/app/views/spree/api/errors/variant_not_in_stock_transfer.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.error(I18n.t('spree.item_not_in_stock_transfer')) diff --git a/api/app/views/spree/api/stock_transfers/receive.json.jbuilder b/api/app/views/spree/api/stock_transfers/receive.json.jbuilder deleted file mode 100644 index 94f7c66b879..00000000000 --- a/api/app/views/spree/api/stock_transfers/receive.json.jbuilder +++ /dev/null @@ -1,4 +0,0 @@ -json.(@stock_transfer, *stock_transfer_attributes) -json.received_item do - json.partial!("spree/api/transfer_items/transfer_item", transfer_item: @transfer_item) -end diff --git a/api/app/views/spree/api/transfer_items/_transfer_item.json.jbuilder b/api/app/views/spree/api/transfer_items/_transfer_item.json.jbuilder deleted file mode 100644 index a5d7db5f4dc..00000000000 --- a/api/app/views/spree/api/transfer_items/_transfer_item.json.jbuilder +++ /dev/null @@ -1,5 +0,0 @@ -json.(transfer_item, *transfer_item_attributes) -json.variant do - json.partial!("spree/api/variants/small", variant: transfer_item.variant) - json.(transfer_item.variant, *transfer_item_variant_attributes) -end diff --git a/api/app/views/spree/api/transfer_items/show.json.jbuilder b/api/app/views/spree/api/transfer_items/show.json.jbuilder deleted file mode 100644 index d7f1545e36f..00000000000 --- a/api/app/views/spree/api/transfer_items/show.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.partial!("spree/api/transfer_items/transfer_item", transfer_item: @transfer_item) diff --git a/api/config/routes.rb b/api/config/routes.rb index 07600893037..3afb92da049 100644 --- a/api/config/routes.rb +++ b/api/config/routes.rb @@ -120,13 +120,6 @@ resources :stock_items, only: [:index, :update, :destroy] - resources :stock_transfers, only: [] do - member do - post :receive - end - resources :transfer_items, only: [:create, :update, :destroy] - end - resources :stores resources :store_credit_events, only: [] do diff --git a/api/spec/requests/spree/api/stock_transfers_controller_spec.rb b/api/spec/requests/spree/api/stock_transfers_controller_spec.rb deleted file mode 100644 index bd8a55f7838..00000000000 --- a/api/spec/requests/spree/api/stock_transfers_controller_spec.rb +++ /dev/null @@ -1,97 +0,0 @@ -require 'spec_helper' - -module Spree - describe Api::StockTransfersController do - - let!(:stock_transfer) { create(:stock_transfer_with_items) } - let(:transfer_item) { stock_transfer.transfer_items.first } - - before do - stub_authentication! - end - - context "as a normal user" do - describe "#receive" do - it "cannot receive transfer items from a stock transfer" do - post spree.receive_api_stock_transfer_path(stock_transfer), params: { variant_id: transfer_item.variant } - expect(response.status).to eq 401 - end - end - end - - context "as an admin" do - sign_in_as_admin! - - describe "#receive" do - subject do - post spree.receive_api_stock_transfer_path(stock_transfer), params: { variant_id: variant_id } - end - - context "valid parameters" do - let(:variant_id) { transfer_item.variant.to_param } - - it "can receive a transfer items from a stock transfer" do - subject - expect(response.status).to eq 200 - end - - it "increments the received quantity for the transfer_item" do - expect { subject }.to change { transfer_item.reload.received_quantity }.by(1) - end - - it "returns the received transfer item in the response" do - subject - expect(JSON.parse(response.body)["received_item"]["id"]).to eq transfer_item.id - end - end - - context "transfer item does not have stock in source location after ship" do - let(:variant_id) { transfer_item.variant.to_param } - let(:user) { create :user } - - before do - stock_transfer.finalize(user) - stock_transfer.ship(shipped_at: Time.current) - stock_transfer.source_location.stock_item(transfer_item.variant_id).set_count_on_hand(0) - end - - it "can still receive item" do - expect { subject }.to change { transfer_item.reload.received_quantity }.by(1) - end - end - - context "transfer item has been fully received" do - let(:variant_id) { transfer_item.variant.to_param } - - before do - transfer_item.update_attributes!(expected_quantity: 1, received_quantity: 1) - end - - it "returns a 422" do - subject - expect(response.status).to eq 422 - end - - it "returns a specific error message" do - subject - expect(JSON.parse(response.body)["errors"]["received_quantity"]).to eq ["must be less than or equal to 1"] - end - end - - context "variant is not in the transfer order" do - let(:variant_id) { create(:variant).to_param } - - it "returns a 422" do - subject - expect(response.status).to eq 422 - end - - it "returns a specific error message" do - subject - expect(JSON.parse(response.body)["error"]).to eq I18n.t('spree.item_not_in_stock_transfer') - end - end - end - end - end -end diff --git a/api/spec/requests/spree/api/transfer_items_controller_spec.rb b/api/spec/requests/spree/api/transfer_items_controller_spec.rb deleted file mode 100644 index d1f3b3d5675..00000000000 --- a/api/spec/requests/spree/api/transfer_items_controller_spec.rb +++ /dev/null @@ -1,150 +0,0 @@ -require 'spec_helper' - -module Spree - describe Api::TransferItemsController do - - let!(:stock_transfer) { create(:stock_transfer_with_items) } - let(:transfer_item) { stock_transfer.transfer_items.first } - - before do - stub_authentication! - end - - context "as a normal user" do - describe "#create" do - it "cannot create a transfer item" do - post spree.api_stock_transfer_transfer_items_path(stock_transfer) - expect(response.status).to eq 401 - end - end - - describe "#update" do - it "cannot update a transfer item" do - put spree.api_stock_transfer_transfer_item_path(stock_transfer, transfer_item) - expect(response.status).to eq 401 - end - end - - describe "#destroy" do - it "cannot delete a transfer item" do - delete spree.api_stock_transfer_transfer_item_path(stock_transfer, transfer_item) - expect(response.status).to eq 401 - end - end - end - - context "as an admin" do - sign_in_as_admin! - - describe "#create" do - subject do - create_params = { - transfer_item: { - variant_id: variant_id, - expected_quantity: 1 - } - } - post spree.api_stock_transfer_transfer_items_path(stock_transfer), params: create_params - end - - context "valid parameters" do - let(:variant) { create(:variant) } - let(:variant_id) { variant.id } - - context "variant is available" do - before do - variant.stock_items.update_all(count_on_hand: 1) - end - - it "can create a transfer item" do - subject - expect(response.status).to eq 201 - end - - it "creates a transfer item" do - expect { subject }.to change { Spree::TransferItem.count }.by(1) - end - end - - context "variant is not available" do - before do - variant.stock_items.update_all(count_on_hand: 0) - end - - it "returns an error status" do - subject - expect(response.status).to eq 422 - end - - it "does not create a transfer item" do - expect { subject }.to_not change { Spree::TransferItem.count } - end - end - end - end - - describe "#update" do - subject do - update_params = { transfer_item: { received_quantity: received_quantity } } - put spree.api_stock_transfer_transfer_item_path(stock_transfer, transfer_item), params: update_params - end - - context "valid parameters" do - let(:received_quantity) { 2 } - - it "can update a transfer item" do - subject - expect(response.status).to eq 200 - end - - it "updates the transfer item" do - expect { subject }.to change { transfer_item.reload.received_quantity }.to(2) - end - end - - context "invalid parameters" do - let(:received_quantity) { -5 } - - it "returns a 422" do - subject - expect(response.status).to eq 422 - end - - it "does not update the transfer item" do - expect { subject }.to_not change { transfer_item.reload.received_quantity } - end - end - end - - describe "#destroy" do - subject { delete spree.api_stock_transfer_transfer_item_path(stock_transfer, transfer_item) } - - context "hasn't been finalized" do - it "can delete a transfer item" do - subject - expect(response.status).to eq 200 - end - - it "deletes the transfer item" do - expect { subject }.to change { Spree::TransferItem.count }.by(-1) - end - end - - context "has been finalized" do - before do - stock_transfer.update_attributes(finalized_at: Time.current) - end - - it "returns an error status code" do - subject - expect(response.status).to eq 422 - end - - it "does not delete the transfer item" do - expect { subject }.to_not change { Spree::TransferItem.count } - end - end - end - end - end -end