1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-20 14:54:15 +01:00

(feat) refund an order by admin

This commit is contained in:
Du Peng 2022-09-16 18:31:20 +02:00
parent b635113843
commit cbed318c3f
9 changed files with 37 additions and 2 deletions

View File

@ -100,7 +100,7 @@ export const OrderActions: React.FC<OrderActionsProps> = ({ order, onSuccess, on
return (
<>
{buildOptions.length > 0 &&
{buildOptions().length > 0 &&
<Select
options={buildOptions()}
onChange={option => handleAction(option)}

View File

@ -71,6 +71,7 @@ class NotificationType
notify_admin_user_proof_of_identity_refusal
notify_user_order_is_ready
notify_user_order_is_canceled
notify_user_order_is_refunded
]
# deprecated:
# - notify_member_subscribed_plan_is_changed

View File

@ -0,0 +1,18 @@
# frozen_string_literal: true
# Provides methods for refund an order
class Orders::OrderRefundedService
def call(order, current_user)
raise ::UpdateOrderStateError if %w[cart payment_error refunded delivered].include?(order.state)
order.state = 'refunded'
ActiveRecord::Base.transaction do
activity = order.order_activities.create(activity_type: 'refunded', operator_profile_id: current_user.invoicing_profile.id)
order.save
NotificationCenter.call type: 'notify_user_order_is_refunded',
receiver: order.statistic_profile.user,
attached_object: activity
end
order.reload
end
end

View File

@ -48,6 +48,7 @@ class Orders::OrderService
return ::Orders::OrderReadyService.new.call(order, current_user, note) if state == 'ready'
return ::Orders::OrderCanceledService.new.call(order, current_user) if state == 'canceled'
return ::Orders::OrderDeliveredService.new.call(order, current_user) if state == 'delivered'
return ::Orders::OrderRefundedService.new.call(order, current_user) if state == 'refunded'
end
def in_stock?(order, stock_type = 'external')

View File

@ -0,0 +1,2 @@
json.title notification.notification_type
json.description t('.order_refunded', REFERENCE: notification.attached_object.order.reference)

View File

@ -0,0 +1,5 @@
<%= render 'notifications_mailer/shared/hello', recipient: @recipient %>
<p>
<%= t('.body.notify_user_order_is_refunded', REFERENCE: @attached_object.order.reference) %>
</p>

View File

@ -628,6 +628,8 @@ en:
order_delivered_success: "Order is delivered"
confirm_order_canceled: "Do you want to cancel this order ? You can modify product stock in stock manage."
order_canceled_success: "Order is canceled"
confirm_order_refunded: "Do you want to refund this order ? You can modify product stock in stock manage."
order_refunded_success: "Order is refunded"
unsaved_form_alert:
modal_title: "You have some unsaved changes"
confirmation_message: "If you leave this page, your changes will be lost. Are you sure you want to continue?"

View File

@ -411,6 +411,8 @@ en:
order_ready: "Your command %{REFERENCE} is ready"
notify_user_order_is_canceled:
order_canceled: "Your command %{REFERENCE} is canceled"
notify_user_order_is_refunded:
order_refunded: "Your command %{REFERENCE} is refunded"
#statistics tools for admins
statistics:
subscriptions: "Subscriptions"

View File

@ -381,4 +381,8 @@ en:
notify_user_order_is_canceled:
subject: "Your command is canceled"
body:
notify_user_order_is_canceled: "Your command %{REFERENCE} is canceled:"
notify_user_order_is_canceled: "Your command %{REFERENCE} is canceled."
notify_user_order_is_refunded:
subject: "Your command is refunded"
body:
notify_user_order_is_refunded: "Your command %{REFERENCE} is refunded:"