mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-06 02:51:34 +00:00
Using customer selection to search for addresses on standing order creation
Can also copy copy address from billing to shipping
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
angular.module("admin.standingOrders").controller "StandingOrderController", ($scope, StandingOrder, customers, schedules, paymentMethods, shippingMethods) ->
|
||||
angular.module("admin.standingOrders").controller "StandingOrderController", ($scope, $http, StandingOrder, customers, schedules, paymentMethods, shippingMethods) ->
|
||||
$scope.standingOrder = new StandingOrder()
|
||||
$scope.customers = customers
|
||||
$scope.schedules = schedules
|
||||
@@ -25,3 +25,15 @@ angular.module("admin.standingOrders").controller "StandingOrderController", ($s
|
||||
$scope.registerBackCallback = (view, callback) => $scope.backCallbacks[view] = callback
|
||||
$scope.next = -> $scope.nextCallbacks[$scope.view]()
|
||||
$scope.back = -> $scope.backCallbacks[$scope.view]()
|
||||
|
||||
$scope.$watch "standingOrder.customer_id", (newValue, oldValue) ->
|
||||
return if !newValue? || newValue == oldValue
|
||||
$http.get("/admin/search/customer_addresses", params: { customer_id: newValue })
|
||||
.success (response) =>
|
||||
delete response.bill_address.id
|
||||
delete response.ship_address.id
|
||||
angular.extend($scope.standingOrder.bill_address, response.bill_address)
|
||||
angular.extend($scope.standingOrder.ship_address, response.ship_address)
|
||||
|
||||
$scope.shipAddressFromBilling = =>
|
||||
angular.extend($scope.standingOrder.ship_address, $scope.standingOrder.bill_address)
|
||||
|
||||
@@ -45,7 +45,9 @@
|
||||
|
||||
|
||||
.two.columns
|
||||
|
||||
%a.button.red.fullwidth{ href: 'javascript:void(0)', ng: { click: 'shipAddressFromBilling()' } }
|
||||
= t('copy')
|
||||
%i.icon-chevron-right
|
||||
.seven.columns.omega
|
||||
%fieldset.no-border-bottom
|
||||
%legend{ align: 'center'}= t(:ship_address)
|
||||
|
||||
@@ -185,7 +185,8 @@ en:
|
||||
filter_results: Filter Results
|
||||
quantity: Quantity
|
||||
pick_up: Pick up
|
||||
|
||||
ok: Ok
|
||||
copy: Copy
|
||||
|
||||
actions:
|
||||
create_and_add_another: "Create and Add Another"
|
||||
|
||||
@@ -121,7 +121,8 @@ feature 'Standing Orders' do
|
||||
end
|
||||
|
||||
context 'creating a new standing order' do
|
||||
let!(:customer) { create(:customer, enterprise: shop) }
|
||||
let(:address) { create(:address) }
|
||||
let!(:customer) { create(:customer, enterprise: shop, bill_address: address) }
|
||||
let!(:product1) { create(:product, supplier: shop) }
|
||||
let!(:product2) { create(:product, supplier: shop) }
|
||||
let!(:variant1) { create(:variant, product: product1, unit_value: '100', price: 12.00, option_values: []) }
|
||||
@@ -152,20 +153,28 @@ feature 'Standing Orders' do
|
||||
|
||||
click_button('Next')
|
||||
expect(page).to have_content 'BILLING ADDRESS'
|
||||
# Customer bill address has been pre-loaded
|
||||
expect(page).to have_input "bill_address_firstname", with: address.firstname
|
||||
expect(page).to have_input "bill_address_lastname", with: address.lastname
|
||||
expect(page).to have_input "bill_address_address1", with: address.address1
|
||||
click_button('Next')
|
||||
expect(page).to have_content 'can\'t be blank', count: 16
|
||||
expect(page).to have_content 'can\'t be blank', count: 7 # 7 because country is set on Spree::Address.default
|
||||
|
||||
# Setting the shipping and billing addresses
|
||||
[:bill_address, :ship_address].each do |type|
|
||||
fill_in "#{type}_firstname", with: 'Freda'
|
||||
fill_in "#{type}_lastname", with: 'Figapple'
|
||||
fill_in "#{type}_address1", with: '7 Tempany Lane'
|
||||
fill_in "#{type}_city", with: 'Natte Yallock'
|
||||
fill_in "#{type}_zipcode", with: '3465'
|
||||
fill_in "#{type}_phone", with: '0400 123 456'
|
||||
select2_select "Australia", from: "#{type}_country_id"
|
||||
select2_select "Victoria", from: "#{type}_state_id"
|
||||
end
|
||||
# Setting the billing address
|
||||
fill_in "bill_address_firstname", with: 'Freda'
|
||||
fill_in "bill_address_lastname", with: 'Figapple'
|
||||
fill_in "bill_address_address1", with: '7 Tempany Lane'
|
||||
fill_in "bill_address_city", with: 'Natte Yallock'
|
||||
fill_in "bill_address_zipcode", with: '3465'
|
||||
fill_in "bill_address_phone", with: '0400 123 456'
|
||||
select2_select "Australia", from: "bill_address_country_id"
|
||||
select2_select "Victoria", from: "bill_address_state_id"
|
||||
|
||||
# Use copy button to fill in ship address
|
||||
click_link "Copy"
|
||||
expect(page).to have_input "ship_address_firstname", with: 'Freda'
|
||||
expect(page).to have_input "ship_address_lastname", with: 'Figapple'
|
||||
expect(page).to have_input "ship_address_address1", with: '7 Tempany Lane'
|
||||
|
||||
click_button('Next')
|
||||
expect(page).to have_content 'NAME OR SKU'
|
||||
|
||||
Reference in New Issue
Block a user