Commit 21ab10da by ivan Lan

Fix AASM_DSL about the disable InvalidTranslation

parent 75149d8b
......@@ -27,18 +27,18 @@ module Shotengai
# e.g.
# event :pay ---> :after_pay, after_commit_pay ...
#
@valid_keys.each do |callback|
# NOTE: QUESTION: add key :error would cancel all exception ?
(@valid_keys - [:error, :ensure]).each do |callback|
preset_methods << "#{callback}_#{@source.name}"
@options[callback] = Array(@options[callback]) << "#{callback}_#{@source.name}"
end
# ignore the method missing if it was in preset_methods
@source.class_eval("
def invoke_callbacks(code, record, args)
case code
when String, Symbol
return true if record.respond_to?(code, true).! && code.to_s.in?(#{preset_methods})
end
super(code, record, args)
rescue NoMethodError
code.to_s.in?(#{preset_methods}) ? true : raise
end
")
end
......
......@@ -33,21 +33,28 @@ module Shotengai
belongs_to :buyer, polymorphic: true, optional: true
default_scope { where.not(status: 'cart') }
scope :status_is, ->(status) { where(status.blank?.! && { status: status }) }
include AASM_DLC
aasm column: :status do
state :unpaid, initial: true
state :paid, :delivering, :received, :evaluated
{
pay: { from: :unpaid, to: :paid, after: [:fill_snapshot, :set_pay_time] },
cancel: { from: :unpaid, to: :canceled },
send_out: { from: :paid, to: :delivering, after: :set_delivery_time },
get_it: { from: :delivering, to: :received, after: :set_receipt_time },
evaluate: { from: :received, to: :evaluated },
# soft_delete: { from: : to: :evaluated },
}.each { |name, options|
event(name) { transitions options }
event :pay, after: [:fill_snapshot, :set_pay_time] {
transitions from: :unpaid, to: :paid
}
event :cancel {
transitions from: :unpaid, to: :canceled
}
event :send_out, after: :set_delivery_time {
transitions from: :paid, to: :delivering
}
event :get_it, after: :set_receipt_time {
transitions from: :delivering, to: :received
}
event :evaluate {
transitions from: :received, to: :evaluated
}
# event :soft_delete
end
def status_zh
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment