Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class NextNumber < ActiveRecord::Base
- class << self
- VALID_CLASSES = [PurchaseOrder, SalesOrder]
- def get_next_number_for(object)
- throw Exception.new("Unsaved object not allowed") if object.new_record?
- throw Exception.new("Invalid object type for NextNumber#get_next_number_for") unless VALID_CLASSES.include?(object.class)
- begin
- next_number = NextNumber.find_by_sequential_type(object.class.to_s)
- next_number.sequential_id = object.id
- next_number.save
- next_number.lock_version
- rescue ActiveRecord::StaleObjectError => e
- retry
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment