Skip to content

Commit

Permalink
Merge pull request #3194 from HugsDaniel/3109-fix-orders-new
Browse files Browse the repository at this point in the history
[Spree Upgrade] Fix admin new order page
  • Loading branch information
sauloperez authored Feb 12, 2019
2 parents dd44d6a + fe0fb22 commit 92dca0c
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ angular.module("admin.utils").directive "variantAutocomplete", ($timeout) ->
distributor_id: scope.distributor_id
order_cycle_id: scope.order_cycle_id
results: (data, page) ->
window.variants = data # this is how spree auto complete JS code picks up variants
results: data
formatResult: (variant) ->
if variant["images"][0] != undefined && variant["images"][0].image != undefined
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/ replace "code[erb-loud]:contains('hidden_field_tag :customer_search')"
/ replace "erb[loud]:contains('hidden_field_tag :customer_search')"
- content_for :app_wrapper_attrs do
= 'ng-app=admin.orders'
Expand Down
28 changes: 11 additions & 17 deletions app/views/spree/admin/orders/_add_product.html.haml
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
= render partial: "spree/admin/variants/autocomplete", formats: :js
#add-line-item
%fieldset
%legend{align: "center"}
= t(:add_product)
.field.eight.columns.alpha
= label_tag :add_product_name, t(:name_or_sku)
= hidden_field_tag :add_variant_id, "", class: "variant_autocomplete fullwidth"
.field.two.columns
= label_tag :add_quantity, t(:qty)
= number_field_tag :add_quantity, 1, min: 0
.actions.two.columns.omega
= link_to_with_icon 'icon-plus', t(:add), admin_order_line_items_url(@order),
method: :post,
id: 'add_line_item_to_order',
class: 'button fullwidth',
'data-update' => 'order-form-wrapper'
= render :partial => "spree/admin/variants/autocomplete", :formats => :js

