Class: Ecom::Core::OvertimeSheet
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Ecom::Core::OvertimeSheet
- Defined in:
- app/models/ecom/core/overtime_sheet.rb
Constant Summary collapse
- OPEN =
'Open'.freeze
- SUBMITTED =
'Submitted'.freeze
- APPROVED =
'Approved'.freeze
Class Method Summary collapse
-
.create_new(date) ⇒ Object
Overtime sheet should be created using the method below only.
- .open_exists? ⇒ Boolean
Class Method Details
.create_new(date) ⇒ Object
Overtime sheet should be created using the method below only. This is because we need to check if there is an open overtime already, and also that we have only one open overtime sheet at a time.
24 25 26 27 28 29 30 |
# File 'app/models/ecom/core/overtime_sheet.rb', line 24 def self.create_new(date) if OvertimeSheet.open_exists? raise 'There is already an open overtime sheet. It has to be submitted before creating a new one.' end OvertimeSheet.create(date: date, opened_at: Time.now, status: OPEN) end |
.open_exists? ⇒ Boolean
15 16 17 |
# File 'app/models/ecom/core/overtime_sheet.rb', line 15 def self.open_exists? OvertimeSheet.where(status: OPEN).exists? end |