From 35e42b28fe6d522830258c7d9f59b0e3f727ac2f Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 25 Jan 2017 16:11:24 +1100 Subject: [PATCH] Using customer selection to search for addresses on standing order creation Can also copy copy address from billing to shipping --- .../standing_order_controller.js.coffee | 14 +++++++- .../admin/standing_orders/_address.html.haml | 4 ++- config/locales/en.yml | 3 +- spec/features/admin/standing_orders_spec.rb | 35 ++++++++++++------- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/app/assets/javascripts/admin/standing_orders/controllers/standing_order_controller.js.coffee b/app/assets/javascripts/admin/standing_orders/controllers/standing_order_controller.js.coffee index 87a576a1b3..54f7b8513d 100644 --- a/app/assets/javascripts/admin/standing_orders/controllers/standing_order_controller.js.coffee +++ b/app/assets/javascripts/admin/standing_orders/controllers/standing_order_controller.js.coffee @@ -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) diff --git a/app/views/admin/standing_orders/_address.html.haml b/app/views/admin/standing_orders/_address.html.haml index 2b8d121c5b..ecf86b87cb 100644 --- a/app/views/admin/standing_orders/_address.html.haml +++ b/app/views/admin/standing_orders/_address.html.haml @@ -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) diff --git a/config/locales/en.yml b/config/locales/en.yml index cea1f65a72..81c6ac7f15 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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" diff --git a/spec/features/admin/standing_orders_spec.rb b/spec/features/admin/standing_orders_spec.rb index afaee71f47..b1f8a96b36 100644 --- a/spec/features/admin/standing_orders_spec.rb +++ b/spec/features/admin/standing_orders_spec.rb @@ -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'