mirror of
https://github.com/rickbarrette/redmine_qbo_calendar.git
synced 2026-10-03 20:40:43 -04:00
Refactor appointment model and views to use a single date field; update tooltip and calendar display for improved functionality
This commit is contained in:
1 parent
88a40b356c
commit
86533981bc
8 files changed
+66
-76
No files matched your search
@@ -17,8 +17,7 @@ class CustomerAppointment < ActiveRecord::Base
|
||||
belongs_to :estimate, optional: true
|
||||
|
||||
validates :subject, presence: true
|
||||
validates :start_date, presence: true
|
||||
validate :date_order
|
||||
validates :date, presence: true
|
||||
|
||||
STATUSES = %w[
|
||||
Scheduled
|
||||
@@ -29,9 +28,15 @@ class CustomerAppointment < ActiveRecord::Base
|
||||
Cancelled
|
||||
]
|
||||
|
||||
# Cast datetime to Date for Redmine Calendar compatibility
|
||||
def start_date
|
||||
date&.to_date
|
||||
end
|
||||
|
||||
def due_date
|
||||
return end_date&.to_date if end_date.present?
|
||||
return start_date&.to_date
|
||||
return nil unless date
|
||||
# Accounts for multi-day duration spanning across dates
|
||||
start_date + ([duration.to_i, 1].max - 1).days
|
||||
end
|
||||
|
||||
def self.visible(user)
|
||||
@@ -40,15 +45,6 @@ class CustomerAppointment < ActiveRecord::Base
|
||||
|
||||
private
|
||||
|
||||
def date_order
|
||||
return if end_date.blank?
|
||||
return if start_date.blank?
|
||||
|
||||
if end_date < start_date
|
||||
errors.add( :end_date, "cannot be before start date")
|
||||
end
|
||||
end
|
||||
|
||||
def log(msg)
|
||||
Rails.logger.info "[Event] #{msg}"
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user