From 783b055d55ef8e29374bbe1fd06e9574b36f984b Mon Sep 17 00:00:00 2001 From: Nihal Mohammed Date: Fri, 23 Jul 2021 19:03:13 +0530 Subject: [PATCH 01/36] Add business address permitted attributes --- .../permitted_attributes/business_address.rb | 14 ++++++++++++++ app/services/permitted_attributes/enterprise.rb | 1 + 2 files changed, 15 insertions(+) create mode 100644 app/services/permitted_attributes/business_address.rb diff --git a/app/services/permitted_attributes/business_address.rb b/app/services/permitted_attributes/business_address.rb new file mode 100644 index 0000000000..53eb64ceeb --- /dev/null +++ b/app/services/permitted_attributes/business_address.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module PermittedAttributes + class BusinessAddress + def self.attributes + [ + :business_name, :address1, :address2, + :city, :country_id, :state_id, :zipcode, + :phone + ] + end + end + end + \ No newline at end of file diff --git a/app/services/permitted_attributes/enterprise.rb b/app/services/permitted_attributes/enterprise.rb index a3f688c64d..dbae9dee32 100644 --- a/app/services/permitted_attributes/enterprise.rb +++ b/app/services/permitted_attributes/enterprise.rb @@ -17,6 +17,7 @@ module PermittedAttributes group_ids: [], user_ids: [], shipping_method_ids: [], payment_method_ids: [], address_attributes: PermittedAttributes::Address.attributes, + business_address_attributes: PermittedAttributes::BusinessAddress.attributes, producer_properties_attributes: [:id, :property_name, :value, :_destroy] ] end From 56c02a2e99917273d00f0a5b48c5cc6e3f2ac90a Mon Sep 17 00:00:00 2001 From: Nihal Mohammed Date: Sat, 24 Jul 2021 02:29:35 +0530 Subject: [PATCH 02/36] Add business_address to build_resource method in enterprise_controller --- app/controllers/admin/enterprises_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index c2a9460447..25f192c540 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -130,6 +130,7 @@ module Admin def build_resource enterprise = super enterprise.address ||= Spree::Address.new + enterprise.business_address ||= Spree::Address.new enterprise.address.country ||= DefaultCountry.country enterprise end From e3307fd3413691ac637342465f2236ad0ae30ab7 Mon Sep 17 00:00:00 2001 From: Nihal Mohammed Date: Mon, 26 Jul 2021 18:51:21 +0530 Subject: [PATCH 03/36] Migration to add business_address_id to enterpries --- .../20210726132054_add_business_address_id_to_enterprises.rb | 5 +++++ db/schema.rb | 1 + 2 files changed, 6 insertions(+) create mode 100644 db/migrate/20210726132054_add_business_address_id_to_enterprises.rb diff --git a/db/migrate/20210726132054_add_business_address_id_to_enterprises.rb b/db/migrate/20210726132054_add_business_address_id_to_enterprises.rb new file mode 100644 index 0000000000..2fc63c138f --- /dev/null +++ b/db/migrate/20210726132054_add_business_address_id_to_enterprises.rb @@ -0,0 +1,5 @@ +class AddBusinessAddressIdToEnterprises < ActiveRecord::Migration[6.1] + def change + add_column :enterprises, :business_address_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 97dd60cf72..8f91507988 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -209,6 +209,7 @@ ActiveRecord::Schema.define(version: 2021_09_27_091723) do t.string "terms_and_conditions_content_type", limit: 255 t.integer "terms_and_conditions_file_size" t.datetime "terms_and_conditions_updated_at" + t.integer "business_address_id" t.index ["address_id"], name: "index_enterprises_on_address_id" t.index ["is_primary_producer", "sells"], name: "index_enterprises_on_is_primary_producer_and_sells" t.index ["name"], name: "index_enterprises_on_name", unique: true From 9007418455663bae4d8980963563d46b4f6617ec Mon Sep 17 00:00:00 2001 From: Nihal Mohammed Date: Mon, 26 Jul 2021 18:56:28 +0530 Subject: [PATCH 04/36] Set belongs_to association for business_address and accept nested attributes on enterprise model --- app/models/enterprise.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index aef90188da..efc9763c98 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -41,6 +41,7 @@ class Enterprise < ApplicationRecord dependent: :destroy has_many :distributed_orders, class_name: 'Spree::Order', foreign_key: 'distributor_id' belongs_to :address, class_name: 'Spree::Address' + belongs_to :business_address, class_name: 'Spree::Address', dependent: :destroy has_many :enterprise_fees has_many :enterprise_roles, dependent: :destroy has_many :users, through: :enterprise_roles @@ -59,6 +60,7 @@ class Enterprise < ApplicationRecord delegate :latitude, :longitude, :city, :state_name, to: :address accepts_nested_attributes_for :address + accepts_nested_attributes_for :business_address accepts_nested_attributes_for :producer_properties, allow_destroy: true, reject_if: lambda { |pp| pp[:property_name].blank? From 26c7cb2bd383835bbb8cbd785eab704fe2367790 Mon Sep 17 00:00:00 2001 From: Nihal Mohammed Date: Mon, 26 Jul 2021 19:00:07 +0530 Subject: [PATCH 05/36] Fix business_address attribute permissions --- .../permitted_attributes/business_address.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/services/permitted_attributes/business_address.rb b/app/services/permitted_attributes/business_address.rb index 53eb64ceeb..2d04223143 100644 --- a/app/services/permitted_attributes/business_address.rb +++ b/app/services/permitted_attributes/business_address.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true module PermittedAttributes - class BusinessAddress - def self.attributes - [ - :business_name, :address1, :address2, - :city, :country_id, :state_id, :zipcode, - :phone - ] - end + class BusinessAddress + def self.attributes + [ + :company, :address1, :address2, + :city, :country_id, :state_id, :zipcode, + :phone + ] end end +end \ No newline at end of file From 7096667c6f1ba09c191edcc77beb6902a647d891 Mon Sep 17 00:00:00 2001 From: Nihal Mohammed Date: Mon, 26 Jul 2021 19:24:57 +0530 Subject: [PATCH 06/36] Add business_address form to business details section --- app/models/spree/address.rb | 4 +- .../form/_business_address.html.haml | 40 +++++++++++++++++++ .../form/_business_details.html.haml | 5 +++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 app/views/admin/enterprises/form/_business_address.html.haml diff --git a/app/models/spree/address.rb b/app/models/spree/address.rb index 24ed00ef5c..b68c88eb3e 100644 --- a/app/models/spree/address.rb +++ b/app/models/spree/address.rb @@ -13,7 +13,9 @@ module Spree has_one :enterprise, dependent: :restrict_with_exception has_many :shipments - validates :firstname, :lastname, :address1, :city, :country, presence: true + validates :address1, :city, presence: true + validates :firstname, :lastname, presence: true, unless: -> { :company.present? } + validates :company, presence: true, unless: -> { :firstname.present? || :lastname.present? } validates :zipcode, presence: true, if: :require_zipcode? validate :state_validate diff --git a/app/views/admin/enterprises/form/_business_address.html.haml b/app/views/admin/enterprises/form/_business_address.html.haml new file mode 100644 index 0000000000..3df6a9c050 --- /dev/null +++ b/app/views/admin/enterprises/form/_business_address.html.haml @@ -0,0 +1,40 @@ +.row + .three.columns.alpha + = bf.label :company, t(:Company_legal_name) + .eight.columns.omega + = bf.text_field :company, { placeholder: t(:legal_name_placeholder) } + +.row + .three.columns.alpha + = bf.label :address1, t(:address) + .eight.columns.omega + = bf.text_field :address1, { placeholder: t(:address_placeholder) } +.row + .alpha.three.columns + = bf.label :address2, t(:address2) + .eight.columns.omega + = bf.text_field :address2 +.row + .three.columns.alpha + = bf.label :city, t(:city) + \/ + = bf.label :zipcode, t(:postcode) + .four.columns + = bf.text_field :city, { placeholder: t(:city_placeholder) } + .four.columns.omega + = bf.text_field :zipcode, { placeholder: t(:postcode_placeholder) } +.row + .three.columns.alpha + = bf.label :state_id, t(:state) + \/ + = bf.label :country_id, t(:country) + .four.columns{ "ng-controller" => "countryCtrl" } + %input.ofn-select2.fullwidth#enterprise_address_attributes_state_id{ name: 'enterprise[address_attributes][state_id]', type: 'number', data: 'countriesById[Enterprise.address.country_id].states', placeholder: t('admin.choose'), ng: { model: 'Enterprise.address.state_id' } } + .four.columns.omega{ "ng-controller" => "countryCtrl" } + %input.ofn-select2.fullwidth#enterprise_address_attributes_country_id{ name: 'enterprise[address_attributes][country_id]', type: 'number', data: 'countries', placeholder: t('admin.choose'), ng: { model: 'Enterprise.address.country_id' } } + +.row + .three.columns.alpha + = bf.label :phone, t(:legal_phone_number) + .eight.columns.omega + = bf.text_field :phone, { placeholder: t(:phone_placeholder) } diff --git a/app/views/admin/enterprises/form/_business_details.html.haml b/app/views/admin/enterprises/form/_business_details.html.haml index 1bade5b580..db82258376 100644 --- a/app/views/admin/enterprises/form/_business_details.html.haml +++ b/app/views/admin/enterprises/form/_business_details.html.haml @@ -47,3 +47,8 @@ .pad-top %a.button.red{ href: '', ng: {click: 'removeTermsAndConditions()', if: 'Enterprise.terms_and_conditions'} } = t('.remove_terms_and_conditions') + + += f.fields_for :business_address, @enterprise.business_address || @enterprise.build_business_address do |bf| + %legend {{business_address.label}} + = render 'admin/enterprises/form/business_address', bf: bf From 83524f2285ca39e00e23709e9295260f5f91be01 Mon Sep 17 00:00:00 2001 From: Nihal Mohammed Date: Tue, 27 Jul 2021 18:10:38 +0530 Subject: [PATCH 07/36] Update en.yml to include translations for business_address form --- .../enterprises/form/_business_address.html.haml | 14 +++++++------- config/locales/en.yml | 8 ++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/views/admin/enterprises/form/_business_address.html.haml b/app/views/admin/enterprises/form/_business_address.html.haml index 3df6a9c050..7e3dafed96 100644 --- a/app/views/admin/enterprises/form/_business_address.html.haml +++ b/app/views/admin/enterprises/form/_business_address.html.haml @@ -1,17 +1,17 @@ .row .three.columns.alpha - = bf.label :company, t(:Company_legal_name) + = bf.label :company, t(".company_legal_name") .eight.columns.omega - = bf.text_field :company, { placeholder: t(:legal_name_placeholder) } + = bf.text_field :company, { placeholder: t(".company_placeholder") } .row .three.columns.alpha - = bf.label :address1, t(:address) + = bf.label :address1, t('.address1') .eight.columns.omega - = bf.text_field :address1, { placeholder: t(:address_placeholder) } + = bf.text_field :address1, { placeholder: t(".address1_placeholder") } .row .alpha.three.columns - = bf.label :address2, t(:address2) + = bf.label :address2, t(".address2") .eight.columns.omega = bf.text_field :address2 .row @@ -35,6 +35,6 @@ .row .three.columns.alpha - = bf.label :phone, t(:legal_phone_number) + = bf.label :phone, t(".legal_phone_number") .eight.columns.omega - = bf.text_field :phone, { placeholder: t(:phone_placeholder) } + = bf.text_field :phone, { placeholder: t(".phone_placeholder") } diff --git a/config/locales/en.yml b/config/locales/en.yml index d9e0955a23..7525ab822a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -774,6 +774,14 @@ en: terms_and_conditions: "Terms and Conditions" remove_terms_and_conditions: "Remove File" uploaded_on: "uploaded on" + business_address: + company_legal_name: Company Legal Name + company_placeholder: Example Inc. + address1: Legal address + address1_placeholder: 123 High St. + address2: Address(contd.) + legal_phone_number: Legal phone number + phone_placeholder: "98 123 4565" contact: name: Name name_placeholder: eg. Gustav Plum From 8393414bf53b3a21c15eb5ff9f1f6595ff10df21 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Wed, 28 Jul 2021 11:04:55 +0100 Subject: [PATCH 08/36] Adapt admin enterprise form handling for both address and business_address --- .../controllers/country_controller.js.coffee | 14 ++++++++------ app/serializers/api/admin/enterprise_serializer.rb | 1 + .../enterprises/form/_business_address.html.haml | 9 +++++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/admin/enterprises/controllers/country_controller.js.coffee b/app/assets/javascripts/admin/enterprises/controllers/country_controller.js.coffee index 085a992a36..a9aa6148bf 100644 --- a/app/assets/javascripts/admin/enterprises/controllers/country_controller.js.coffee +++ b/app/assets/javascripts/admin/enterprises/controllers/country_controller.js.coffee @@ -1,5 +1,6 @@ # Used in enterprise new and edit forms to reset the state when the country is changed -angular.module("admin.enterprises").controller 'countryCtrl', ($scope, availableCountries) -> +angular.module("admin.enterprises").controller 'countryCtrl', ($scope, $timeout, availableCountries) -> + $scope.address_type = "address" $scope.countries = availableCountries $scope.countriesById = $scope.countries.reduce (obj, country) -> @@ -7,12 +8,13 @@ angular.module("admin.enterprises").controller 'countryCtrl', ($scope, available obj , {} - $scope.$watch 'Enterprise.address.country_id', (newID, oldID) -> - $scope.clearState() unless $scope.addressStateMatchesCountry() + $timeout -> + $scope.$watch 'Enterprise.' + $scope.address_type + '.country_id', (newID, oldID) -> + $scope.clearState() unless $scope.addressStateMatchesCountry() $scope.clearState = -> - $scope.Enterprise.address.state_id = null + $scope.Enterprise[$scope.address_type].state_id = null $scope.addressStateMatchesCountry = -> - $scope.countriesById[$scope.Enterprise.address.country_id].states.some (state) -> - state.id == $scope.Enterprise.address.state_id + $scope.countriesById[$scope.Enterprise[$scope.address_type].country_id].states.some (state) -> + state.id == $scope.Enterprise[$scope.address_type].state_id diff --git a/app/serializers/api/admin/enterprise_serializer.rb b/app/serializers/api/admin/enterprise_serializer.rb index cc2a962f7e..6d45133e4c 100644 --- a/app/serializers/api/admin/enterprise_serializer.rb +++ b/app/serializers/api/admin/enterprise_serializer.rb @@ -17,6 +17,7 @@ module Api has_one :owner, serializer: Api::Admin::UserSerializer has_many :users, serializer: Api::Admin::UserSerializer has_one :address, serializer: Api::AddressSerializer + has_one :business_address, serializer: Api::AddressSerializer def logo attachment_urls(object.logo, [:thumb, :small, :medium]) diff --git a/app/views/admin/enterprises/form/_business_address.html.haml b/app/views/admin/enterprises/form/_business_address.html.haml index 7e3dafed96..88d6959777 100644 --- a/app/views/admin/enterprises/form/_business_address.html.haml +++ b/app/views/admin/enterprises/form/_business_address.html.haml @@ -28,10 +28,11 @@ = bf.label :state_id, t(:state) \/ = bf.label :country_id, t(:country) - .four.columns{ "ng-controller" => "countryCtrl" } - %input.ofn-select2.fullwidth#enterprise_address_attributes_state_id{ name: 'enterprise[address_attributes][state_id]', type: 'number', data: 'countriesById[Enterprise.address.country_id].states', placeholder: t('admin.choose'), ng: { model: 'Enterprise.address.state_id' } } - .four.columns.omega{ "ng-controller" => "countryCtrl" } - %input.ofn-select2.fullwidth#enterprise_address_attributes_country_id{ name: 'enterprise[address_attributes][country_id]', type: 'number', data: 'countries', placeholder: t('admin.choose'), ng: { model: 'Enterprise.address.country_id' } } + %div{ "ng-controller": "countryCtrl", "ng-init": "address_type='business_address'" } + .four.columns + %input.ofn-select2.fullwidth#enterprise_business_address_attributes_state_id{ name: 'enterprise[business_address_attributes][state_id]', type: 'number', data: 'countriesById[Enterprise.address.country_id].states', placeholder: t('admin.choose'), ng: { model: 'Enterprise.business_address.state_id' } } + .four.columns.omega{ "ng-controller" => "countryCtrl" } + %input.ofn-select2.fullwidth#enterprise_business_address_attributes_country_id{ name: 'enterprise[business_address_attributes][country_id]', type: 'number', data: 'countries', placeholder: t('admin.choose'), ng: { model: 'Enterprise.business_address.country_id' } } .row .three.columns.alpha From ed8edf0ab976f6f24b941fade22595ce9b174c6f Mon Sep 17 00:00:00 2001 From: "Nihal M. Kelanthodika" Date: Wed, 28 Jul 2021 18:14:18 +0530 Subject: [PATCH 09/36] Update business_address form Removes `{ "ng-controller" => "countryCtrl" }` from column element as its now on the parent div. Co-authored-by: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> --- app/views/admin/enterprises/form/_business_address.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/enterprises/form/_business_address.html.haml b/app/views/admin/enterprises/form/_business_address.html.haml index 88d6959777..547d98e1d7 100644 --- a/app/views/admin/enterprises/form/_business_address.html.haml +++ b/app/views/admin/enterprises/form/_business_address.html.haml @@ -31,7 +31,7 @@ %div{ "ng-controller": "countryCtrl", "ng-init": "address_type='business_address'" } .four.columns %input.ofn-select2.fullwidth#enterprise_business_address_attributes_state_id{ name: 'enterprise[business_address_attributes][state_id]', type: 'number', data: 'countriesById[Enterprise.address.country_id].states', placeholder: t('admin.choose'), ng: { model: 'Enterprise.business_address.state_id' } } - .four.columns.omega{ "ng-controller" => "countryCtrl" } + .four.columns.omega %input.ofn-select2.fullwidth#enterprise_business_address_attributes_country_id{ name: 'enterprise[business_address_attributes][country_id]', type: 'number', data: 'countries', placeholder: t('admin.choose'), ng: { model: 'Enterprise.business_address.country_id' } } .row From f5743b3b364d46d397ee1f1d40a0a690891925de Mon Sep 17 00:00:00 2001 From: Nihal Mohammed Date: Fri, 30 Jul 2021 01:46:41 +0530 Subject: [PATCH 10/36] Update invoice templates to use business address when form filled in --- .../spree/admin/orders/invoice.html.haml | 10 +++++-- .../spree/admin/orders/invoice2.html.haml | 30 +++++++++++++------ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/app/views/spree/admin/orders/invoice.html.haml b/app/views/spree/admin/orders/invoice.html.haml index 73629cea18..1ee17ea165 100644 --- a/app/views/spree/admin/orders/invoice.html.haml +++ b/app/views/spree/admin/orders/invoice.html.haml @@ -18,12 +18,18 @@ %h4= @order.order_cycle&.name %tr{ valign: "top" } %td{ align: "left", colspan: 3 } - %strong= "#{t('.from')}: #{@order.distributor.name}" + - if @order.distributor.business_address.blank? + %strong= "#{t('.from')}: #{@order.distributor.name}" + - else + %strong= "#{t('.from')}: #{@order.distributor.business_address.company}" - if @order.distributor.abn.present? %br = "#{t(:abn)} #{@order.distributor.abn}" %br - = @order.distributor.address.full_address + - if @order.distributor.business_address.blank? + = @order.distributor.address.full_address + - else + = @order.distributor.business_address.full_address %br = @order.distributor.contact.email %tr{ valign: "top" } diff --git a/app/views/spree/admin/orders/invoice2.html.haml b/app/views/spree/admin/orders/invoice2.html.haml index c38472e0d9..9428d62eca 100644 --- a/app/views/spree/admin/orders/invoice2.html.haml +++ b/app/views/spree/admin/orders/invoice2.html.haml @@ -12,16 +12,28 @@ = wicked_pdf_image_tag @order.distributor.logo(:small), width: 150, height: 150 %tr{ valign: "top" } %td{ :align => "left" } - %strong= @order.distributor.name - %br - = @order.distributor.address.address_part1 - %br - = @order.distributor.address.address_part2 - %br - = @order.distributor.email_address - - if @order.distributor.phone.present? + - if @order.distributor.business_address.blank? + %strong= @order.distributor.name %br - = @order.distributor.phone + = @order.distributor.address.address_part1 + %br + = @order.distributor.address.address_part2 + %br + = @order.distributor.email_address + - if @order.distributor.phone.present? + %br + = @order.distributor.phone + - else + %strong= @order.distributor.business_address.company + %br + = @order.distributor.business_address.address_part1 + %br + = @order.distributor.business_address.address_part2 + %br + = @order.distributor.email_address + - if @order.distributor.business_address.phone.present? + %br + = @order.distributor.business_address.phone - if @order.distributor.abn.present? %br = "#{t :abn} #{@order.distributor.abn}" From 32d8ce78eff642a17c60362104d2eb796d9554bf Mon Sep 17 00:00:00 2001 From: Nihal Mohammed Date: Fri, 30 Jul 2021 16:51:38 +0530 Subject: [PATCH 11/36] Re-add :country validation to spree_address model --- app/models/spree/address.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/address.rb b/app/models/spree/address.rb index b68c88eb3e..d418cdd699 100644 --- a/app/models/spree/address.rb +++ b/app/models/spree/address.rb @@ -13,7 +13,7 @@ module Spree has_one :enterprise, dependent: :restrict_with_exception has_many :shipments - validates :address1, :city, presence: true + validates :address1, :city, :country, presence: true validates :firstname, :lastname, presence: true, unless: -> { :company.present? } validates :company, presence: true, unless: -> { :firstname.present? || :lastname.present? } validates :zipcode, presence: true, if: :require_zipcode? From 3cd5ed58c03bb9d35fba56b255caeca2c7af2084 Mon Sep 17 00:00:00 2001 From: Nihal Mohammed Date: Tue, 10 Aug 2021 15:54:47 +0530 Subject: [PATCH 12/36] Add checkbox to clear business_address form --- app/models/enterprise.rb | 2 +- app/services/permitted_attributes/business_address.rb | 2 +- .../admin/enterprises/form/_business_address.html.haml | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index efc9763c98..b394f2bca7 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -60,7 +60,7 @@ class Enterprise < ApplicationRecord delegate :latitude, :longitude, :city, :state_name, to: :address accepts_nested_attributes_for :address - accepts_nested_attributes_for :business_address + accepts_nested_attributes_for :business_address, allow_destroy: true accepts_nested_attributes_for :producer_properties, allow_destroy: true, reject_if: lambda { |pp| pp[:property_name].blank? diff --git a/app/services/permitted_attributes/business_address.rb b/app/services/permitted_attributes/business_address.rb index 2d04223143..2a4154e7ea 100644 --- a/app/services/permitted_attributes/business_address.rb +++ b/app/services/permitted_attributes/business_address.rb @@ -6,7 +6,7 @@ module PermittedAttributes [ :company, :address1, :address2, :city, :country_id, :state_id, :zipcode, - :phone + :phone, :_destroy ] end end diff --git a/app/views/admin/enterprises/form/_business_address.html.haml b/app/views/admin/enterprises/form/_business_address.html.haml index 547d98e1d7..f44f606442 100644 --- a/app/views/admin/enterprises/form/_business_address.html.haml +++ b/app/views/admin/enterprises/form/_business_address.html.haml @@ -39,3 +39,9 @@ = bf.label :phone, t(".legal_phone_number") .eight.columns.omega = bf.text_field :phone, { placeholder: t(".phone_placeholder") } + +.row + .three.columns.alpha + = bf.label :clear + .eight.columns.omega + = bf.check_box :_destroy From 1c72cd799d1ab2d19e914e2091de2d37dc1ae45f Mon Sep 17 00:00:00 2001 From: Nihal Mohammed Date: Wed, 11 Aug 2021 13:36:42 +0530 Subject: [PATCH 13/36] Permit :id attribute in PermittedAttributes:BusinessAddress --- app/services/permitted_attributes/business_address.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/permitted_attributes/business_address.rb b/app/services/permitted_attributes/business_address.rb index 2a4154e7ea..52a4bccb75 100644 --- a/app/services/permitted_attributes/business_address.rb +++ b/app/services/permitted_attributes/business_address.rb @@ -6,7 +6,7 @@ module PermittedAttributes [ :company, :address1, :address2, :city, :country_id, :state_id, :zipcode, - :phone, :_destroy + :phone, :_destroy, :id ] end end From 9cd0314ab3c1f5ab511cb48b1a66923419d361d8 Mon Sep 17 00:00:00 2001 From: Nihal Mohammed Date: Wed, 11 Aug 2021 13:54:57 +0530 Subject: [PATCH 14/36] Fix business address title and border --- app/views/admin/enterprises/form/_business_details.html.haml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/admin/enterprises/form/_business_details.html.haml b/app/views/admin/enterprises/form/_business_details.html.haml index db82258376..6e69312917 100644 --- a/app/views/admin/enterprises/form/_business_details.html.haml +++ b/app/views/admin/enterprises/form/_business_details.html.haml @@ -50,5 +50,6 @@ = f.fields_for :business_address, @enterprise.business_address || @enterprise.build_business_address do |bf| - %legend {{business_address.label}} - = render 'admin/enterprises/form/business_address', bf: bf + %fieldset.alpha.no-border-bottom + %legend= t('business_address') + = render 'admin/enterprises/form/business_address', bf: bf From 7ef6671e370102a6d97548630edf24ed81ad4b08 Mon Sep 17 00:00:00 2001 From: Nihal Mohammed Date: Wed, 11 Aug 2021 14:13:04 +0530 Subject: [PATCH 15/36] Add tooltip for business address Fix schema --- .../templates/admin/modals/business_address_info.html.haml | 7 +++++++ .../admin/enterprises/form/_business_address.html.haml | 3 +++ config/locales/en.yml | 3 +++ 3 files changed, 13 insertions(+) create mode 100644 app/assets/javascripts/templates/admin/modals/business_address_info.html.haml diff --git a/app/assets/javascripts/templates/admin/modals/business_address_info.html.haml b/app/assets/javascripts/templates/admin/modals/business_address_info.html.haml new file mode 100644 index 0000000000..abb0eb148f --- /dev/null +++ b/app/assets/javascripts/templates/admin/modals/business_address_info.html.haml @@ -0,0 +1,7 @@ +%div + .margin-bottom-30 + %p + {{ 'js.admin.modals.business_address_info.message' | t }} + + .text-center + %input.button.red.icon-plus{ type: 'button', value: t('js.admin.modals.got_it'), ng: { click: 'close()' } } diff --git a/app/views/admin/enterprises/form/_business_address.html.haml b/app/views/admin/enterprises/form/_business_address.html.haml index f44f606442..6b93bd2a50 100644 --- a/app/views/admin/enterprises/form/_business_address.html.haml +++ b/app/views/admin/enterprises/form/_business_address.html.haml @@ -1,12 +1,14 @@ .row .three.columns.alpha = bf.label :company, t(".company_legal_name") + %i.text-big.icon-question-sign.help-modal{ template: 'admin/modals/business_address_info.html' } .eight.columns.omega = bf.text_field :company, { placeholder: t(".company_placeholder") } .row .three.columns.alpha = bf.label :address1, t('.address1') + %i.text-big.icon-question-sign.help-modal{ template: 'admin/modals/business_address_info.html' } .eight.columns.omega = bf.text_field :address1, { placeholder: t(".address1_placeholder") } .row @@ -37,6 +39,7 @@ .row .three.columns.alpha = bf.label :phone, t(".legal_phone_number") + %i.text-big.icon-question-sign.help-modal{ template: 'admin/modals/business_address_info.html' } .eight.columns.omega = bf.text_field :phone, { placeholder: t(".phone_placeholder") } diff --git a/config/locales/en.yml b/config/locales/en.yml index 7525ab822a..1a1efc1923 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -265,6 +265,7 @@ en: producers: 'Australian Producers' producers_join: Australian producers are now welcome to join the Open Food Network. #FIXME charges_sales_tax: Charges GST? + business_address: "Business Address" print_invoice: "Print Invoice" print_ticket: "Print Ticket" select_ticket_printer: "Select printer for tickets" @@ -2747,6 +2748,8 @@ See the %{link} to find out more about %{sitename}'s features and to start using title: "Uploading Terms and Conditions" message_1: "All your buyers will have to agree to them once at checkout. If you update the file, all your buyers will have to agree to them again at checkout." message_2: "For buyers with subscriptions, you need to email them the Terms and Conditions (or the changes to them) for now, nothing will notify them about these new Terms and Conditions." + business_address_info: + message: "Company Legal Name, Legal Address and Legal Phone number are used for businesses that invoice from a legal entity registered with different details to their public trading information. These details will ONLY be used on invoices. If these details are blank your public Name, Address and Phone Number will be used on invoices." panels: save: SAVE saved: SAVED From a7a45769d6f22674a0a338d846c1db652b8894ab Mon Sep 17 00:00:00 2001 From: Nihal Mohammed Date: Wed, 11 Aug 2021 15:18:18 +0530 Subject: [PATCH 16/36] Update enterprises_controller and schema --- app/controllers/admin/enterprises_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 25f192c540..c2a9460447 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -130,7 +130,6 @@ module Admin def build_resource enterprise = super enterprise.address ||= Spree::Address.new - enterprise.business_address ||= Spree::Address.new enterprise.address.country ||= DefaultCountry.country enterprise end From 496319b539bb1a4adf4d6f2948b834e9991b42d7 Mon Sep 17 00:00:00 2001 From: Nihal Mohammed Date: Mon, 23 Aug 2021 18:17:17 +0530 Subject: [PATCH 17/36] Reject changes to business_address if fields are empty --- app/models/enterprise.rb | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index b394f2bca7..56fa5826d1 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -60,7 +60,11 @@ class Enterprise < ApplicationRecord delegate :latitude, :longitude, :city, :state_name, to: :address accepts_nested_attributes_for :address - accepts_nested_attributes_for :business_address, allow_destroy: true +<<<<<<< HEAD + accepts_nested_attributes_for :business_address, :reject_if => :empty_field, allow_destroy: true +======= + accepts_nested_attributes_for :business_address, :reject_if => :business_address_empty?, allow_destroy: true +>>>>>>> 389cfdf10 (Redo destroy) accepts_nested_attributes_for :producer_properties, allow_destroy: true, reject_if: lambda { |pp| pp[:property_name].blank? @@ -212,6 +216,31 @@ class Enterprise < ApplicationRecord ", one, one, others) } +<<<<<<< HEAD + def empty_field(attributes) + exists = attributes['business_address_id'].present? + empty = attributes.slice(:address1, :city, :country, :phone, :zipcode).values.all?(&:blank?) + attributes.merge!({:_destroy => 1}) if exists and empty + return (!exists and empty) +======= + def business_address_empty?(attributes) + is_empty_attributes = + attributes[:company].blank? && + attributes[:address1].blank? && + attributes[:city].blank? && + attributes[:phone].blank? && + attributes[:zipcode].blank? + + if is_empty_attributes + if attributes[:id].present? + attributes.merge!({:_destroy => 1}) && false + else + true + end + end +>>>>>>> 389cfdf10 (Redo destroy) + end + # Force a distinct count to work around relation count issue https://github.com/rails/rails/issues/5554 def self.distinct_count count(distinct: true) From 90038ff25021d4802b209a654611d90e51f8fb01 Mon Sep 17 00:00:00 2001 From: Nihal Date: Fri, 27 Aug 2021 14:56:18 +0530 Subject: [PATCH 18/36] Add test coverage for business_address association in enterprise model --- spec/models/enterprise_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 98e920f0c5..94130fa444 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -23,6 +23,7 @@ describe Enterprise do it { is_expected.to have_many(:supplied_products) } it { is_expected.to have_many(:distributed_orders) } it { is_expected.to belong_to(:address) } + it { is_expected.to belong_to(:business_address) } it "destroys enterprise roles upon its own demise" do e = create(:enterprise) From c6219a47c39fa7e8946ce207125989ed6b10aafe Mon Sep 17 00:00:00 2001 From: "Nihal M. Kelanthodika" Date: Wed, 8 Sep 2021 13:38:14 +0530 Subject: [PATCH 19/36] Remove stray space --- app/services/permitted_attributes/business_address.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/services/permitted_attributes/business_address.rb b/app/services/permitted_attributes/business_address.rb index 52a4bccb75..24348a353b 100644 --- a/app/services/permitted_attributes/business_address.rb +++ b/app/services/permitted_attributes/business_address.rb @@ -11,4 +11,3 @@ module PermittedAttributes end end end - \ No newline at end of file From c120965a8d797fc1c19f599e2b3a25a6b9b1d62d Mon Sep 17 00:00:00 2001 From: Nihal Date: Mon, 13 Sep 2021 18:30:52 +0530 Subject: [PATCH 20/36] Fix translations --- .../templates/admin/modals/business_address_info.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/templates/admin/modals/business_address_info.html.haml b/app/assets/javascripts/templates/admin/modals/business_address_info.html.haml index abb0eb148f..9a0945e90c 100644 --- a/app/assets/javascripts/templates/admin/modals/business_address_info.html.haml +++ b/app/assets/javascripts/templates/admin/modals/business_address_info.html.haml @@ -4,4 +4,4 @@ {{ 'js.admin.modals.business_address_info.message' | t }} .text-center - %input.button.red.icon-plus{ type: 'button', value: t('js.admin.modals.got_it'), ng: { click: 'close()' } } + %input.button.red.icon-plus{ type: 'button', value: '{{ "js.admin.modals.got_it" | t }}', ng: { click: 'close()' } } From 372326debcaccc4c8be30f37e89f425465c4c7b6 Mon Sep 17 00:00:00 2001 From: Nihal Date: Fri, 17 Sep 2021 16:13:07 +0530 Subject: [PATCH 21/36] Updated validation to include phone and edit address_spec to requires phone --- app/models/enterprise.rb | 16 ++-------------- app/models/spree/address.rb | 5 +++-- spec/models/spree/address_spec.rb | 4 ++-- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 56fa5826d1..c7fb01f8bd 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -5,7 +5,6 @@ require 'spree/core/s3_support' class Enterprise < ApplicationRecord SELLS = %w(unspecified none own any).freeze ENTERPRISE_SEARCH_RADIUS = 100 - searchable_attributes :sells, :is_primary_producer searchable_associations :properties searchable_scopes :is_primary_producer, :is_distributor, :is_hub, :activated, :visible, @@ -60,11 +59,7 @@ class Enterprise < ApplicationRecord delegate :latitude, :longitude, :city, :state_name, to: :address accepts_nested_attributes_for :address -<<<<<<< HEAD - accepts_nested_attributes_for :business_address, :reject_if => :empty_field, allow_destroy: true -======= accepts_nested_attributes_for :business_address, :reject_if => :business_address_empty?, allow_destroy: true ->>>>>>> 389cfdf10 (Redo destroy) accepts_nested_attributes_for :producer_properties, allow_destroy: true, reject_if: lambda { |pp| pp[:property_name].blank? @@ -216,13 +211,6 @@ class Enterprise < ApplicationRecord ", one, one, others) } -<<<<<<< HEAD - def empty_field(attributes) - exists = attributes['business_address_id'].present? - empty = attributes.slice(:address1, :city, :country, :phone, :zipcode).values.all?(&:blank?) - attributes.merge!({:_destroy => 1}) if exists and empty - return (!exists and empty) -======= def business_address_empty?(attributes) is_empty_attributes = attributes[:company].blank? && @@ -238,7 +226,6 @@ class Enterprise < ApplicationRecord true end end ->>>>>>> 389cfdf10 (Redo destroy) end # Force a distinct count to work around relation count issue https://github.com/rails/rails/issues/5554 @@ -445,7 +432,8 @@ class Enterprise < ApplicationRecord end def set_unused_address_fields - address.firstname = address.lastname = address.phone = 'unused' if address.present? + address.firstname = address.lastname = address.phone = address.company = 'unused' if address.present? + business_address.first_name = business_address.last_name = 'unused' if business_address.present? end def ensure_owner_is_manager diff --git a/app/models/spree/address.rb b/app/models/spree/address.rb index d418cdd699..f39976e8dd 100644 --- a/app/models/spree/address.rb +++ b/app/models/spree/address.rb @@ -14,8 +14,9 @@ module Spree has_many :shipments validates :address1, :city, :country, presence: true - validates :firstname, :lastname, presence: true, unless: -> { :company.present? } - validates :company, presence: true, unless: -> { :firstname.present? || :lastname.present? } + validates :company, presence: true, unless: -> { first_name.blank? || last_name.blank?} + validates :firstname, :lastname, presence: true, unless: -> { company.present? } + validates :phone, presence: true, if: -> { company = 'unused' } validates :zipcode, presence: true, if: :require_zipcode? validate :state_validate diff --git a/spec/models/spree/address_spec.rb b/spec/models/spree/address_spec.rb index cf3987ebba..f0f838ddcd 100644 --- a/spec/models/spree/address_spec.rb +++ b/spec/models/spree/address_spec.rb @@ -110,10 +110,10 @@ describe Spree::Address do expect(address).to be_valid end - it "does not require phone" do + it "requires phone" do address.phone = "" address.valid? - expect(address.errors[:phone]).to be_empty + expect(address.errors[:phone].first).to eq "can't be blank" end it "requires zipcode" do From 5f1a326a058c92bc85a30514ec3dbbb971bfa0cc Mon Sep 17 00:00:00 2001 From: Nihal Date: Mon, 20 Sep 2021 14:37:03 +0530 Subject: [PATCH 22/36] Add before_validation callback to set unused addressed fields in customer, order, user, subscription, enterprise_group --- app/models/customer.rb | 6 ++++++ app/models/enterprise_group.rb | 2 +- app/models/spree/order.rb | 6 ++++++ app/models/spree/user.rb | 8 +++++++- app/models/subscription.rb | 7 +++++++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/models/customer.rb b/app/models/customer.rb index 7f23c60589..362be4d54a 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -20,6 +20,7 @@ class Customer < ApplicationRecord before_validation :downcase_email before_validation :empty_code + before_validation :set_unused_address_fields validates :code, uniqueness: { scope: :enterprise_id, allow_nil: true } validates :email, presence: true, 'valid_email_2/email': true, @@ -52,4 +53,9 @@ class Customer < ApplicationRecord errors.add(:base, I18n.t('admin.customers.destroy.has_associated_orders')) throw :abort end + + def set_unused_address_fields + ship_address.company = 'Company' if ship_address.present? + bill_address.company = 'Company' if bill_address.present? + end end diff --git a/app/models/enterprise_group.rb b/app/models/enterprise_group.rb index 7d100ea2c6..1c3b435d9e 100644 --- a/app/models/enterprise_group.rb +++ b/app/models/enterprise_group.rb @@ -54,7 +54,7 @@ class EnterpriseGroup < ApplicationRecord } def set_unused_address_fields - address.firstname = address.lastname = I18n.t(:unused) + address.firstname = address.lastname = address.company = I18n.t(:unused) end def set_undefined_address_fields diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index e7af441b7e..41dbe30bd0 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -86,6 +86,7 @@ module Spree before_validation :clone_billing_address, if: :use_billing? before_validation :associate_customer, unless: :customer_id? before_validation :ensure_customer, unless: :customer_is_valid? + before_validation :set_unused_address_fields before_create :link_by_email after_create :create_tax_charge! @@ -611,6 +612,11 @@ module Spree private + def set_unused_address_fields + ship_address.company = 'Company' if ship_address.present? + bill_address.company = 'Company' if bill_address.present? + end + def fee_handler @fee_handler ||= OrderFeesHandler.new(self) end diff --git a/app/models/spree/user.rb b/app/models/spree/user.rb index ccd8975f6f..b8a9379772 100644 --- a/app/models/spree/user.rb +++ b/app/models/spree/user.rb @@ -20,7 +20,8 @@ module Spree before_validation :set_login before_destroy :check_completed_orders - + before_validation :set_unused_address_fields + roles_table_name = Role.table_name scope :admin, lambda { includes(:spree_roles).where("#{roles_table_name}.name" => "admin") } @@ -150,6 +151,11 @@ module Spree private + def set_unused_address_fields + ship_address.company = 'Company' if ship_address.present? + bill_address.company = 'Company' if bill_address.present? + end + def check_completed_orders raise DestroyWithOrdersError if orders.complete.present? end diff --git a/app/models/subscription.rb b/app/models/subscription.rb index f533b617f5..e4f3c63da1 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -27,6 +27,8 @@ class Subscription < ApplicationRecord accepts_nested_attributes_for :subscription_line_items, allow_destroy: true accepts_nested_attributes_for :bill_address, :ship_address + before_validation :set_unused_address_fields + scope :not_ended, -> { where('subscriptions.ends_at > (?) OR subscriptions.ends_at IS NULL', Time.zone.now) } @@ -75,6 +77,11 @@ class Subscription < ApplicationRecord private + def set_unused_address_fields + ship_address.company = 'Company' if ship_address.present? + bill_address.company = 'Company' if bill_address.present? + end + def pending? return true unless begins_at From 912b869407eb2e87ec9557e2f133c0c534889a55 Mon Sep 17 00:00:00 2001 From: Nihal Date: Wed, 22 Sep 2021 13:15:37 +0530 Subject: [PATCH 23/36] Re-order country/state selector --- .../admin/enterprises/form/_business_address.html.haml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/views/admin/enterprises/form/_business_address.html.haml b/app/views/admin/enterprises/form/_business_address.html.haml index 6b93bd2a50..39a9331d9a 100644 --- a/app/views/admin/enterprises/form/_business_address.html.haml +++ b/app/views/admin/enterprises/form/_business_address.html.haml @@ -27,14 +27,16 @@ = bf.text_field :zipcode, { placeholder: t(:postcode_placeholder) } .row .three.columns.alpha - = bf.label :state_id, t(:state) - \/ = bf.label :country_id, t(:country) + \/ + = bf.label :state_id, t(:state) %div{ "ng-controller": "countryCtrl", "ng-init": "address_type='business_address'" } .four.columns - %input.ofn-select2.fullwidth#enterprise_business_address_attributes_state_id{ name: 'enterprise[business_address_attributes][state_id]', type: 'number', data: 'countriesById[Enterprise.address.country_id].states', placeholder: t('admin.choose'), ng: { model: 'Enterprise.business_address.state_id' } } - .four.columns.omega + -# %input.ofn-select2.fullwidth#enterprise_business_address_attributes_state_id{ name: 'enterprise[business_address_attributes][state_id]', type: 'number', data: 'countriesById[Enterprise.address.country_id].states', placeholder: t('admin.choose'), ng: { model: 'Enterprise.business_address.state_id' } } %input.ofn-select2.fullwidth#enterprise_business_address_attributes_country_id{ name: 'enterprise[business_address_attributes][country_id]', type: 'number', data: 'countries', placeholder: t('admin.choose'), ng: { model: 'Enterprise.business_address.country_id' } } + .four.columns.omega + %input.ofn-select2.fullwidth#enterprise_business_address_attributes_state_id{ name: 'enterprise[business_address_attributes][state_id]', type: 'number', data: 'countriesById[Enterprise.address.country_id].states', placeholder: t('admin.choose'), ng: { model: 'Enterprise.business_address.state_id' } } + -# %input.ofn-select2.fullwidth#enterprise_business_address_attributes_country_id{ name: 'enterprise[business_address_attributes][country_id]', type: 'number', data: 'countries', placeholder: t('admin.choose'), ng: { model: 'Enterprise.business_address.country_id' } } .row .three.columns.alpha From f72f1823637f72be50e346a82c50012269bc07d5 Mon Sep 17 00:00:00 2001 From: Nihal Date: Wed, 22 Sep 2021 13:30:28 +0530 Subject: [PATCH 24/36] Redo business_address_empty? method --- app/models/enterprise.rb | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index c7fb01f8bd..1d2af37a91 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -59,7 +59,7 @@ class Enterprise < ApplicationRecord delegate :latitude, :longitude, :city, :state_name, to: :address accepts_nested_attributes_for :address - accepts_nested_attributes_for :business_address, :reject_if => :business_address_empty?, allow_destroy: true + accepts_nested_attributes_for :business_address, reject_if: :business_address_empty?, allow_destroy: true accepts_nested_attributes_for :producer_properties, allow_destroy: true, reject_if: lambda { |pp| pp[:property_name].blank? @@ -212,20 +212,10 @@ class Enterprise < ApplicationRecord } def business_address_empty?(attributes) - is_empty_attributes = - attributes[:company].blank? && - attributes[:address1].blank? && - attributes[:city].blank? && - attributes[:phone].blank? && - attributes[:zipcode].blank? - - if is_empty_attributes - if attributes[:id].present? - attributes.merge!({:_destroy => 1}) && false - else - true - end - end + attributes_exists = attributes['id'].present? + attributes_empty = attributes.slice(:company, :address1, :city, :phone, :zipcode).values.all?(&:blank?) + attributes.merge!(_destroy: 1) if attributes_exists and attributes_empty + !attributes_exists && attributes_empty end # Force a distinct count to work around relation count issue https://github.com/rails/rails/issues/5554 From 7eb0c6c33cdaed421671c983433bb01bbdc5cb1f Mon Sep 17 00:00:00 2001 From: Nihal Date: Wed, 22 Sep 2021 14:15:13 +0530 Subject: [PATCH 25/36] Add module to set unused ship, bill address fields --- app/models/concerns/set_unused_address_fields.rb | 14 ++++++++++++++ app/models/spree/order.rb | 8 ++------ app/models/spree/user.rb | 8 ++------ app/models/subscription.rb | 9 ++------- 4 files changed, 20 insertions(+), 19 deletions(-) create mode 100644 app/models/concerns/set_unused_address_fields.rb diff --git a/app/models/concerns/set_unused_address_fields.rb b/app/models/concerns/set_unused_address_fields.rb new file mode 100644 index 0000000000..1e07d40660 --- /dev/null +++ b/app/models/concerns/set_unused_address_fields.rb @@ -0,0 +1,14 @@ +require 'active_support/concern' + +module SetUnusedAddressFields + extend ActiveSupport::Concern + + included do + self.before_validation :set_unused_address_fields + end + + def set_unused_address_fields + ship_address.company = 'Company' if ship_address.present? + bill_address.company = 'Company' if bill_address.present? + end +end diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index 41dbe30bd0..c21b1ecbdd 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -10,6 +10,7 @@ module Spree include OrderShipment include Checkout include Balance + include SetUnusedAddressFields searchable_attributes :number, :state, :shipment_state, :payment_state, :distributor_id, :order_cycle_id, :email, :total @@ -86,7 +87,7 @@ module Spree before_validation :clone_billing_address, if: :use_billing? before_validation :associate_customer, unless: :customer_id? before_validation :ensure_customer, unless: :customer_is_valid? - before_validation :set_unused_address_fields + before_create :link_by_email after_create :create_tax_charge! @@ -612,11 +613,6 @@ module Spree private - def set_unused_address_fields - ship_address.company = 'Company' if ship_address.present? - bill_address.company = 'Company' if bill_address.present? - end - def fee_handler @fee_handler ||= OrderFeesHandler.new(self) end diff --git a/app/models/spree/user.rb b/app/models/spree/user.rb index b8a9379772..d30e993e8e 100644 --- a/app/models/spree/user.rb +++ b/app/models/spree/user.rb @@ -2,6 +2,8 @@ module Spree class User < ApplicationRecord + include SetUnusedAddressFields + searchable_attributes :email devise :database_authenticatable, :token_authenticatable, :registerable, :recoverable, @@ -20,7 +22,6 @@ module Spree before_validation :set_login before_destroy :check_completed_orders - before_validation :set_unused_address_fields roles_table_name = Role.table_name @@ -151,11 +152,6 @@ module Spree private - def set_unused_address_fields - ship_address.company = 'Company' if ship_address.present? - bill_address.company = 'Company' if bill_address.present? - end - def check_completed_orders raise DestroyWithOrdersError if orders.complete.present? end diff --git a/app/models/subscription.rb b/app/models/subscription.rb index e4f3c63da1..8fc4667fad 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class Subscription < ApplicationRecord + include SetUnusedAddressFields + ALLOWED_PAYMENT_METHOD_TYPES = ["Spree::PaymentMethod::Check", "Spree::Gateway::StripeConnect", "Spree::Gateway::StripeSCA"].freeze @@ -26,8 +28,6 @@ class Subscription < ApplicationRecord accepts_nested_attributes_for :subscription_line_items, allow_destroy: true accepts_nested_attributes_for :bill_address, :ship_address - - before_validation :set_unused_address_fields scope :not_ended, -> { where('subscriptions.ends_at > (?) OR subscriptions.ends_at IS NULL', Time.zone.now) @@ -77,11 +77,6 @@ class Subscription < ApplicationRecord private - def set_unused_address_fields - ship_address.company = 'Company' if ship_address.present? - bill_address.company = 'Company' if bill_address.present? - end - def pending? return true unless begins_at From f6e66de52b18a909aaf24050cdcef7b5f2f0196c Mon Sep 17 00:00:00 2001 From: Nihal Date: Wed, 22 Sep 2021 14:37:55 +0530 Subject: [PATCH 26/36] Update phone validation to simple validation --- app/models/spree/address.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/models/spree/address.rb b/app/models/spree/address.rb index f39976e8dd..cff38fab0e 100644 --- a/app/models/spree/address.rb +++ b/app/models/spree/address.rb @@ -13,10 +13,9 @@ module Spree has_one :enterprise, dependent: :restrict_with_exception has_many :shipments - validates :address1, :city, :country, presence: true + validates :address1, :city, :country, :phone, presence: true validates :company, presence: true, unless: -> { first_name.blank? || last_name.blank?} validates :firstname, :lastname, presence: true, unless: -> { company.present? } - validates :phone, presence: true, if: -> { company = 'unused' } validates :zipcode, presence: true, if: :require_zipcode? validate :state_validate From 49e93a6125e33067baba7930d8f0d7b9be64c31f Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Wed, 22 Sep 2021 10:31:16 +0200 Subject: [PATCH 27/36] Add StimulusJS controllers via webpacker for the admin --- app/views/spree/admin/shared/_head.html.haml | 2 ++ app/webpacker/packs/admin.js | 6 ++++++ 2 files changed, 8 insertions(+) create mode 100644 app/webpacker/packs/admin.js diff --git a/app/views/spree/admin/shared/_head.html.haml b/app/views/spree/admin/shared/_head.html.haml index e783e2f07e..becc6d0309 100644 --- a/app/views/spree/admin/shared/_head.html.haml +++ b/app/views/spree/admin/shared/_head.html.haml @@ -18,6 +18,8 @@ = render "spree/admin/shared/translations" = render "spree/admin/shared/routes" += javascript_pack_tag "admin", "data-turbo-track": "reload" + %script = raw "var AUTH_TOKEN = \"#{form_authenticity_token}\";" diff --git a/app/webpacker/packs/admin.js b/app/webpacker/packs/admin.js new file mode 100644 index 0000000000..38fb32259e --- /dev/null +++ b/app/webpacker/packs/admin.js @@ -0,0 +1,6 @@ +import { Application } from "stimulus" +import { definitionsFromContext } from "stimulus/webpack-helpers" + +const application = Application.start() +const context = require.context("controllers", true, /.js$/) +application.load(definitionsFromContext(context)) From 786b198f4d41fd97e940d6a215fd789f4460c018 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Wed, 22 Sep 2021 10:31:53 +0200 Subject: [PATCH 28/36] Create an updateinput controller - that update the targets input value to the value stored in data attribute - Add tests --- .../controllers/updateinput_controller.js | 13 ++++++++ .../stimulus/update_controller_test.js | 30 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 app/webpacker/controllers/updateinput_controller.js create mode 100644 spec/javascripts/stimulus/update_controller_test.js diff --git a/app/webpacker/controllers/updateinput_controller.js b/app/webpacker/controllers/updateinput_controller.js new file mode 100644 index 0000000000..aa72ae2086 --- /dev/null +++ b/app/webpacker/controllers/updateinput_controller.js @@ -0,0 +1,13 @@ +import { Controller } from "stimulus"; + +export default class extends Controller { + static targets = ["input"]; + + update(event) { + const value = event.currentTarget.dataset.updateinputValue; + + this.inputTargets.forEach((t) => { + t.value = value; + }); + } +} diff --git a/spec/javascripts/stimulus/update_controller_test.js b/spec/javascripts/stimulus/update_controller_test.js new file mode 100644 index 0000000000..33c85645c7 --- /dev/null +++ b/spec/javascripts/stimulus/update_controller_test.js @@ -0,0 +1,30 @@ +/** + * @jest-environment jsdom + */ + +import { Application } from "stimulus"; +import updateinput_controller from "../../../app/webpacker/controllers/updateinput_controller"; + +describe("updateInput controller", () => { + describe("#update", () => { + beforeEach(() => { + document.body.innerHTML = `
+ +
+ `; + + const application = Application.start(); + application.register("updateinput", updateinput_controller); + }); + + it("update the input value", () => { + const submit = document.getElementById("submit"); + const input = document.getElementById("input"); + expect(input.value).toBe("false"); + + submit.click(); + + expect(input.value).toBe("true"); + }); + }); +}); From 802c5c8c941b425bf6f9a1435dc2e4ac130c573e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Wed, 22 Sep 2021 10:32:10 +0200 Subject: [PATCH 29/36] Create a secondary form button --- app/assets/stylesheets/admin/disabled.scss | 6 ++++++ app/assets/stylesheets/admin/shared/forms.scss | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/app/assets/stylesheets/admin/disabled.scss b/app/assets/stylesheets/admin/disabled.scss index d7c7805036..b454754f2a 100644 --- a/app/assets/stylesheets/admin/disabled.scss +++ b/app/assets/stylesheets/admin/disabled.scss @@ -10,6 +10,12 @@ input[type='button'], input[type='submit'] { background-color: $disabled-background; color: #ffffff; } + + &.secondary:disabled { + background-color: #ebf3fb; + border: 1px solid #ebf3fb; + color: #AFCFEF; + } } .select2-container-disabled { diff --git a/app/assets/stylesheets/admin/shared/forms.scss b/app/assets/stylesheets/admin/shared/forms.scss index d034595fd3..8f4ee24dde 100644 --- a/app/assets/stylesheets/admin/shared/forms.scss +++ b/app/assets/stylesheets/admin/shared/forms.scss @@ -85,6 +85,20 @@ button, .button { width: 100%; text-align: center; } + + &.secondary { + background-color: transparent; + border: 1px solid $color-btn-bg; + color: $color-btn-bg; + + &:hover, &:active, &:focus { + background-color: #ebf3fb; + } + + &:active:focus { + box-shadow: none; + } + } } span.info { From 9b6cc187b6b0672a1c9c3328c55e700aa8ae84b7 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Wed, 22 Sep 2021 10:32:36 +0200 Subject: [PATCH 30/36] Remove clear form checkbox (used via _destroy) --- app/views/admin/enterprises/form/_business_address.html.haml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/views/admin/enterprises/form/_business_address.html.haml b/app/views/admin/enterprises/form/_business_address.html.haml index 39a9331d9a..cd7ed33ee0 100644 --- a/app/views/admin/enterprises/form/_business_address.html.haml +++ b/app/views/admin/enterprises/form/_business_address.html.haml @@ -45,8 +45,3 @@ .eight.columns.omega = bf.text_field :phone, { placeholder: t(".phone_placeholder") } -.row - .three.columns.alpha - = bf.label :clear - .eight.columns.omega - = bf.check_box :_destroy From aa5831872364112a6d819f5c636f3b0b28907d1a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Wed, 22 Sep 2021 10:34:22 +0200 Subject: [PATCH 31/36] Create a Reset form button that destroy the form itself - Thanks to the input hidden field. Its value is false, but when clicking on Reset form, this value changes to 'true' (and then the form is cleared) --- app/views/admin/enterprises/form/_business_details.html.haml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/views/admin/enterprises/form/_business_details.html.haml b/app/views/admin/enterprises/form/_business_details.html.haml index 6e69312917..0ad67fb451 100644 --- a/app/views/admin/enterprises/form/_business_details.html.haml +++ b/app/views/admin/enterprises/form/_business_details.html.haml @@ -53,3 +53,7 @@ %fieldset.alpha.no-border-bottom %legend= t('business_address') = render 'admin/enterprises/form/business_address', bf: bf + + .row{"data-controller": "updateinput"} + = bf.hidden_field :_destroy, {"data-updateinput-target": "input"} + = f.submit "Reset form", {class: 'secondary', "data-action": "click->updateinput#update", "data-updateinput-value": "true"} From 06344ed7c41223c7a9df3bea1a6cca7ab3b9c197 Mon Sep 17 00:00:00 2001 From: "Nihal M. Kelanthodika" Date: Fri, 1 Oct 2021 10:57:13 +0530 Subject: [PATCH 32/36] Remove comments --- app/views/admin/enterprises/form/_business_address.html.haml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/admin/enterprises/form/_business_address.html.haml b/app/views/admin/enterprises/form/_business_address.html.haml index cd7ed33ee0..be99ce6cfd 100644 --- a/app/views/admin/enterprises/form/_business_address.html.haml +++ b/app/views/admin/enterprises/form/_business_address.html.haml @@ -32,11 +32,10 @@ = bf.label :state_id, t(:state) %div{ "ng-controller": "countryCtrl", "ng-init": "address_type='business_address'" } .four.columns - -# %input.ofn-select2.fullwidth#enterprise_business_address_attributes_state_id{ name: 'enterprise[business_address_attributes][state_id]', type: 'number', data: 'countriesById[Enterprise.address.country_id].states', placeholder: t('admin.choose'), ng: { model: 'Enterprise.business_address.state_id' } } %input.ofn-select2.fullwidth#enterprise_business_address_attributes_country_id{ name: 'enterprise[business_address_attributes][country_id]', type: 'number', data: 'countries', placeholder: t('admin.choose'), ng: { model: 'Enterprise.business_address.country_id' } } .four.columns.omega %input.ofn-select2.fullwidth#enterprise_business_address_attributes_state_id{ name: 'enterprise[business_address_attributes][state_id]', type: 'number', data: 'countriesById[Enterprise.address.country_id].states', placeholder: t('admin.choose'), ng: { model: 'Enterprise.business_address.state_id' } } - -# %input.ofn-select2.fullwidth#enterprise_business_address_attributes_country_id{ name: 'enterprise[business_address_attributes][country_id]', type: 'number', data: 'countries', placeholder: t('admin.choose'), ng: { model: 'Enterprise.business_address.country_id' } } + .row .three.columns.alpha From b0dcf47481f38994d2656ebb1158e6250f8171de Mon Sep 17 00:00:00 2001 From: "Nihal M. Kelanthodika" Date: Fri, 1 Oct 2021 11:06:50 +0530 Subject: [PATCH 33/36] Add translation for "Reset Form" button --- app/views/admin/enterprises/form/_business_details.html.haml | 2 +- config/locales/en.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/admin/enterprises/form/_business_details.html.haml b/app/views/admin/enterprises/form/_business_details.html.haml index 0ad67fb451..b5a36a527e 100644 --- a/app/views/admin/enterprises/form/_business_details.html.haml +++ b/app/views/admin/enterprises/form/_business_details.html.haml @@ -56,4 +56,4 @@ .row{"data-controller": "updateinput"} = bf.hidden_field :_destroy, {"data-updateinput-target": "input"} - = f.submit "Reset form", {class: 'secondary', "data-action": "click->updateinput#update", "data-updateinput-value": "true"} + = f.submit t(".reset_form"), {class: 'secondary', "data-action": "click->updateinput#update", "data-updateinput-value": "true"} diff --git a/config/locales/en.yml b/config/locales/en.yml index 1a1efc1923..562227021a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -775,6 +775,7 @@ en: terms_and_conditions: "Terms and Conditions" remove_terms_and_conditions: "Remove File" uploaded_on: "uploaded on" + reset_form: "Reset Form" business_address: company_legal_name: Company Legal Name company_placeholder: Example Inc. From c63244246699a0ec4e5606a6092555ca1b891cd8 Mon Sep 17 00:00:00 2001 From: "Nihal M. Kelanthodika" Date: Wed, 6 Oct 2021 14:39:58 +0530 Subject: [PATCH 34/36] Update unused company field to 'unused' --- app/models/concerns/set_unused_address_fields.rb | 4 ++-- app/models/customer.rb | 8 ++------ spec/factories/address_factory.rb | 2 +- spec/models/spree/address_spec.rb | 2 +- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/models/concerns/set_unused_address_fields.rb b/app/models/concerns/set_unused_address_fields.rb index 1e07d40660..cb6f563f25 100644 --- a/app/models/concerns/set_unused_address_fields.rb +++ b/app/models/concerns/set_unused_address_fields.rb @@ -8,7 +8,7 @@ module SetUnusedAddressFields end def set_unused_address_fields - ship_address.company = 'Company' if ship_address.present? - bill_address.company = 'Company' if bill_address.present? + ship_address.company = 'unused' if ship_address.present? + bill_address.company = 'unused' if bill_address.present? end end diff --git a/app/models/customer.rb b/app/models/customer.rb index 362be4d54a..fc030bd1a1 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class Customer < ApplicationRecord + include SetUnusedAddressFields + acts_as_taggable searchable_attributes :name, :email, :code @@ -20,7 +22,6 @@ class Customer < ApplicationRecord before_validation :downcase_email before_validation :empty_code - before_validation :set_unused_address_fields validates :code, uniqueness: { scope: :enterprise_id, allow_nil: true } validates :email, presence: true, 'valid_email_2/email': true, @@ -53,9 +54,4 @@ class Customer < ApplicationRecord errors.add(:base, I18n.t('admin.customers.destroy.has_associated_orders')) throw :abort end - - def set_unused_address_fields - ship_address.company = 'Company' if ship_address.present? - bill_address.company = 'Company' if bill_address.present? - end end diff --git a/spec/factories/address_factory.rb b/spec/factories/address_factory.rb index 3a2dadf090..036318c6f3 100644 --- a/spec/factories/address_factory.rb +++ b/spec/factories/address_factory.rb @@ -4,7 +4,7 @@ FactoryBot.define do factory :address, aliases: [:bill_address, :ship_address], class: Spree::Address do firstname { 'John' } lastname { 'Doe' } - company { 'Company' } + company { 'unused' } address1 { '10 Lovely Street' } address2 { 'Northwest' } city { 'Herndon' } diff --git a/spec/models/spree/address_spec.rb b/spec/models/spree/address_spec.rb index f0f838ddcd..a1cb4fa8dd 100644 --- a/spec/models/spree/address_spec.rb +++ b/spec/models/spree/address_spec.rb @@ -14,7 +14,7 @@ describe Spree::Address do country: state.country, firstname: 'firstname', lastname: 'lastname', - company: 'company', + company: 'unused', phone: 'phone', state_id: state.id, state_name: state.name, From f7124ee32734a16f3cd90d0516428f3b0220aee9 Mon Sep 17 00:00:00 2001 From: "Nihal M. Kelanthodika" Date: Fri, 1 Oct 2021 14:14:01 +0530 Subject: [PATCH 35/36] Add business address form feature spec --- .../enterprises/business_address_form_spec.rb | 143 ++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 spec/features/admin/enterprises/business_address_form_spec.rb diff --git a/spec/features/admin/enterprises/business_address_form_spec.rb b/spec/features/admin/enterprises/business_address_form_spec.rb new file mode 100644 index 0000000000..38c9681db7 --- /dev/null +++ b/spec/features/admin/enterprises/business_address_form_spec.rb @@ -0,0 +1,143 @@ +require "spec_helper" + +describe "Business Address" do + include WebHelper + include AuthenticationHelper + + context "as an Enterprise user", js: true do + let(:enterprise_user) { create(:user, enterprise_limit: 1) } + let(:distributor) { create(:distributor_enterprise, name: "First Distributor") } + + before do + enterprise_user.enterprise_roles.build(enterprise: distributor).save! + + login_as enterprise_user + visit edit_admin_enterprise_path(distributor) + end + + describe "Business Address form" do + def go_to_business_details + within(".side_menu") do + click_link "Business Details" + end + end + + before do + go_to_business_details + end + + it 'adds a business address' do + fill_in 'enterprise_business_address_attributes_company', with: 'Company' + fill_in 'enterprise_business_address_attributes_address1', with: '35 Ballantyne St' + fill_in 'enterprise_business_address_attributes_city', with: 'Thornbury' + fill_in 'enterprise_business_address_attributes_zipcode', with: '3072' + select2_select 'Australia', from: 'enterprise_business_address_attributes_country_id' + select2_select 'Victoria', from: 'enterprise_business_address_attributes_state_id' + fill_in 'enterprise_business_address_attributes_phone', with: '0123456789' + + click_button "Update" + expect(page).to have_content("Enterprise \"First Distributor\" has been successfully updated!") + end + + it 'is missing company field' do + fill_in 'enterprise_business_address_attributes_address1', with: '35 Ballantyne St' + fill_in 'enterprise_business_address_attributes_city', with: 'Thornbury' + fill_in 'enterprise_business_address_attributes_zipcode', with: '3072' + select2_select 'Australia', from: 'enterprise_business_address_attributes_country_id' + select2_select 'Victoria', from: 'enterprise_business_address_attributes_state_id' + fill_in 'enterprise_business_address_attributes_phone', with: '0123456789' + + click_button "Update" + expect(page).to have_content("Business address company can't be blank") + end + + it 'is missing address field' do + fill_in 'enterprise_business_address_attributes_company', with: 'Company' + fill_in 'enterprise_business_address_attributes_city', with: 'Thornbury' + fill_in 'enterprise_business_address_attributes_zipcode', with: '3072' + select2_select 'Australia', from: 'enterprise_business_address_attributes_country_id' + select2_select 'Victoria', from: 'enterprise_business_address_attributes_state_id' + fill_in 'enterprise_business_address_attributes_phone', with: '0123456789' + + click_button "Update" + expect(page).to have_content("Business address address1 can't be blank") + end + + it 'is missing city field' do + fill_in 'enterprise_business_address_attributes_company', with: 'Company' + fill_in 'enterprise_business_address_attributes_address1', with: '35 Ballantyne St' + fill_in 'enterprise_business_address_attributes_zipcode', with: '3072' + select2_select 'Australia', from: 'enterprise_business_address_attributes_country_id' + select2_select 'Victoria', from: 'enterprise_business_address_attributes_state_id' + fill_in 'enterprise_business_address_attributes_phone', with: '0123456789' + + click_button "Update" + expect(page).to have_content("Business address city can't be blank") + end + + it 'is missing zipcode field' do + fill_in 'enterprise_business_address_attributes_company', with: 'Company' + fill_in 'enterprise_business_address_attributes_address1', with: '35 Ballantyne St' + fill_in 'enterprise_business_address_attributes_city', with: 'Thornbury' + select2_select 'Australia', from: 'enterprise_business_address_attributes_country_id' + select2_select 'Victoria', from: 'enterprise_business_address_attributes_state_id' + fill_in 'enterprise_business_address_attributes_phone', with: '0123456789' + + click_button "Update" + expect(page).to have_content("Business address zipcode can't be blank") + end + + it 'is missing phone field' do + fill_in 'enterprise_business_address_attributes_company', with: 'Company' + fill_in 'enterprise_business_address_attributes_address1', with: '35 Ballantyne St' + fill_in 'enterprise_business_address_attributes_city', with: 'Thornbury' + fill_in 'enterprise_business_address_attributes_zipcode', with: '3072' + select2_select 'Australia', from: 'enterprise_business_address_attributes_country_id' + select2_select 'Victoria', from: 'enterprise_business_address_attributes_state_id' + + click_button "Update" + expect(page).to have_content("Business address phone can't be blank") + end + + it 'destroys business address when Reset Form button is clicked' do + fill_in 'enterprise_business_address_attributes_company', with: 'Company' + fill_in 'enterprise_business_address_attributes_address1', with: '35 Ballantyne St' + fill_in 'enterprise_business_address_attributes_city', with: 'Thornbury' + fill_in 'enterprise_business_address_attributes_zipcode', with: '3072' + select2_select 'Australia', from: 'enterprise_business_address_attributes_country_id' + select2_select 'Victoria', from: 'enterprise_business_address_attributes_state_id' + fill_in 'enterprise_business_address_attributes_phone', with: '0123456789' + + click_button "Update" + + go_to_business_details + + click_button "Reset Form" + expect(page).to have_content("Enterprise \"First Distributor\" has been successfully updated!") + end + + it 'clears form when all fields are empty' do + fill_in 'enterprise_business_address_attributes_company', with: 'Company' + fill_in 'enterprise_business_address_attributes_address1', with: '35 Ballantyne St' + fill_in 'enterprise_business_address_attributes_city', with: 'Thornbury' + fill_in 'enterprise_business_address_attributes_zipcode', with: '3072' + select2_select 'Australia', from: 'enterprise_business_address_attributes_country_id' + select2_select 'Victoria', from: 'enterprise_business_address_attributes_state_id' + fill_in 'enterprise_business_address_attributes_phone', with: '0123456789' + + click_button "Update" + + go_to_business_details + + fill_in 'enterprise_business_address_attributes_company', with: '' + fill_in 'enterprise_business_address_attributes_address1', with: '' + fill_in 'enterprise_business_address_attributes_city', with: '' + fill_in 'enterprise_business_address_attributes_zipcode', with: '' + fill_in 'enterprise_business_address_attributes_phone', with: '' + + click_button "Update" + expect(page).to have_content("Enterprise \"First Distributor\" has been successfully updated!") + end + end + end +end From 82d9b041c9511d75dda8e3b12b568fc94bb392ac Mon Sep 17 00:00:00 2001 From: "Nihal M. Kelanthodika" Date: Wed, 6 Oct 2021 14:57:57 +0530 Subject: [PATCH 36/36] Remove unnecessary spaces and newlines --- app/models/spree/order.rb | 1 - app/models/spree/user.rb | 2 +- app/models/subscription.rb | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index c21b1ecbdd..e081e45559 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -88,7 +88,6 @@ module Spree before_validation :associate_customer, unless: :customer_id? before_validation :ensure_customer, unless: :customer_is_valid? - before_create :link_by_email after_create :create_tax_charge! diff --git a/app/models/spree/user.rb b/app/models/spree/user.rb index d30e993e8e..c25634777f 100644 --- a/app/models/spree/user.rb +++ b/app/models/spree/user.rb @@ -22,7 +22,7 @@ module Spree before_validation :set_login before_destroy :check_completed_orders - + roles_table_name = Role.table_name scope :admin, lambda { includes(:spree_roles).where("#{roles_table_name}.name" => "admin") } diff --git a/app/models/subscription.rb b/app/models/subscription.rb index 8fc4667fad..8c219b6c3a 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -28,7 +28,7 @@ class Subscription < ApplicationRecord accepts_nested_attributes_for :subscription_line_items, allow_destroy: true accepts_nested_attributes_for :bill_address, :ship_address - + scope :not_ended, -> { where('subscriptions.ends_at > (?) OR subscriptions.ends_at IS NULL', Time.zone.now) }