Module: SpreeCmCommissioner::OrderStateMachine
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/spree_cm_commissioner/order_state_machine.rb
Instance Method Summary collapse
-
#accepted_by(user) ⇒ Object
allow authorized user to accept all requested line items.
-
#can_accept_all? ⇒ Boolean
can_accepted? already use by ransack/visitor.rb.
- #can_alert_request_to_vendor? ⇒ Boolean
- #can_reject_all? ⇒ Boolean
-
#confirmation_delivered? ⇒ Boolean
overrided not to send email yet to user if order needs confirmation it will send after vendors accepted.
- #generate_bib_number ⇒ Object
- #need_confirmation? ⇒ Boolean
- #notify_order_complete_app_notification_to_user ⇒ Object
- #notify_order_complete_telegram_notification_to_user ⇒ Object
- #precalculate_conversion ⇒ Object
- #rejected_by(user) ⇒ Object
- #requested_state? ⇒ Boolean
- #send_order_accepted_app_notification_to_user ⇒ Object
- #send_order_accepted_telegram_alert_to_store ⇒ Object
- #send_order_complete_telegram_alert_to_store ⇒ Object
- #send_order_complete_telegram_alert_to_vendors ⇒ Object
- #send_order_rejected_app_notification_to_user ⇒ Object
- #send_order_rejected_telegram_alert_to_store ⇒ Object
- #send_order_request_telegram_confirmation_alert_to_vendor ⇒ Object
- #send_order_requested_app_notification_to_user ⇒ Object
- #send_order_requested_telegram_alert_to_store ⇒ Object
- #send_transaction_email_to_user ⇒ Object
- #user_has_email? ⇒ Boolean
Instance Method Details
#accepted_by(user) ⇒ Object
allow authorized user to accept all requested line items
111 112 113 114 115 116 117 118 119 |
# File 'app/models/concerns/spree_cm_commissioner/order_state_machine.rb', line 111 def accepted_by(user) transaction do accept! line_items.each do |line_item| line_item.accepted_by(user) end end end |
#can_accept_all? ⇒ Boolean
can_accepted? already use by ransack/visitor.rb
128 129 130 |
# File 'app/models/concerns/spree_cm_commissioner/order_state_machine.rb', line 128 def can_accept_all? approved? && requested? end |
#can_alert_request_to_vendor? ⇒ Boolean
136 137 138 |
# File 'app/models/concerns/spree_cm_commissioner/order_state_machine.rb', line 136 def can_alert_request_to_vendor? !accepted? && approved? && need_confirmation? end |
#can_reject_all? ⇒ Boolean
132 133 134 |
# File 'app/models/concerns/spree_cm_commissioner/order_state_machine.rb', line 132 def can_reject_all? approved? && requested? end |
#confirmation_delivered? ⇒ Boolean
overrided not to send email yet to user if order needs confirmation it will send after vendors accepted.
123 124 125 |
# File 'app/models/concerns/spree_cm_commissioner/order_state_machine.rb', line 123 def confirmation_delivered? confirmation_delivered || need_confirmation? end |
#generate_bib_number ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/models/concerns/spree_cm_commissioner/order_state_machine.rb', line 70 def generate_bib_number line_items.find_each(&:generate_remaining_guests) line_items.with_bib_prefix.each do |line_item| line_item.guests.none_bib.each do |guest| guest.generate_bib next if guest.save guest.errors.each do |msg| errors.add(:guests, msg) end end end errors.empty? end |
#need_confirmation? ⇒ Boolean
144 145 146 |
# File 'app/models/concerns/spree_cm_commissioner/order_state_machine.rb', line 144 def need_confirmation? line_items.any?(&:need_confirmation) end |
#notify_order_complete_app_notification_to_user ⇒ Object
161 162 163 |
# File 'app/models/concerns/spree_cm_commissioner/order_state_machine.rb', line 161 def notify_order_complete_app_notification_to_user SpreeCmCommissioner::OrderCompleteNotificationSender.call(order: self) end |
#notify_order_complete_telegram_notification_to_user ⇒ Object
165 166 167 |
# File 'app/models/concerns/spree_cm_commissioner/order_state_machine.rb', line 165 def notify_order_complete_telegram_notification_to_user SpreeCmCommissioner::OrderCompleteTelegramSenderJob.perform_later(id) if user_id.present? end |
#precalculate_conversion ⇒ Object
64 65 66 67 68 |
# File 'app/models/concerns/spree_cm_commissioner/order_state_machine.rb', line 64 def precalculate_conversion line_items.each do |item| SpreeCmCommissioner::ConversionPreCalculatorJob.perform_later(item.product_id) end end |
#rejected_by(user) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'app/models/concerns/spree_cm_commissioner/order_state_machine.rb', line 87 def rejected_by(user) transaction do reject! line_items.each do |line_item| line_item.rejected_by(user) end end end |
#requested_state? ⇒ Boolean
140 141 142 |
# File 'app/models/concerns/spree_cm_commissioner/order_state_machine.rb', line 140 def requested_state? request_state == 'requested' end |
#send_order_accepted_app_notification_to_user ⇒ Object
173 174 175 |
# File 'app/models/concerns/spree_cm_commissioner/order_state_machine.rb', line 173 def send_order_accepted_app_notification_to_user SpreeCmCommissioner::OrderAcceptedNotificationSender.call(order: self) end |
#send_order_accepted_telegram_alert_to_store ⇒ Object
188 189 190 191 192 193 |
# File 'app/models/concerns/spree_cm_commissioner/order_state_machine.rb', line 188 def send_order_accepted_telegram_alert_to_store title = '✅ --- [ORDER ACCEPTED BY VENDOR] ---' chat_id = store.preferred_telegram_order_request_alert_chat_id factory = OrderTelegramMessageFactory.new(title: title, order: self) TelegramNotificationSenderJob.perform_later(chat_id: chat_id, message: factory., parse_mode: factory.parse_mode) end |
#send_order_complete_telegram_alert_to_store ⇒ Object
202 203 204 205 206 207 |
# File 'app/models/concerns/spree_cm_commissioner/order_state_machine.rb', line 202 def send_order_complete_telegram_alert_to_store title = '🎫 --- [NEW ORDER] ---' chat_id = store.preferred_telegram_order_alert_chat_id factory = OrderTelegramMessageFactory.new(title: title, order: self) TelegramNotificationSenderJob.perform_later(chat_id: chat_id, message: factory., parse_mode: factory.parse_mode) end |
#send_order_complete_telegram_alert_to_vendors ⇒ Object
150 151 152 153 154 155 156 157 158 159 |
# File 'app/models/concerns/spree_cm_commissioner/order_state_machine.rb', line 150 def send_order_complete_telegram_alert_to_vendors vendor_list.each do |vendor| title = '🎫 --- [NEW ORDER FROM BOOKME+] ---' chat_id = vendor.preferred_telegram_chat_id if chat_id.present? factory = OrderTelegramMessageFactory.new(title: title, order: self, vendor: vendor) TelegramNotificationSenderJob.perform_later(chat_id: chat_id, message: factory., parse_mode: factory.parse_mode) end end end |
#send_order_rejected_app_notification_to_user ⇒ Object
177 178 179 |
# File 'app/models/concerns/spree_cm_commissioner/order_state_machine.rb', line 177 def send_order_rejected_app_notification_to_user SpreeCmCommissioner::OrderRejectedNotificationSender.call(order: self) end |
#send_order_rejected_telegram_alert_to_store ⇒ Object
195 196 197 198 199 200 |
# File 'app/models/concerns/spree_cm_commissioner/order_state_machine.rb', line 195 def send_order_rejected_telegram_alert_to_store title = '❌ --- [ORDER REJECTED BY VENDOR] ---' chat_id = store.preferred_telegram_order_request_alert_chat_id factory = OrderTelegramMessageFactory.new(title: title, order: self) TelegramNotificationSenderJob.perform_later(chat_id: chat_id, message: factory., parse_mode: factory.parse_mode) end |
#send_order_request_telegram_confirmation_alert_to_vendor ⇒ Object
148 |
# File 'app/models/concerns/spree_cm_commissioner/order_state_machine.rb', line 148 def send_order_request_telegram_confirmation_alert_to_vendor; end |
#send_order_requested_app_notification_to_user ⇒ Object
169 170 171 |
# File 'app/models/concerns/spree_cm_commissioner/order_state_machine.rb', line 169 def send_order_requested_app_notification_to_user SpreeCmCommissioner::OrderRequestedNotificationSender.call(order: self) end |
#send_order_requested_telegram_alert_to_store ⇒ Object
181 182 183 184 185 186 |
# File 'app/models/concerns/spree_cm_commissioner/order_state_machine.rb', line 181 def send_order_requested_telegram_alert_to_store title = '🔔 --- [NEW REQUESTED BY USER] ---' chat_id = store.preferred_telegram_order_request_alert_chat_id factory = OrderTelegramMessageFactory.new(title: title, order: self) TelegramNotificationSenderJob.perform_later(chat_id: chat_id, message: factory., parse_mode: factory.parse_mode) end |
#send_transaction_email_to_user ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'app/models/concerns/spree_cm_commissioner/order_state_machine.rb', line 97 def send_transaction_email_to_user line_items.each do |line_item| next if line_item.event.nil? event_id = line_item.event.parent_id SpreeCmCommissioner::EventTransactionalMailer.send_to_participant(event_id, user.id).deliver_later end end |
#user_has_email? ⇒ Boolean
106 107 108 |
# File 'app/models/concerns/spree_cm_commissioner/order_state_machine.rb', line 106 def user_has_email? user.email.present? end |