mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
When admin associates user with an order, look up last used address
This commit is contained in:
@@ -12,7 +12,14 @@ Spree::Admin::SearchController.class_eval do
|
||||
:bill_address_lastname_start => params[:q]
|
||||
}).result.limit(10)
|
||||
end
|
||||
render :users
|
||||
|
||||
render :users
|
||||
end
|
||||
|
||||
|
||||
def users_with_ams
|
||||
users_without_ams
|
||||
render json: @users, each_serializer: Api::Admin::UserSerializer
|
||||
end
|
||||
alias_method_chain :users, :ams
|
||||
end
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
require 'open_food_network/last_used_address'
|
||||
|
||||
class Api::Admin::UserSerializer < ActiveModel::Serializer
|
||||
attributes :id, :email
|
||||
|
||||
has_one :ship_address, serializer: Api::AddressSerializer
|
||||
has_one :bill_address, serializer: Api::AddressSerializer
|
||||
|
||||
def ship_address
|
||||
object.ship_address ||
|
||||
OpenFoodNetwork::LastUsedAddress.new(object.email).last_used_ship_address
|
||||
end
|
||||
|
||||
def bill_address
|
||||
object.bill_address ||
|
||||
OpenFoodNetwork::LastUsedAddress.new(object.email).last_used_bill_address
|
||||
end
|
||||
end
|
||||
|
||||
@@ -113,6 +113,36 @@ feature %q{
|
||||
page.should have_selector 'p', text: "Order cycle: None"
|
||||
end
|
||||
|
||||
scenario "filling customer details" do
|
||||
# Given a customer with an order, which includes their shipping and billing address
|
||||
@order.ship_address = create(:address, lastname: 'Ship')
|
||||
@order.bill_address = create(:address, lastname: 'Bill')
|
||||
@order.shipping_method = create(:shipping_method, require_ship_address: true)
|
||||
@order.save!
|
||||
|
||||
# When I create a new order
|
||||
login_to_admin_section
|
||||
visit '/admin/orders'
|
||||
click_link 'New Order'
|
||||
select @distributor.name, from: 'order_distributor_id'
|
||||
select2_select @order_cycle.name, from: 'order_order_cycle_id'
|
||||
targetted_select2_search @product.name, from: '#add_variant_id', dropdown_css: '.select2-drop'
|
||||
click_link 'Add'
|
||||
page.has_selector? "table.index tbody[data-hook='admin_order_form_line_items'] tr" # Wait for JS
|
||||
click_button 'Update'
|
||||
within('h1.page-title') { page.should have_content "Customer Details" }
|
||||
|
||||
# And I select that customer's email address and save the order
|
||||
targetted_select2_search @order.user.email, from: '#customer_search', dropdown_css: '.select2-drop'
|
||||
click_button 'Continue'
|
||||
within('h1.page-title') { page.should have_content "Shipments" }
|
||||
|
||||
# Then their addresses should be associated with the order
|
||||
order = Spree::Order.last
|
||||
order.ship_address.lastname.should == 'Ship'
|
||||
order.bill_address.lastname.should == 'Bill'
|
||||
end
|
||||
|
||||
scenario "capture multiple payments from the orders index page" do
|
||||
# d.cook: could also test for an order that has had payment voided, then a new check payment created but not yet captured. But it's not critical and I know it works anyway.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user