Fix for #1826, ensure that adjustment states are initialized prior to validation

This commit is contained in:
Rob Harrington
2017-09-14 13:20:46 +10:00
parent 4c238748c6
commit d7de7d462f

View File

@@ -6,6 +6,8 @@ module Spree
has_one :metadata, class_name: 'AdjustmentMetadata'
belongs_to :tax_rate, foreign_key: 'originator_id', conditions: "spree_adjustments.originator_type = 'Spree::TaxRate'"
before_validation :initialize_state
scope :enterprise_fee, where(originator_type: 'EnterpriseFee')
scope :billable_period, where(source_type: 'BillablePeriod')
scope :admin, where(source_type: nil, originator_type: nil)
@@ -74,5 +76,15 @@ module Spree
result
end
private
# Required after Spree Upgrade Step 6, as existing adjustments did not have
# a state, and so failed validation. New adjustments are not affected.
def initialize_state
return unless state.nil?
# (static: true) only updates state when not already set
# use (static: :force) to force initialization
initialize_state_machines(static: true)
end
end
end