Skip to content

Commit

Permalink
close #749 alert request telegram to store
Browse files Browse the repository at this point in the history
  • Loading branch information
theachoem committed Oct 24, 2023
1 parent 87f7a2f commit 18de5dc
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 16 deletions.
7 changes: 7 additions & 0 deletions app/assets/images/backend-reject_all.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def self.prepended(base)
base.before_action :load_order, only: %i[
edit update cancel resume approve resend open_adjustments
close_adjustments cart channel set_channel
accept_all alert_request_to_vendor
accept_all reject_all alert_request_to_vendor
notifications fire_notification
]

Expand All @@ -21,6 +21,12 @@ def accept_all
redirect_back fallback_location: spree.edit_admin_order_url(@order)
end

def reject_all
@order.rejected_by(try_spree_current_user)
flash[:success] = Spree.t(:rejected)
redirect_back fallback_location: spree.edit_admin_order_url(@order)
end

def alert_request_to_vendor
@order.send_order_request_telegram_confirmation_alert_to_vendor

Expand Down Expand Up @@ -51,6 +57,10 @@ def initialize_notification_methods
@notification_methods = %w[
send_order_complete_telegram_alert_to_vendors
send_order_complete_telegram_alert_to_store

send_order_requested_telegram_alert_store
send_order_accepted_telegram_alert_to_store
send_order_rejected_telegram_alert_to_store
]
end
end
Expand Down
39 changes: 35 additions & 4 deletions app/models/concerns/spree_cm_commissioner/order_requestable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ module OrderRequestable
end
end

def rejected_by(user)
transaction do
reject!

line_items.each do |line_item|
line_item.rejected_by(user)
end
end
end

# allow authorized user to accept all requested line items
def accepted_by(user)
transaction do
Expand All @@ -58,7 +68,11 @@ def accepted_by(user)

# can_accepted? already use by ransack/visitor.rb
def can_accept_all?
approved? && !accepted? && need_confirmation?
approved? && requested?
end

def can_reject_all?
approved? && requested?
end

def can_alert_request_to_vendor?
Expand Down Expand Up @@ -100,9 +114,26 @@ def send_order_rejected_app_notification_to_user
SpreeCmCommissioner::OrderRejectedNotificationSender.call(order: self)
end

def send_order_requested_telegram_alert_store; end
def send_order_accepted_telegram_alert_to_store; end
def send_order_rejected_telegram_alert_to_store; end
def send_order_requested_telegram_alert_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.message, parse_mode: factory.parse_mode)
end

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.message, parse_mode: factory.parse_mode)
end

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.message, parse_mode: factory.parse_mode)
end

def send_order_complete_telegram_alert_to_store
title = '🎫 --- [NEW ORDER] ---'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module StorePreference

included do
preference :telegram_order_alert_chat_id, :string
preference :telegram_order_request_alert_chat_id, :string
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
<h5 class="card-title mb-0 h6">
<%= Spree.t(:order_line_items) %>
</h5>
<%= event_links(@order, [:accept_all]) %>
</div>
<div class="page-actions d-flex justify-content-center flex-wrap">
<%= event_links(@order, [:accept_all, :reject_all]) %>
</div>
</div>
2 changes: 1 addition & 1 deletion config/initializers/spree_permitted_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module PermittedAttributes
@@line_item_attributes += %i[from_date to_date]
@@user_attributes += %i[first_name last_name dob gender profile]
@@taxon_attributes += %i[category_icon custom_redirect_url to_date from_date kind]
@@store_attributes += %i[preferred_telegram_order_alert_chat_id]
@@store_attributes += %i[preferred_telegram_order_alert_chat_id preferred_telegram_order_request_alert_chat_id]

@@checkout_attributes += %i[phone_number country_code]
end
Expand Down
17 changes: 9 additions & 8 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
en:
account_checker:
verify:
already_exist: "%{login} already exist"
not_exist: "%{login} not exist"
already_exist: '%{login} already exist'
not_exist: '%{login} not exist'

sms:
to:
Expand Down Expand Up @@ -35,10 +35,10 @@ en:
hello: 'Hello world'

recaptcha:
request_failed: "Request failed"
invalid_code: "Invalid code"
score_not_qualify: "Score is not qualify"
action_not_matched: "Action is not matched"
request_failed: 'Request failed'
invalid_code: 'Invalid code'
score_not_qualify: 'Score is not qualify'
action_not_matched: 'Action is not matched'

taxon:
icon: Icon (Square)
Expand Down Expand Up @@ -144,6 +144,7 @@ en:
alert_request_to_vendor: 'Alert request to vendor'
alerted_to_vendor: 'Alerted to vendor Telegram'
accept_all: 'Accept all'
reject_all: 'Reject all'
sent: 'Sent'
send_failed_or_method_not_support: 'Send failed or method not support'
subscribe: 'Use Service'
Expand All @@ -163,8 +164,8 @@ en:
new_customer: 'New Customer'
listing_price: 'Listing Price'
length: 'Length'
preference: "Preference"
notification: "Notification"
preference: 'Preference'
notification: 'Notification'
promotion_rule_types:
fixed_date:
name: 'Fixed Date'
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
resources :orders, except: [:show] do
member do
put :accept_all
put :reject_all
put :alert_request_to_vendor

get :notifications
Expand Down

0 comments on commit 18de5dc

Please sign in to comment.