mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Redo business_address_empty? method
This commit is contained in:
committed by
Nihal M. Kelanthodika
parent
912b869407
commit
f72f182363
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user