1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-04 15:24:23 +01:00
fab-manager/app/services/orders/order_ready_service.rb

19 lines
719 B
Ruby
Raw Normal View History

2022-09-15 20:19:19 +02:00
# frozen_string_literal: true
# Provides methods for set order to ready state
class Orders::OrderReadyService
def call(order, current_user, note = '')
2022-09-16 17:54:41 +02:00
raise ::UpdateOrderStateError if %w[cart payment_failed ready canceled refunded delivered].include?(order.state)
2022-09-15 20:19:19 +02:00
order.state = 'ready'
ActiveRecord::Base.transaction do
activity = order.order_activities.create(activity_type: 'ready', operator_profile_id: current_user.invoicing_profile.id, note: note)
order.save
NotificationCenter.call type: 'notify_user_order_is_ready',
receiver: order.statistic_profile.user,
attached_object: activity
end
order.reload
end
end