Guest User

Untitled

a guest
Jun 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. class NextNumber < ActiveRecord::Base
  2.  
  3. class << self
  4. VALID_CLASSES = [PurchaseOrder, SalesOrder]
  5.  
  6. def get_next_number_for(object)
  7. throw Exception.new("Unsaved object not allowed") if object.new_record?
  8. throw Exception.new("Invalid object type for NextNumber#get_next_number_for") unless VALID_CLASSES.include?(object.class)
  9.  
  10. begin
  11. next_number = NextNumber.find_by_sequential_type(object.class.to_s)
  12. next_number.sequential_id = object.id
  13. next_number.save
  14. next_number.lock_version
  15. rescue ActiveRecord::StaleObjectError => e
  16. retry
  17. end
  18. end
  19. end
  20.  
  21. end
Add Comment
Please, Sign In to add comment