Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions api/app/controllers/spree/api/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,7 @@ def cancel

def create
authorize! :create, Order

order_user = if order_params[:user_id]
Spree.user_class.find(order_params[:user_id])
else
current_api_user
end

@order = Spree::Core::Importer::Order.import(order_user, order_params)
@order = Spree::Core::Importer::Order.import(determine_order_user, order_params)
respond_with(@order, default_template: :show, status: 201)
end

Expand Down Expand Up @@ -116,6 +109,15 @@ def normalize_params
params[:order][:bill_address_attributes] = params[:order].delete(:bill_address) if params[:order][:bill_address].present?
end

# @api public
def determine_order_user
if order_params[:user_id].present?
Spree.user_class.find(order_params[:user_id])
else
current_api_user
end
end

def permitted_order_attributes
can?(:admin, Spree::Order) ? (super + admin_order_attributes) : super
end
Expand Down
38 changes: 7 additions & 31 deletions api/spec/controllers/spree/api/line_items_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ module Spree
api_put :update, :id => line_item.id, :line_item => { :quantity => 101 }
expect(response.status).to eq(200)
order.reload
expect(order.total).to eq(1010) # 10 original due to factory, + 1000 in this test
expect(order.total).to eq(1110) # 101 quantity * 10 item price + 100 shipping cost
expect(json_response).to have_attributes(attributes)
expect(json_response["quantity"]).to eq(101)
end
Expand All @@ -117,41 +117,17 @@ module Spree
expect { line_item.reload }.to raise_error(ActiveRecord::RecordNotFound)
end

context "order contents changed after shipments were created" do
let!(:order) { Order.create }
let!(:line_item) { order.contents.add(product.master) }
context "order contents changed after shipments were created and order is completed" do

before { order.create_proposed_shipments }

it "clear out shipments on create" do
expect(order.reload.shipments).not_to be_empty
api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
expect(order.reload.shipments).to be_empty
before do
allow(order).to receive_messages completed?: true
allow(Order).to receive_message_chain :includes, find_by!: order
end

it "clear out shipments on update" do
it "doesn't destroy shipments or restart checkout flow" do
expect(order.reload.shipments).not_to be_empty
api_put :update, :id => line_item.id, :line_item => { :quantity => 1000 }
expect(order.reload.shipments).to be_empty
end

it "clear out shipments on delete" do
api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
expect(order.reload.shipments).not_to be_empty
api_delete :destroy, :id => line_item.id
expect(order.reload.shipments).to be_empty
end

context "order is completed" do
before do
allow(order).to receive_messages completed?: true
allow(Order).to receive_message_chain :includes, find_by!: order
end

it "doesn't destroy shipments or restart checkout flow" do
expect(order.reload.shipments).not_to be_empty
api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
expect(order.reload.shipments).not_to be_empty
end
end
end
end
Expand Down
14 changes: 0 additions & 14 deletions api/spec/controllers/spree/api/orders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -499,20 +499,6 @@ module Spree
expect(json_response["user_id"]).to eq(original_id)
end

context "order has shipments" do
before { order.create_proposed_shipments }

it "clears out all existing shipments on line item udpate" do
previous_shipments = order.shipments
api_put :update, :id => order.to_param, :order => {
:line_items => {
0 => { :id => line_item.id, :quantity => 10 }
}
}
expect(order.reload.shipments).to be_empty
end
end

context "with a line item" do
let(:order) { create(:order_with_line_items) }

Expand Down
18 changes: 5 additions & 13 deletions backend/app/controllers/spree/admin/stock_transfers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class StockTransfersController < ResourceController
{ translation_key: :name, attr_name: :name }
]

before_filter :load_transferable_stock_locations, only: :index
before_filter :load_viewable_stock_locations, only: :index
before_filter :load_variant_display_attributes, only: [:receive, :edit, :show, :tracking_info]
before_filter :load_source_stock_locations, only: :new
before_filter :load_destination_stock_locations, only: :edit
Expand Down Expand Up @@ -100,16 +100,16 @@ def authorize_transfer_attributes!
authorize! :create, duplicate
end

def load_transferable_stock_locations
@stock_locations = accessible_source_stock_locations | accessible_destination_stock_locations
def load_viewable_stock_locations
@stock_locations = Spree::StockLocation.accessible_by(current_ability, :read)
end

def load_source_stock_locations
@source_stock_locations = accessible_source_stock_locations
@source_stock_locations ||= Spree::StockLocation.accessible_by(current_ability, :transfer_from)
end

def load_destination_stock_locations
@destination_stock_locations = accessible_destination_stock_locations.where.not(id: @stock_transfer.source_location_id)
@destination_stock_locations ||= Spree::StockLocation.accessible_by(current_ability, :transfer_to).where.not(id: @stock_transfer.source_location_id)
end

def load_variant_display_attributes
Expand Down Expand Up @@ -142,14 +142,6 @@ def adjust_inventory
@stock_transfer.destination_location.move(transfer_item.variant, transfer_item.received_quantity, @stock_transfer)
end
end

def accessible_source_stock_locations
@source_locations ||= Spree::StockLocation.accessible_by(current_ability, :transfer_from)
end

def accessible_destination_stock_locations
@destination_locations ||= Spree::StockLocation.accessible_by(current_ability, :transfer_to)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<table class="index">
<table class="index customer-return-reimbursements">
<thead data-hook="customer_return_header">
<tr>
<th><%= Spree.t(:number) %></th>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<% return_item = item_fields.object %>

<tr>
<td class="align-center" class="inventory-unit-checkbox">
<td class="align-center inventory-unit-checkbox">
<div style="display:none">
<%= item_fields.hidden_field :inventory_unit_id %>
<%= item_fields.hidden_field :return_authorization_id %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<% end %>

<% if @pending_return_items.any? %>
<fieldset data-hook="accepted_return_items" class="no-border-bottom">
<fieldset data-hook="pending_return_items" class="no-border-bottom">
<legend align="center"><%= Spree.t(:pending) %></legend>
<%= render partial: 'return_item_decision', locals: {return_items: @pending_return_items, show_decision: true} %>
</fieldset>
Expand Down
4 changes: 2 additions & 2 deletions backend/app/views/spree/admin/reimbursements/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<%= form_for [:admin, @order, @reimbursement] do |f| %>
<fieldset class='no-border-bottom'>
<legend align='center'><%= Spree.t(:items_to_be_reimbursed) %></legend>
<table class="index reimbursement-return-items-table">
<table class="index reimbursement-return-items">
<thead>
<tr>
<th><%= Spree.t(:product) %></th>
Expand Down Expand Up @@ -73,7 +73,7 @@

<fieldset>
<legend align='center'><%= Spree.t(:calculated_reimbursements) %></legend>
<table class="index">
<table class="index calculated-reimbursements">
<thead data-hook="customer_return_header">
<tr>
<th><%= Spree.t(:reimbursement_type) %></th>
Expand Down
18 changes: 9 additions & 9 deletions backend/app/views/spree/admin/reimbursements/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<fieldset class='no-border-bottom'>
<legend align='center'><%= Spree.t(:items_reimbursed) %></legend>
<table class="index reimbursement-reimbursement-items-table">
<table class="index reimbursement-reimbursement-items">
<thead>
<tr>
<th><%= Spree.t(:product) %></th>
Expand Down Expand Up @@ -55,7 +55,7 @@

<fieldset class="no-border-bottom">
<legend align='center'><%= Spree.t(:refunds) %></legend>
<table class="index">
<table class="index reimbursement-refunds">
<thead data-hook="customer_return_header">
<tr>
<th><%= Spree.t(:description) %></th>
Expand All @@ -64,9 +64,9 @@
</thead>
<tbody>
<% @reimbursement.refunds.each do |refund| %>
<tr id="<%= spree_dom_id(refund) %>" data-hook="reimbursement_refund_row" class="<%= cycle('odd', 'even')%>">
<td><%= refund.description %></td>
<td><%= refund.display_amount %></td>
<tr id="<%= spree_dom_id(refund) %>" data-hook="reimbursement_refund_row" class="reimbursement-refund <%= cycle('odd', 'even')%>">
<td class="reimbursement-refund-description"><%= refund.description %></td>
<td class="reimbursement-refund-amount"><%= refund.display_amount %></td>
</tr>
<% end %>
</tbody>
Expand All @@ -75,7 +75,7 @@