#add-line-item{"data-hook" => ""}
%fieldset.no-border-bottom
%legend{:align => "center"}= Spree.t(:add_product)
.field.twelve.columns.alpha{"data-hook" => "add_product_name"}
= label_tag :add_variant_id, Spree.t(:name_or_sku)
= hidden_field_tag :add_variant_id, "", :class => "variant_autocomplete fullwidth"
#stock_details
96 changes: 36 additions & 60 deletions app/views/spree/admin/orders/_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,68 +1,44 @@
%div
%div{"data-hook" => "admin_order_form_fields"}
- if @line_item.try(:errors).present?
= render partial: 'spree/shared/error_messages', locals: { target: @line_item }
= form_for @order, url: admin_order_url(@order), method: :put do |f|
%fieldset.no-border-top
= f.hidden_field :number
%table.index{"ng-show" => "distributionChosen()"}
%colgroup
%col{style: "width: 49%;"}/
%col{style: "width: 14%;"}/
%col{style: "width: 10%;"}/
%col{style: "width: 14%;"}/
%col{style: "width: 8%;"}/
%thead#line-items
%tr
%th
= t(:item_description)
%th.price
= t(:price)
%th.qty
= t(:qty)
%th.total
%span
= t(:total)
%th.orders-actions.actions
%tbody
= f.fields_for :line_items do |li_form|
= render partial: 'spree/admin/orders/line_item', locals: { f: li_form }
%tbody#subtotal.no-border-top
%tr#subtotal-row
%td{colspan: "3"}
%b
= t(:subtotal)
\:
%td.total.align-center
%span
= @order.display_item_total.to_html
%td.actions
%tbody#order-charges.no-border-top
- @order.adjustments.eligible.each do |adjustment|
%tr
%td{colspan: "3"}
= render :partial => 'spree/shared/error_messages', :locals => { :target => @line_item }
= render :partial => "spree/admin/orders/shipment", :collection => @order.shipments, :locals => { :order => order }
- if order.adjustments.eligible.exists?
%fieldset.no-border-bottom
%legend= Spree.t('adjustments')
%table
%thead
%th= Spree.t('name')
%th= Spree.t('amount')
%tbody#order-charges.with-border{"data-hook" => "order_details_adjustments"}
- order.adjustments.eligible.each do |adjustment|
- next if ((adjustment.originator_type == 'Spree::TaxRate') and (adjustment.amount == 0)) || adjustment.originator_type == 'Spree::ShippingMethod'
%tr.total
%td
%strong
= adjustment.label
\:
%td.total.align-center
%span= adjustment.display_amount.to_html
%td.actions
%tbody#order-total.grand-total.no-border-top
%tr
%td{colspan: "3"}
%b
= t(:order_total)
\:
%td.total.align-center
%span#order_total
= @order.display_total.to_html
%td.actions
%span= adjustment.display_amount
- if order.line_items.exists?
%fieldset#order-total.no-border-bottom{"data-hook" => "order_details_total"}
%legend= Spree.t(:order_total)
%span.order-total= order.display_total
= form_for @order, url: admin_order_url(@order), method: :put do |f|
= render partial: 'spree/admin/orders/_form/distribution_fields'
= render partial: 'spree/admin/orders/_form/distribution_fields'
.filter-actions.actions{"ng-show" => "distributionChosen()"}
= button t(:update_and_recalculate_fees), 'icon-refresh'
%span.or
= t(:or)
= link_to_with_icon 'button icon-arrow-left', t(:back), admin_orders_url
.filter-actions.actions{"ng-show" => "distributionChosen()"}
= button t(:update_and_recalculate_fees), 'icon-refresh'
%span.or
= t(:or)
= link_to_with_icon 'button icon-arrow-left', t(:back), admin_orders_url
= javascript_tag do
= render partial: 'spree/admin/shared/update_order_state', handlers: [:js]
var order_number = '#{@order.number}';
var shipments = [];
- @order.shipments.each do |shipment|
shipments.push(#{shipment.to_json(:root => false, :include => [:inventory_units, :stock_location]).html_safe});
= render :partial => 'spree/admin/shared/update_order_state', :handlers => [:js]
37 changes: 22 additions & 15 deletions app/views/spree/admin/orders/edit.html.haml
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
= csrf_meta_tags

- content_for :page_actions do
%li= event_links
%li= button_link_to t(:resend), resend_admin_order_url(@order), method: :post, icon: 'icon-email'
- if can?(:fire, @order)
%li= event_links
- if can?(:resend, @order)
%li= button_link_to Spree.t(:resend), resend_admin_order_url(@order), :method => :post, :icon => 'icon-email'
%li.links-dropdown#links-dropdown{ links: order_links(@order).to_json }
- if can?(:admin, Spree::Order)
%li= button_link_to Spree.t(:back_to_orders_list), admin_orders_path, :icon => 'icon-arrow-left'

%li= button_link_to t(:back_to_orders_list), admin_orders_path, icon: 'icon-arrow-left'

= admin_inject_shops(module: 'admin.orders')
= admin_inject_order_cycles

= render 'spree/admin/shared/order_tabs', current: 'Order Details'
= render :partial => 'spree/admin/shared/order_tabs', :locals => { :current => 'Order Details' }

%div
%div{"data-hook" => "admin_order_edit_header"}
-# Suppress errors when manually creating a new order - needs to proceed to edit page
-# without having line items (which otherwise gives a validation error)
- unless params["suppress_error_msg"]
= render partial: "spree/shared/error_messages", :locals => { :target => @order }
%div{"ng-app" => "admin.orders", "ng-controller" => "orderCtrl", "ofn-distributor-id" => @order.distributor_id, "ofn-order-cycle-id" => @order.order_cycle_id}
= render 'add_product'
= admin_inject_shops(module: 'admin.orders')
= admin_inject_order_cycles
%div{"ng-app" => "admin.orders", "ng-controller" => "orderCtrl", "ofn-distributor-id" => @order.distributor_id, "ofn-order-cycle-id" => @order.order_cycle_id}
= render :partial => 'add_product' if can?(:update, @order)
- if @order.line_items.empty?
.no-objects-found
= Spree.t(:your_order_is_empty_add_product)
%div
#order-form-wrapper
= render 'form', order: @order
%div{"data-hook" => "admin_order_edit_form"}
#order-form-wrapper
= render :partial => 'form', :locals => { :order => @order }
- content_for :head do
= javascript_tag 'var expand_variants = true;'
Expand Down
7 changes: 5 additions & 2 deletions app/views/spree/admin/shared/_routes.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<script>
Spree.routes = <%== {
:variants_search => admin_search_variants_path(:format => 'json'),
:variants_search => spree.admin_search_variants_path(:format => 'json'),
:taxons_search => spree.api_taxons_path(:format => 'json'),
:user_search => spree.admin_search_users_path(:format => 'json'),
:product_search => spree.api_products_path(:format => 'json'),
:option_type_search => spree.api_option_types_path(:format => 'json'),
:states_search => spree.api_states_path(:format => 'json')
:states_search => spree.api_states_path(:format => 'json'),
:orders_api => spree.api_orders_path(:format => 'json'),
:stock_locations_api => spree.api_stock_locations_path(:format => 'json'),
:variants_api => spree.api_variants_path(:format => 'json')
}.to_json %>;
</script>
41 changes: 41 additions & 0 deletions app/views/spree/admin/variants/_autocomplete.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,44 @@
</div>
</div>
</script>
<script type='text/template' id='variant_autocomplete_stock_template'>
<fieldset>
<legend align="center"><%= Spree.t(:select_stock) %></legend>
<table class="stock-levels" data-hook="stock-levels">
<colgroup>
<col style="width: 30%;" />
<col style="width: 40%;" />
<col style="width: 20%;" />
<col style="width: 10%;" />
</colgroup>
<thead>
<th><%= Spree.t(:location) %></th>
<th><%= Spree.t(:count_on_hand) %></th>
<th><%= Spree.t(:quantity) %></th>
<th class="actions"></th>
</thead>
<tbody>
<tr>
<td>{{variant.stock_location_name}}</td>
{{#if variant.[in_stock?]}}
{{#if variant.on_demand}}
<td>Spree.t(:on_demand)</td>
{{else}}
<td>
{{variant.count_on_hand}}
</td>
{{/if}}
<td>
<input class="quantity" id="stock_item_quantity" data-stock-location-id="{{variant.stock_location_id}}" type="number" min="1" value="1">
</td>
<td class="actions">
<button class="add_variant no-text icon-plus icon_link with-tip" data-stock-location-id="{{variant.stock_location_id}}" title="Add" data-action="add"></button>
</td>
{{else}}
<td><%= Spree.t(:out_of_stock) %></td>
<td>0</td>
{{/if}}
</tr>
</tbody>
</fieldset>
</script>
10 changes: 9 additions & 1 deletion app/views/spree/admin/variants/search.rabl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# overriding spree/core/app/views/spree/admin/variants/search.rabl
#
collection @variants
attributes :sku, :options_text, :count_on_hand, :id, :cost_price
attributes :sku, :options_text, :in_stock?, :on_demand, :count_on_hand, :id, :cost_price

node(:name) do |v|
# TODO: when products must have a unit, full_name will always be present
Expand All @@ -22,6 +22,14 @@ node(:producer_name) do |v|
v.product.supplier.name
end

node(:stock_location_id) do |v|
v.stock_items.first.stock_location.id
end

node(:stock_location_name) do |v|
v.stock_items.first.stock_location.name
end

child(:images => :images) do
attributes :mini_url
end
Expand Down
Loading

0 comments on commit 92dca0c

Please sign in to comment.