<div class="calculator-fields row">

  <div class="field alpha four columns">
    <% field_name = "#{param_prefix}[calculator_type]" %>
    <%= label_tag field_name, Spree.t(:calculator) %>
    <%= select_tag field_name,
                   options_from_collection_for_select(Spree::Promotion::Actions::CreateItemAdjustments.calculators, :to_s, :description, promotion_action.calculator.type),
                   :class => 'type-select select2 fullwidth' %>
    <% if promotion_action.calculator.respond_to?(:preferences) %>
      <span class="warning info"><%= Spree.t(:calculator_settings_warning) %></span>
    <% end %>
  </div>

  <% unless promotion_action.new_record? %>
    <div class="settings field omega four columns">
      <% promotion_action.calculator.preferences.keys.map do |key| %>
        <% field_name = "#{param_prefix}[calculator_attributes][preferred_#{key}]" %>
        <%= label_tag field_name, Spree.t(key.to_s) %>
        <%= preference_field_tag(field_name,
                                 promotion_action.calculator.get_preference(key),
                                 :type => promotion_action.calculator.preference_type(key)) %>
      <% end %>
      <%= hidden_field_tag "#{param_prefix}[calculator_attributes][id]", promotion_action.calculator.id %>
    </div>
  <% end %>
</div>

<div class="calculator-fields row">

  <div class="field alpha four columns">
    <% field_name = "#{param_prefix}[calculator_type]" %>
    <%= label_tag field_name, Spree.t(:calculator) %>
    <%= select_tag field_name,
                   options_from_collection_for_select(Spree::Promotion::Actions::CreateItemAdjustments.calculators, :to_s, :description, promotion_action.calculator.type),
                   :class => 'type-select select2 fullwidth' %>
    <% if promotion_action.calculator.respond_to?(:preferences) %>
      <span class="warning info"><%= Spree.t(:calculator_settings_warning) %></span>
    <% end %>
  </div>

  <% unless promotion_action.new_record? %>
    <div class="settings field omega four columns">
      <% type_name = promotion_action.calculator.type.demodulize.underscore %>
      <% if lookup_context.exists?("fields",
          ["spree/admin/promotions/calculators/#{type_name}"], true) %>
        <%= render "spree/admin/promotions/calculators/#{type_name}/fields",
          calculator: promotion_action.calculator, prefix: param_prefix %>
      <% else %>
        <%= render "spree/admin/promotions/calculators/default_fields",
          calculator: promotion_action.calculator, prefix: param_prefix %>
      <% end %>
      <%= hidden_field_tag "#{param_prefix}[calculator_attributes][id]", promotion_action.calculator.id %>
    </div>
  <% end %>
</div>

Allow item_adjustments form to specify calculator-specific fields
Allow item_adjustments form to specify calculator-specific fields

Given a promotion action with complex fields, when creating it with and order-level
action it will allow you to specify the template that you want to render for the
promotion action. If no template is available, it uses the default fields.

If the promotion action is for the item-level, it will always use the default fields.

This allows stores to have the same logic for both order and line-item level promotion actions.