<fieldset class="no-border-bottom">
<legend align='center'><%= Spree.t(:credits) %></legend>
<table class="index">
<table class="index reimbursement-credits">
<thead data-hook="customer_return_header">
<tr>
<th><%= Spree.t(:description) %></th>
Expand All @@ -84,9 +84,9 @@
</thead>
<tbody>
<% @reimbursement.credits.each do |credit| %>
<tr id="<%= spree_dom_id(credit) %>" data-hook="reimbursement_refund_row" class="<%= cycle('odd', 'even')%>">
<td><%= credit.description %></td>
<td><%= credit.display_amount %></td>
<tr id="<%= spree_dom_id(credit) %>" data-hook="reimbursement_refund_row" class="reimbursement-credit <%= cycle('odd', 'even')%>">
<td class="reimbursement-credit-description"><%= credit.description %></td>
<td class="reimbursement-credit-amount"><%= credit.display_amount %></td>
</tr>
<% end %>
</tbody>
Expand Down
32 changes: 16 additions & 16 deletions backend/app/views/spree/admin/return_authorizations/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
<table class="index return-items-table">
<thead>
<tr data-hook="rma_header">
<th>
<th class="return-item-checkbox">
<% if allow_return_item_changes %>
<%= check_box_tag 'select-all' %>
<% end %>
</th>
<th><%= Spree.t(:product) %></th>
<th><%= Spree.t(:state) %></th>
<th><%= Spree.t(:charged) %></th>
<th><%= Spree.t(:pre_tax_refund_amount) %></th>
<th><%= Spree.t(:reimbursement_type) %></th>
<th><%= Spree.t(:exchange_for) %></th>
<th><%= Spree.t(:reason) %></th>
<th class="return-item-product"><%= Spree.t(:product) %></th>
<th class="return-item-state"><%= Spree.t(:state) %></th>
<th class="return-item-charged"><%= Spree.t(:charged) %></th>
<th class="return-item-pre-tax-refund-amount"><%= Spree.t(:pre_tax_refund_amount) %></th>
<th class="return-item-reimbursement-type"><%= Spree.t(:reimbursement_type) %></th>
<th class="return-item-exchange-for"><%= Spree.t(:exchange_for) %></th>
<th class="return-item-reason"><%= Spree.t(:reason) %></th>
</tr>
</thead>
<tbody>
Expand All @@ -24,42 +24,42 @@
<% inventory_unit = return_item.inventory_unit %>
<% editable = inventory_unit.shipped? && !inventory_unit.exchange_requested? && allow_return_item_changes && return_item.reimbursement.nil? %>
<tr>
<td class="align-center" class="inventory-unit-checkbox">
<td class="return-item-checkbox align-center inventory-unit-checkbox">
<% if editable %>
<%= item_fields.hidden_field :inventory_unit_id %>
<%= item_fields.check_box :_destroy, {checked: return_item.persisted?, class: 'add-item', "data-price" => return_item.pre_tax_amount}, '0', '1' %>
<% end %>
</td>
<td>
<td class="return-item-product">
<div class="variant-name"><%= inventory_unit.variant.name %></div>
<div class="variant-options"><%= inventory_unit.variant.options_text %></div>
</td>
<td class="align-center"><%= inventory_unit.state.humanize %></td>
<td class="align-center">
<td class="return-item-state align-center"><%= inventory_unit.state.humanize %></td>
<td class="return-item-charged align-center">
<%= return_item.display_pre_tax_amount %>
</td>
<td class="align-center">
<td class="return-item-pre-tax-refund-amount align-center">
<% if editable %>
<%= item_fields.text_field :pre_tax_amount, { class: 'refund-amount-input' } %>
<% else %>
<%= return_item.display_pre_tax_amount %>
<% end %>
</td>
<td>
<td class="return-item-reimbursement-type">
<% if editable %>
<%= item_fields.select :preferred_reimbursement_type_id, @reimbursement_types.collect{|r|[r.name.humanize, r.id]}, {include_blank: true}, {class: 'select2 fullwidth'} %>
<% else %>
<%= return_item.preferred_reimbursement_type.try(:name) %>
<% end %>
</td>
<td class="align-center">
<td class="return-item-exchange-for align-center">
<% if editable %>
<%= item_fields.collection_select :exchange_variant_id, return_item.eligible_exchange_variants(@stock_locations), :id, :options_text, { include_blank: true }, { class: "select2 fullwidth return-item-exchange-selection" } %>
<% elsif return_item.exchange_processed? %>
<%= return_item.exchange_variant.options_text %>
<% end %>
</td>
<td>
<td class="return-item-reason">
<% if editable %>
<%= item_fields.select :return_reason_id, @reasons.collect{|r|[r.name, r.id]}, {include_blank: true}, {class: 'select2 fullwidth'} %>
<% else %>
Expand Down
18 changes: 18 additions & 0 deletions backend/app/views/spree/admin/shipping_methods/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@
</div>
</div>

<div class="alpha omega twelve columns">
<div class="alpha six columns">
<%= f.field_container :carrier do %>
<%= f.label :carrier %><br />
<%= f.text_field :carrier, :class => 'fullwidth', :label => false %>
<%= error_message_on :shipping_method, :carrier %>
<% end %>
</div>

<div class="omega six columns">
<%= f.field_container :service_level do %>
<%= f.label :service_level %><br />
<%= f.text_field :service_level, :class => 'fullwidth', :label => false %>
<%= error_message_on :shipping_method, :service_level %>
<% end %>
</div>
</div>

<div data-hook="admin_shipping_method_form_tracking_url_field" class="alpha twelve columns">
<%= f.field_container :tracking_url do %>
<%= f.label :tracking_url, Spree.t(:tracking_url) %><br />
Expand Down
Loading