mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-01 12:24:28 +01:00
Merge branch 'product-store_order' into product-store
This commit is contained in:
commit
74bf28abec
@ -53,16 +53,16 @@ export const OrderActions: React.FC<OrderActionsProps> = ({ order, onSuccess, on
|
||||
let actions = [];
|
||||
switch (order.state) {
|
||||
case 'paid':
|
||||
actions = actions.concat(['in_progress', 'ready', 'canceled', 'refunded']);
|
||||
actions = actions.concat(['in_progress', 'ready', 'delivered', 'canceled', 'refunded']);
|
||||
break;
|
||||
case 'payment_failed':
|
||||
actions = actions.concat(['canceled']);
|
||||
break;
|
||||
case 'in_progress':
|
||||
actions = actions.concat(['ready', 'canceled', 'refunded']);
|
||||
actions = actions.concat(['ready', 'delivered', 'canceled', 'refunded']);
|
||||
break;
|
||||
case 'ready':
|
||||
actions = actions.concat(['canceled', 'refunded']);
|
||||
actions = actions.concat(['delivered', 'canceled', 'refunded']);
|
||||
break;
|
||||
case 'canceled':
|
||||
actions = actions.concat(['refunded']);
|
||||
@ -100,12 +100,14 @@ export const OrderActions: React.FC<OrderActionsProps> = ({ order, onSuccess, on
|
||||
|
||||
return (
|
||||
<>
|
||||
<Select
|
||||
options={buildOptions()}
|
||||
onChange={option => handleAction(option)}
|
||||
value={currentAction}
|
||||
styles={customStyles}
|
||||
/>
|
||||
{buildOptions().length > 0 &&
|
||||
<Select
|
||||
options={buildOptions()}
|
||||
onChange={option => handleAction(option)}
|
||||
value={currentAction}
|
||||
styles={customStyles}
|
||||
/>
|
||||
}
|
||||
<FabModal title={t('app.shared.store.order_actions.confirmation_required')}
|
||||
isOpen={modalIsOpen}
|
||||
toggleModal={closeModal}
|
||||
|
@ -34,7 +34,7 @@ export const OrdersDashboard: React.FC<OrdersDashboardProps> = ({ currentUser, o
|
||||
const [totalCount, setTotalCount] = useState<number>(0);
|
||||
|
||||
useEffect(() => {
|
||||
OrderAPI.index({}).then(res => {
|
||||
OrderAPI.index({ user_id: currentUser.id }).then(res => {
|
||||
setPageCount(res.total_pages);
|
||||
setTotalCount(res.total_count);
|
||||
setOrders(res.data);
|
||||
@ -67,7 +67,7 @@ export const OrdersDashboard: React.FC<OrdersDashboardProps> = ({ currentUser, o
|
||||
*/
|
||||
const handlePagination = (page: number) => {
|
||||
if (page !== currentPage) {
|
||||
OrderAPI.index({ page }).then(res => {
|
||||
OrderAPI.index({ user_id: currentUser.id, page }).then(res => {
|
||||
setCurrentPage(page);
|
||||
setOrders(res.data);
|
||||
setPageCount(res.total_pages);
|
||||
|
@ -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
|
||||
|
@ -10,7 +10,7 @@ class Order < PaymentDocument
|
||||
has_one :payment_gateway_object, as: :item
|
||||
has_many :order_activities, dependent: :destroy
|
||||
|
||||
ALL_STATES = %w[cart paid payment_failed refunded in_progress ready canceled return].freeze
|
||||
ALL_STATES = %w[cart paid payment_failed refunded in_progress ready canceled delivered].freeze
|
||||
enum state: ALL_STATES.zip(ALL_STATES).to_h
|
||||
|
||||
validates :token, :state, presence: true
|
||||
|
@ -4,7 +4,7 @@
|
||||
class OrderActivity < ApplicationRecord
|
||||
belongs_to :order
|
||||
|
||||
TYPES = %w[paid payment_failed refunded in_progress ready canceled return note].freeze
|
||||
TYPES = %w[paid payment_failed refunded in_progress ready canceled delivered note].freeze
|
||||
enum activity_type: TYPES.zip(TYPES).to_h
|
||||
|
||||
validates :activity_type, presence: true
|
||||
|
@ -43,12 +43,8 @@ class PDF::Invoice < Prawn::Document
|
||||
end
|
||||
text I18n.t('invoices.code', CODE: Setting.get('invoice_code-value')), leading: 3 if Setting.get('invoice_code-active')
|
||||
if invoice.main_item.object_type != WalletTransaction.name
|
||||
if invoice.is_a?(Avoir)
|
||||
text I18n.t('invoices.order_number', NUMBER: invoice.invoice.order_number), leading: 3
|
||||
else
|
||||
order_number = invoice.main_item.object_type == OrderItem.name ? invoice.main_item.object.order.reference : invoice.order_number
|
||||
text I18n.t('invoices.order_number', NUMBER: order_number), leading: 3
|
||||
end
|
||||
order_number = invoice.main_item.object_type == OrderItem.name ? invoice.main_item.object.order.reference : invoice.order_number
|
||||
text I18n.t('invoices.order_number', NUMBER: order_number), leading: 3
|
||||
end
|
||||
if invoice.is_a?(Avoir)
|
||||
text I18n.t('invoices.refund_invoice_issued_on_DATE', DATE: I18n.l(invoice.avoir_date.to_date))
|
||||
|
@ -1,16 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Provides methods for cancel an order
|
||||
class Orders::CancelOrderService
|
||||
class Orders::OrderCanceledService
|
||||
def call(order, current_user)
|
||||
raise ::UpdateOrderStateError if %w[cart payment_failed canceled refunded].include?(order.state)
|
||||
raise ::UpdateOrderStateError if %w[cart canceled refunded delivered].include?(order.state)
|
||||
|
||||
order.state = 'canceled'
|
||||
ActiveRecord::Base.transaction do
|
||||
activity = order.order_activities.create(activity_type: 'canceled', operator_profile_id: current_user.invoicing_profile.id)
|
||||
order.order_items.each do |item|
|
||||
ProductService.update_stock(item.orderable, 'external', 'cancelled', item.quantity, item.id)
|
||||
end
|
||||
order.save
|
||||
NotificationCenter.call type: 'notify_user_order_is_canceled',
|
||||
receiver: order.statistic_profile.user,
|
13
app/services/orders/order_delivered_service.rb
Normal file
13
app/services/orders/order_delivered_service.rb
Normal file
@ -0,0 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Provides methods for set order to delivered state
|
||||
class Orders::OrderDeliveredService
|
||||
def call(order, current_user)
|
||||
raise ::UpdateOrderStateError if %w[cart payment_failed canceled refunded delivered].include?(order.state)
|
||||
|
||||
order.state = 'delivered'
|
||||
order.order_activities.push(OrderActivity.new(activity_type: 'delivered', operator_profile_id: current_user.invoicing_profile.id))
|
||||
order.save
|
||||
order.reload
|
||||
end
|
||||
end
|
@ -3,7 +3,7 @@
|
||||
# Provides methods for set order to ready state
|
||||
class Orders::OrderReadyService
|
||||
def call(order, current_user, note = '')
|
||||
raise ::UpdateOrderStateError if %w[cart payment_failed ready canceled refunded].include?(order.state)
|
||||
raise ::UpdateOrderStateError if %w[cart payment_failed ready canceled refunded delivered].include?(order.state)
|
||||
|
||||
order.state = 'ready'
|
||||
ActiveRecord::Base.transaction do
|
||||
|
18
app/services/orders/order_refunded_service.rb
Normal file
18
app/services/orders/order_refunded_service.rb
Normal 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
|
@ -46,7 +46,9 @@ class Orders::OrderService
|
||||
def self.update_state(order, current_user, state, note = nil)
|
||||
return ::Orders::SetInProgressService.new.call(order, current_user) if state == 'in_progress'
|
||||
return ::Orders::OrderReadyService.new.call(order, current_user, note) if state == 'ready'
|
||||
return ::Orders::CancelOrderService.new.call(order, current_user) if state == 'canceled'
|
||||
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')
|
||||
|
@ -3,7 +3,7 @@
|
||||
# Provides methods for set in progress state to order
|
||||
class Orders::SetInProgressService
|
||||
def call(order, current_user)
|
||||
raise ::UpdateOrderStateError if %w[cart payment_failed in_progress canceled refunded].include?(order.state)
|
||||
raise ::UpdateOrderStateError if %w[cart payment_failed in_progress canceled refunded delivered].include?(order.state)
|
||||
|
||||
order.state = 'in_progress'
|
||||
order.order_activities.push(OrderActivity.new(activity_type: 'in_progress', operator_profile_id: current_user.invoicing_profile.id))
|
||||
|
@ -0,0 +1,2 @@
|
||||
json.title notification.notification_type
|
||||
json.description t('.order_refunded', REFERENCE: notification.attached_object.order.reference)
|
@ -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>
|
@ -2049,12 +2049,13 @@ en:
|
||||
filter_period: "By period"
|
||||
state:
|
||||
cart: 'Cart'
|
||||
in_progress: 'In progress'
|
||||
in_progress: 'Under preparation'
|
||||
paid: "Paid"
|
||||
payment_failed: "Payment error"
|
||||
canceled: "Canceled"
|
||||
ready: "Ready"
|
||||
refunded: "Refunded"
|
||||
delivered: "Delivered"
|
||||
sort:
|
||||
newest: "Newest first"
|
||||
oldest: "Oldest first"
|
||||
|
@ -566,12 +566,13 @@ en:
|
||||
client: "Client"
|
||||
state:
|
||||
cart: 'Cart'
|
||||
in_progress: 'In progress'
|
||||
in_progress: 'Under preparation'
|
||||
paid: "Paid"
|
||||
payment_failed: "Payment error"
|
||||
canceled: "Canceled"
|
||||
ready: "Ready"
|
||||
refunded: "Refunded"
|
||||
delivered: "Delivered"
|
||||
show_order:
|
||||
back_to_list: "Back to list"
|
||||
see_invoice: "See invoice"
|
||||
@ -591,12 +592,13 @@ en:
|
||||
cart_total: "Cart total"
|
||||
state:
|
||||
cart: 'Cart'
|
||||
in_progress: 'In progress'
|
||||
in_progress: 'Under preparation'
|
||||
paid: "Paid"
|
||||
payment_failed: "Payment error"
|
||||
canceled: "Canceled"
|
||||
ready: "Ready"
|
||||
refunded: "Refunded"
|
||||
delivered: "Delivered"
|
||||
payment:
|
||||
by_wallet: "by wallet"
|
||||
settlement_by_debit_card: "Settlement by debit card"
|
||||
@ -608,21 +610,26 @@ en:
|
||||
order_actions:
|
||||
state:
|
||||
cart: 'Cart'
|
||||
in_progress: 'In progress'
|
||||
in_progress: 'Under preparation'
|
||||
paid: "Paid"
|
||||
payment_failed: "Payment error"
|
||||
canceled: "Canceled"
|
||||
ready: "Ready"
|
||||
refunded: "Refunded"
|
||||
delivered: "Delivered"
|
||||
confirm: 'Confirm'
|
||||
confirmation_required: "Confirmation required"
|
||||
confirm_order_in_progress: "This order is in the process of being prepared ?"
|
||||
order_in_progress_success: "Order is under preparation"
|
||||
confirm_order_ready: "This order is ready ?"
|
||||
order_ready_note: ''
|
||||
order_ready_note: 'Leave your message'
|
||||
order_ready_success: "Order is ready"
|
||||
confirm_order_canceled: "Do you want to cancel this order ?"
|
||||
confirm_order_delivered: "This order is delivered ?"
|
||||
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?"
|
||||
|
@ -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"
|
||||
|
@ -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:"
|
||||
|
Loading…
Reference in New Issue
Block a user