mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-30 19:52:20 +01:00
(feat) add delivered state to order
This commit is contained in:
parent
8769244a33
commit
96a0f10747
@ -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}
|
||||
|
@ -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
|
||||
|
@ -1,9 +1,9 @@
|
||||
# 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
|
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
|
||||
|
@ -46,7 +46,8 @@ 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'
|
||||
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))
|
||||
|
@ -2055,6 +2055,7 @@ en:
|
||||
canceled: "Canceled"
|
||||
ready: "Ready"
|
||||
refunded: "Refunded"
|
||||
delivered: "Delivered"
|
||||
sort:
|
||||
newest: "Newest first"
|
||||
oldest: "Oldest first"
|
||||
|
@ -572,6 +572,7 @@ en:
|
||||
canceled: "Canceled"
|
||||
ready: "Ready"
|
||||
refunded: "Refunded"
|
||||
delivered: "Delivered"
|
||||
show_order:
|
||||
back_to_list: "Back to list"
|
||||
see_invoice: "See invoice"
|
||||
@ -597,6 +598,7 @@ en:
|
||||
canceled: "Canceled"
|
||||
ready: "Ready"
|
||||
refunded: "Refunded"
|
||||
delivered: "Delivered"
|
||||
payment:
|
||||
by_wallet: "by wallet"
|
||||
settlement_by_debit_card: "Settlement by debit card"
|
||||
@ -614,6 +616,7 @@ en:
|
||||
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 ?"
|
||||
@ -621,6 +624,8 @@ en:
|
||||
confirm_order_ready: "This order is ready ?"
|
||||
order_ready_note: 'Leave your message'
|
||||
order_ready_success: "Order is ready"
|
||||
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"
|
||||
unsaved_form_alert:
|
||||
|
Loading…
x
Reference in New Issue
Block a user