Files
assistant-storefront/app/models/working_hour.rb
Liang XJ 092fb2e083
Some checks failed
Lock Threads / action (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
Run Linux nightly installer / nightly (push) Has been cancelled
Initial commit: Add logistics and order_detail message types
- Add Logistics component with progress tracking
- Add OrderDetail component for order information
- Support data-driven steps and actions
- Add blue color scale to widget SCSS
- Fix node overflow and progress bar rendering issues
- Add English translations for dashboard components

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-26 11:16:56 +08:00

94 lines
2.8 KiB
Ruby

# == Schema Information
#
# Table name: working_hours
#
# id :bigint not null, primary key
# close_hour :integer
# close_minutes :integer
# closed_all_day :boolean default(FALSE)
# day_of_week :integer not null
# open_all_day :boolean default(FALSE)
# open_hour :integer
# open_minutes :integer
# created_at :datetime not null
# updated_at :datetime not null
# account_id :bigint
# inbox_id :bigint
#
# Indexes
#
# index_working_hours_on_account_id (account_id)
# index_working_hours_on_inbox_id (inbox_id)
#
class WorkingHour < ApplicationRecord
belongs_to :inbox
before_validation :ensure_open_all_day_hours
before_save :assign_account
validates :open_hour, presence: true, unless: :closed_all_day?
validates :open_minutes, presence: true, unless: :closed_all_day?
validates :close_hour, presence: true, unless: :closed_all_day?
validates :close_minutes, presence: true, unless: :closed_all_day?
validates :open_hour, inclusion: 0..23, unless: :closed_all_day?
validates :close_hour, inclusion: 0..23, unless: :closed_all_day?
validates :open_minutes, inclusion: 0..59, unless: :closed_all_day?
validates :close_minutes, inclusion: 0..59, unless: :closed_all_day?
validate :close_after_open, unless: :closed_all_day?
validate :open_all_day_and_closed_all_day
def self.today
# While getting the day of the week, consider the timezone as well. `first` would
# return the first working hour from the list of working hours available per week.
inbox = first.inbox
find_by(day_of_week: Time.zone.now.in_time_zone(inbox.timezone).to_date.wday)
end
def open_at?(time)
return false if closed_all_day?
open_time = Time.zone.now.in_time_zone(inbox.timezone).change({ hour: open_hour, min: open_minutes })
close_time = Time.zone.now.in_time_zone(inbox.timezone).change({ hour: close_hour, min: close_minutes })
time.between?(open_time, close_time)
end
def open_now?
inbox_time = Time.zone.now.in_time_zone(inbox.timezone)
open_at?(inbox_time)
end
def closed_now?
!open_now?
end
private
def assign_account
self.account_id = inbox.account_id
end
def close_after_open
return unless open_hour.hours + open_minutes.minutes >= close_hour.hours + close_minutes.minutes
errors.add(:close_hour, 'Closing time cannot be before opening time')
end
def ensure_open_all_day_hours
return unless open_all_day?
self.open_hour = 0
self.open_minutes = 0
self.close_hour = 23
self.close_minutes = 59
end
def open_all_day_and_closed_all_day
return unless open_all_day? && closed_all_day?
errors.add(:base, 'open_all_day and closed_all_day cannot be true at the same time')
end
end