cats_core 1.4.22 → 1.4.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/cats/core/dispatch_authorizations_controller.rb +9 -1
- data/app/controllers/cats/core/dispatches_controller.rb +18 -2
- data/app/controllers/cats/core/lost_commodities_controller.rb +2 -2
- data/app/controllers/cats/core/receipt_authorizations_controller.rb +1 -2
- data/app/controllers/cats/core/receipts_controller.rb +19 -0
- data/app/models/cats/core/authorization.rb +33 -5
- data/app/models/cats/core/dispatch.rb +17 -8
- data/app/models/cats/core/lost_commodity.rb +2 -3
- data/app/models/cats/core/receipt.rb +10 -0
- data/app/models/cats/core/receipt_authorization.rb +4 -8
- data/app/models/cats/core/receipt_transaction.rb +1 -0
- data/app/serializers/cats/core/dispatch_authorization_serializer.rb +1 -1
- data/app/serializers/cats/core/dispatch_serializer.rb +1 -1
- data/app/serializers/cats/core/lost_commodity_serializer.rb +1 -1
- data/app/serializers/cats/core/receipt_authorization_serializer.rb +2 -2
- data/app/serializers/cats/core/receipt_serializer.rb +1 -2
- data/app/serializers/cats/core/receipt_transaction_serializer.rb +1 -5
- data/app/services/cats/core/authorization_service.rb +27 -0
- data/app/services/cats/core/dispatch_service.rb +22 -0
- data/config/routes.rb +11 -1
- data/db/migrate/20210718045516_create_cats_core_dispatches.rb +1 -0
- data/db/migrate/20210727074646_create_cats_core_receipt_authorizations.rb +3 -1
- data/db/migrate/20210727105834_create_cats_core_receipts.rb +15 -0
- data/db/migrate/20210728041505_create_cats_core_lost_commodities.rb +3 -4
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/dispatches.rb +16 -0
- data/spec/factories/cats/core/lost_commodities.rb +1 -2
- data/spec/factories/cats/core/receipt_authorizations.rb +13 -7
- data/spec/factories/cats/core/receipts.rb +8 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad828e18f9f084f3c2e0343af564a1f1cc4832e935c9eec068503f4293442b87
|
4
|
+
data.tar.gz: 8e0520ff2a6df1e2b4dd3f726a60aef02ef45915158c72c73ccbc74a9ae2786d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc1d8fc0861a5f8c46734cbbf029608625e8734d31361cf924834769166cc6d429f247b169b299616a5bedcf9dffd0cdc2ad4960e4caa502757a1a98cfd55865
|
7
|
+
data.tar.gz: '0850a3f89b88aea548765a78f46a8d4cac259642dc3f8c15837ab54c1d5c7911b311b8b55719972fe19312cf614d07042652376556a134ea2e20c8b1f7227fc1'
|
@@ -11,12 +11,20 @@ module Cats
|
|
11
11
|
|
12
12
|
def confirm
|
13
13
|
authorization = DispatchAuthorization.find(params[:id])
|
14
|
-
authorization.confirm
|
14
|
+
authorization = authorization.confirm
|
15
15
|
render json: { success: true, data: serialize(authorization) }
|
16
16
|
rescue StandardError => e
|
17
17
|
render json: { success: false, error: e.message }
|
18
18
|
end
|
19
19
|
|
20
|
+
def storekeeper_authorizations
|
21
|
+
storekeeper = User.find(params[:id])
|
22
|
+
stores = storekeeper.stores
|
23
|
+
authorizations = DispatchAuthorization.joins(:dispatch)
|
24
|
+
.where(store: stores, dispatch: { dispatch_status: Dispatch::APPROVED })
|
25
|
+
render json: { success: true, data: serialize(authorizations) }
|
26
|
+
end
|
27
|
+
|
20
28
|
private
|
21
29
|
|
22
30
|
def model_params
|
@@ -2,8 +2,8 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class DispatchesController < ApplicationController
|
4
4
|
include Common
|
5
|
-
|
6
|
-
before_action :set_service, only: %i[create_receipt_authorization approve start search confirm]
|
5
|
+
skip_before_action :authenticate, only: %i[start_with_pin]
|
6
|
+
before_action :set_service, only: %i[create_receipt_authorization approve start start_with_pin search confirm]
|
7
7
|
|
8
8
|
def index
|
9
9
|
super do
|
@@ -35,6 +35,13 @@ module Cats
|
|
35
35
|
render json: { success: false, error: e.message }
|
36
36
|
end
|
37
37
|
|
38
|
+
def start_with_pin
|
39
|
+
dispatch = @service.start_with_pin(params[:id], start_with_pin_params[:pin])
|
40
|
+
render json: { success: true, data: serialize(dispatch) }
|
41
|
+
rescue StandardError => e
|
42
|
+
render json: { success: false, error: e.message }
|
43
|
+
end
|
44
|
+
|
38
45
|
def confirm
|
39
46
|
dispatch = set_object
|
40
47
|
dispatch.confirm
|
@@ -43,6 +50,11 @@ module Cats
|
|
43
50
|
render json: { success: false, error: e.message }
|
44
51
|
end
|
45
52
|
|
53
|
+
def filter
|
54
|
+
query = Dispatch.ransack(params[:q])
|
55
|
+
render json: { success: true, data: serialize(query.result) }
|
56
|
+
end
|
57
|
+
|
46
58
|
def search
|
47
59
|
data = @service.search(current_user, params[:status])
|
48
60
|
render json: { success: true, data: serialize(data) }
|
@@ -63,6 +75,10 @@ module Cats
|
|
63
75
|
params.require(:payload).permit(:reference_no, :dispatch_plan_item_id, :transporter_id, :plate_no, :unit_id,
|
64
76
|
:driver_name, :driver_phone, :remark)
|
65
77
|
end
|
78
|
+
|
79
|
+
def start_with_pin_params
|
80
|
+
params.require(:payload).permit(:pin)
|
81
|
+
end
|
66
82
|
end
|
67
83
|
end
|
68
84
|
end
|
@@ -5,12 +5,12 @@ module Cats
|
|
5
5
|
|
6
6
|
def index
|
7
7
|
super do
|
8
|
-
LostCommodity.where(
|
8
|
+
LostCommodity.where(receipt_authorization_id: params[:id])
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
def model_params
|
13
|
-
params.require(:payload).permit(:
|
13
|
+
params.require(:payload).permit(:receipt_authorization_id, :quantity, :remark)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -20,8 +20,7 @@ module Cats
|
|
20
20
|
private
|
21
21
|
|
22
22
|
def model_params
|
23
|
-
params.require(:payload).permit(:dispatch_id, :store_id, :quantity, :
|
24
|
-
:authorized_by_id)
|
23
|
+
params.require(:payload).permit(:dispatch_id, :store_id, :quantity, :remark, :status, :authorized_by_id)
|
25
24
|
end
|
26
25
|
end
|
27
26
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class ReceiptsController < ApplicationController
|
4
|
+
include Common
|
5
|
+
|
6
|
+
def index
|
7
|
+
super do
|
8
|
+
Receipt.where(receipt_authorization_id: params[:id])
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def model_params
|
15
|
+
params.require(:payload).permit(:receipt_authorization_id, :commodity_status, :quantity, :remark)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -20,6 +20,9 @@ module Cats
|
|
20
20
|
delegate(:full_name, to: :authorized_by, prefix: :authorizer)
|
21
21
|
delegate(:name, to: :store, prefix: true)
|
22
22
|
delegate(:reference_no, to: :dispatch, prefix: true)
|
23
|
+
delegate(:dispatch_status, to: :dispatch)
|
24
|
+
delegate(:plate_no, to: :dispatch)
|
25
|
+
delegate(:driver_name, to: :dispatch)
|
23
26
|
|
24
27
|
def validate_dispatch_status
|
25
28
|
return unless dispatch
|
@@ -42,14 +45,39 @@ module Cats
|
|
42
45
|
end
|
43
46
|
|
44
47
|
def confirm
|
45
|
-
# Check if all transactions are committed first.
|
46
48
|
if instance_of?(DispatchAuthorization)
|
47
|
-
|
49
|
+
ActiveRecord::Base.transaction do
|
50
|
+
raise(StandardError, 'Authorization does not have transactions.') if transactions.blank?
|
48
51
|
|
49
|
-
|
50
|
-
|
52
|
+
transactions.each(&:commit)
|
53
|
+
self.status = CONFIRMED
|
54
|
+
save!
|
55
|
+
if dispatch.all_authorizations_confirmed?
|
56
|
+
dispatch.generate_pin
|
57
|
+
dispatch.quantity = dispatch.dispatch_transactions.sum(:quantity)
|
58
|
+
dispatch.dispatch_status = Dispatch::READY_TO_START
|
59
|
+
dispatch.save!
|
60
|
+
end
|
61
|
+
end
|
62
|
+
elsif instance_of?(ReceiptAuthorization)
|
63
|
+
raise(StandardError, 'Authorization does not have receipts.') unless receipts.count.positive?
|
64
|
+
|
65
|
+
total_received = receipts.sum(:quantity)
|
66
|
+
total_lost = lost_commodities.sum(:quantity)
|
67
|
+
diff = quantity - (total_received + total_lost)
|
68
|
+
raise(StandardError, "A quantity of #{diff} is unaccounted for.") unless diff.zero?
|
69
|
+
|
70
|
+
self.received_quantity = total_received
|
71
|
+
self.status = CONFIRMED
|
72
|
+
save!
|
73
|
+
generate_pin
|
51
74
|
end
|
52
|
-
self
|
75
|
+
self
|
76
|
+
end
|
77
|
+
|
78
|
+
def generate_pin
|
79
|
+
pin = SecureRandom.hex(10)
|
80
|
+
self.auth_details = { pin: pin, active: true, expires_at: DateTime.now + 1.hour }
|
53
81
|
save!
|
54
82
|
end
|
55
83
|
|
@@ -3,12 +3,13 @@ module Cats
|
|
3
3
|
class Dispatch < ApplicationRecord
|
4
4
|
DRAFT = 'Draft'.freeze
|
5
5
|
APPROVED = 'Approved'.freeze
|
6
|
+
READY_TO_START = 'Ready to Start'.freeze
|
6
7
|
STARTED = 'Started'.freeze
|
7
8
|
ARRIVED = 'Arrived'.freeze
|
8
9
|
UNLOADED = 'Unloaded'.freeze
|
9
10
|
RECEIVED = 'Received'.freeze
|
10
11
|
|
11
|
-
DISPATCH_STATUSES = [DRAFT, APPROVED, STARTED, ARRIVED, UNLOADED, RECEIVED].freeze
|
12
|
+
DISPATCH_STATUSES = [DRAFT, APPROVED, READY_TO_START, STARTED, ARRIVED, UNLOADED, RECEIVED].freeze
|
12
13
|
|
13
14
|
belongs_to :prepared_by, class_name: 'Cats::Core::User'
|
14
15
|
belongs_to :transporter
|
@@ -60,14 +61,16 @@ module Cats
|
|
60
61
|
save!
|
61
62
|
end
|
62
63
|
|
64
|
+
def all_authorizations_confirmed?
|
65
|
+
statuses = dispatch_authorizations.map(&:status).uniq
|
66
|
+
return true if statuses.length == 1 && statuses[0] == Authorization::CONFIRMED
|
67
|
+
|
68
|
+
false
|
69
|
+
end
|
70
|
+
|
63
71
|
def start
|
64
|
-
|
65
|
-
|
66
|
-
self.quantity = dispatch_transactions.sum(:quantity)
|
67
|
-
self.dispatch_status = STARTED
|
68
|
-
save!
|
69
|
-
dispatch_transactions.each(&:commit)
|
70
|
-
end
|
72
|
+
self.dispatch_status = STARTED
|
73
|
+
save!
|
71
74
|
end
|
72
75
|
|
73
76
|
def self.search_commodity(batch_no)
|
@@ -89,6 +92,12 @@ module Cats
|
|
89
92
|
}
|
90
93
|
end
|
91
94
|
end
|
95
|
+
|
96
|
+
def generate_pin
|
97
|
+
pin = SecureRandom.hex(10)
|
98
|
+
self.auth_details = { pin: pin, active: true, expires_at: DateTime.now + 1.hour }
|
99
|
+
save!
|
100
|
+
end
|
92
101
|
end
|
93
102
|
end
|
94
103
|
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class LostCommodity < ApplicationRecord
|
4
|
-
belongs_to :
|
4
|
+
belongs_to :receipt_authorization
|
5
5
|
|
6
|
-
validates :quantity, presence: true
|
7
|
-
validates :commodity_status, presence: true, inclusion: { in: Commodity::COMMODITY_STATUSES }
|
6
|
+
validates :quantity, presence: true, numericality: { greater_than: 0 }
|
8
7
|
end
|
9
8
|
end
|
10
9
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class Receipt < ApplicationRecord
|
4
|
+
belongs_to :receipt_authorization
|
5
|
+
|
6
|
+
validates :commodity_status, presence: true, inclusion: { in: Commodity::COMMODITY_STATUSES }
|
7
|
+
validates :quantity, presence: true, numericality: { greater_than: 0 }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -1,26 +1,22 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class ReceiptAuthorization < Authorization
|
4
|
+
has_many :receipts
|
5
|
+
has_many :lost_commodities
|
4
6
|
has_many :receipt_transactions
|
5
7
|
|
6
|
-
validates :
|
8
|
+
validates :received_quantity, presence: true, numericality: { greater_than_or_equal_to: 0 }
|
7
9
|
validate :validate_total_quantity
|
8
10
|
|
9
11
|
def validate_total_quantity
|
10
12
|
return unless dispatch && quantity
|
11
13
|
|
12
|
-
received = dispatch.receipt_authorizations.sum(:quantity)
|
14
|
+
received = dispatch.receipt_authorizations.sum(:quantity)
|
13
15
|
diff = dispatch.quantity - received
|
14
16
|
diff += quantity_was if quantity_was
|
15
|
-
diff += lost_quantity_was if lost_quantity_was
|
16
17
|
|
17
18
|
errors.add(:quantity, "authorized is higher than dispatch quantity (Max = #{diff}).") if quantity > diff
|
18
19
|
end
|
19
|
-
|
20
|
-
def confirm
|
21
|
-
self.status = CONFIRMED
|
22
|
-
save!
|
23
|
-
end
|
24
20
|
end
|
25
21
|
end
|
26
22
|
end
|
@@ -2,7 +2,7 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class DispatchAuthorizationSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :dispatch_id, :dispatch_reference_no, :store_id, :store_name, :quantity, :authorized_by_id,
|
5
|
-
:authorizer_full_name
|
5
|
+
:authorizer_full_name, :dispatch_status, :plate_no, :driver_name, :status
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -3,7 +3,7 @@ module Cats
|
|
3
3
|
class DispatchSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :reference_no, :dispatch_plan_item_id, :transporter_id, :transporter_name, :plate_no,
|
5
5
|
:driver_name, :driver_phone, :quantity, :remark, :prepared_by_id, :prepared_by_email,
|
6
|
-
:dispatch_status, :destination
|
6
|
+
:dispatch_status, :destination, :auth_details
|
7
7
|
|
8
8
|
def destination
|
9
9
|
object.dispatch_plan_item.destination.name
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class ReceiptAuthorizationSerializer < ActiveModel::Serializer
|
4
|
-
attributes :id, :dispatch_id, :dispatch_reference_no, :store_id, :store_name, :quantity, :
|
5
|
-
:status, :authorized_by_id, :authorizer_full_name
|
4
|
+
attributes :id, :dispatch_id, :dispatch_reference_no, :store_id, :store_name, :quantity, :received_quantity,
|
5
|
+
:remark, :status, :authorized_by_id, :authorizer_full_name, :auth_details
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -1,8 +1,7 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class ReceiptSerializer < ActiveModel::Serializer
|
4
|
-
attributes :id, :
|
5
|
-
:prepared_by_id, :prepared_by_email
|
4
|
+
attributes :id, :receipt_authorization_id, :commodity_status, :quantity, :remark
|
6
5
|
end
|
7
6
|
end
|
8
7
|
end
|
@@ -1,12 +1,8 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class ReceiptTransactionSerializer < ActiveModel::Serializer
|
4
|
-
attributes :id, :receipt_authorization_id, :
|
4
|
+
attributes :id, :receipt_authorization_id, :dispatch_reference_no, :destination_id, :destination_code, :quantity,
|
5
5
|
:transaction_date, :status
|
6
|
-
|
7
|
-
def dispatch_reference
|
8
|
-
object.receipt_authorization.dispatch.reference_no
|
9
|
-
end
|
10
6
|
end
|
11
7
|
end
|
12
8
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class AuthorizationService
|
4
|
+
def driver_confirm(authorization_id, pin)
|
5
|
+
authorization = ReceiptAuthorization.find(authorization_id)
|
6
|
+
if authorization.status == Authorization::AUTHORIZED
|
7
|
+
raise(StandardError, 'Authorization not confirmed by storekeeper.')
|
8
|
+
end
|
9
|
+
|
10
|
+
raise(StandardError, 'No pin has been generated for receipt.') if authorization.auth_details.nil?
|
11
|
+
|
12
|
+
raise(StandardError, 'Incorrect pin.') unless pin == authorization.auth_details['pin']
|
13
|
+
|
14
|
+
raise(StandardError, 'Pin is not active.') unless authorization.auth_details['active']
|
15
|
+
|
16
|
+
if DateTime.now > authorization.auth_details['expires_at']
|
17
|
+
authorization.auth_details[:active] = false
|
18
|
+
authorization.save!
|
19
|
+
raise(StandardError, 'Pin has expired.')
|
20
|
+
end
|
21
|
+
authorization.driver_confirmed = true
|
22
|
+
authorization.save!
|
23
|
+
authorization
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -37,6 +37,28 @@ module Cats
|
|
37
37
|
dispatch
|
38
38
|
end
|
39
39
|
|
40
|
+
def start_with_pin(dispatch_id, pin)
|
41
|
+
dispatch = Dispatch.find(dispatch_id)
|
42
|
+
raise(StandardError, 'Dispatch is already started.') if dispatch.dispatch_status == Dispatch::STARTED
|
43
|
+
|
44
|
+
raise(StandardError, 'No pin has been generated for dispatch.') if dispatch.auth_details.nil?
|
45
|
+
|
46
|
+
raise(StandardError, 'Incorrect pin.') unless pin == dispatch.auth_details['pin']
|
47
|
+
|
48
|
+
raise(StandardError, 'Pin is not active.') unless dispatch.auth_details['active']
|
49
|
+
|
50
|
+
if DateTime.now > dispatch.auth_details['expires_at']
|
51
|
+
dispatch.auth_details[:active] = false
|
52
|
+
dispatch.save!
|
53
|
+
raise(StandardError, 'Pin has expired.')
|
54
|
+
end
|
55
|
+
dispatch.start
|
56
|
+
send_notification(dispatch)
|
57
|
+
dispatch.auth_details = nil
|
58
|
+
dispatch.save!
|
59
|
+
dispatch
|
60
|
+
end
|
61
|
+
|
40
62
|
def send_notification(dispatch)
|
41
63
|
notification_rule = Cats::Core::NotificationRule.find_by(code: 'dispatch')
|
42
64
|
raise(StandardError, 'Notification rule not found for dispatch notification.') unless notification_rule
|
data/config/routes.rb
CHANGED
@@ -96,17 +96,18 @@ Cats::Core::Engine.routes.draw do
|
|
96
96
|
post '/dispatch_plan_items/filter', controller: :dispatch_plan_items, action: :filter
|
97
97
|
get '/dispatch_plan_items/:id/dispatches', controller: :dispatches, action: :index, as: :dispatches_plan_item
|
98
98
|
|
99
|
+
post '/dispatches/filter', controller: :dispatches, action: :filter
|
99
100
|
get '/dispatches/search', controller: :dispatches, action: :search, as: :search_dispatches
|
100
101
|
resources :dispatches, except: %i[index destroy] do
|
101
102
|
member do
|
102
103
|
get 'dispatch_authorizations', controller: :dispatch_authorizations, action: :index
|
103
104
|
get 'receipt_authorizations', controller: :receipt_authorizations, action: :index
|
104
105
|
get 'receipts', controller: :receipts, action: :index
|
105
|
-
get 'lost', controller: :lost_commodities, action: :index
|
106
106
|
get 'commodity'
|
107
107
|
post 'approve'
|
108
108
|
post 'start'
|
109
109
|
post 'confirm'
|
110
|
+
post 'start_with_pin'
|
110
111
|
end
|
111
112
|
end
|
112
113
|
|
@@ -117,13 +118,22 @@ Cats::Core::Engine.routes.draw do
|
|
117
118
|
end
|
118
119
|
end
|
119
120
|
|
121
|
+
get(
|
122
|
+
'/storekeeper/:id/authorizations',
|
123
|
+
controller: :dispatch_authorizations,
|
124
|
+
action: :storekeeper_authorizations,
|
125
|
+
as: :storekeeper_authorizations
|
126
|
+
)
|
120
127
|
resources :receipt_authorizations, except: %i[index destroy] do
|
121
128
|
member do
|
122
129
|
get 'transactions', controller: :receipt_transactions, action: :index
|
130
|
+
get 'lost', controller: :lost_commodities, action: :index
|
131
|
+
get 'receipts', controller: :receipts, action: :index
|
123
132
|
post 'confirm', controller: :receipt_authorizations, action: :confirm
|
124
133
|
end
|
125
134
|
end
|
126
135
|
|
136
|
+
resources :receipts, except: %i[index destroy]
|
127
137
|
post(
|
128
138
|
'dispatch_transactions/allocation',
|
129
139
|
controller: :dispatch_transactions,
|
@@ -10,9 +10,11 @@ class CreateCatsCoreReceiptAuthorizations < ActiveRecord::Migration[6.1]
|
|
10
10
|
index: { name: 'store_on_ra_indx' },
|
11
11
|
foreign_key: { to_table: :cats_core_stores }
|
12
12
|
t.float :quantity, null: false
|
13
|
-
t.float :
|
13
|
+
t.float :received_quantity, null: false, default: 0
|
14
14
|
t.string :status, null: false, default: 'Authorized'
|
15
15
|
t.string :remark
|
16
|
+
t.jsonb :auth_details
|
17
|
+
t.boolean :driver_confirmed, null: false, default: false
|
16
18
|
t.references :authorized_by,
|
17
19
|
null: false,
|
18
20
|
index: { name: 'ab_on_receipt_authorizations_indx' },
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateCatsCoreReceipts < ActiveRecord::Migration[7.0]
|
2
|
+
def change
|
3
|
+
create_table :cats_core_receipts do |t|
|
4
|
+
t.references :receipt_authorization,
|
5
|
+
null: false,
|
6
|
+
index: { name: 'ra_on_receipts_indx' },
|
7
|
+
foreign_key: { to_table: :cats_core_receipt_authorizations }
|
8
|
+
t.string :commodity_status, null: false
|
9
|
+
t.float :quantity, null: false
|
10
|
+
t.string :remark
|
11
|
+
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,12 +1,11 @@
|
|
1
1
|
class CreateCatsCoreLostCommodities < ActiveRecord::Migration[7.0]
|
2
2
|
def change
|
3
3
|
create_table :cats_core_lost_commodities do |t|
|
4
|
-
t.references :
|
4
|
+
t.references :receipt_authorization,
|
5
5
|
null: false,
|
6
|
-
index: { name: '
|
7
|
-
foreign_key: { to_table: :
|
6
|
+
index: { name: 'ra_on_lc_indx' },
|
7
|
+
foreign_key: { to_table: :cats_core_receipt_authorizations }
|
8
8
|
t.float :quantity, null: false
|
9
|
-
t.string :commodity_status, null: false
|
10
9
|
t.string :remark
|
11
10
|
|
12
11
|
t.timestamps
|
data/lib/cats/core/version.rb
CHANGED
@@ -33,11 +33,27 @@ FactoryBot.define do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
trait :ready_to_start do
|
37
|
+
after(:create) do |dispatch, options|
|
38
|
+
authorization = create(:dispatch_authorization, dispatch: dispatch, store: options.stack.store)
|
39
|
+
dispatch.approve
|
40
|
+
create(:dispatch_transaction, dispatch_authorization: authorization, source: options.stack, quantity: 100)
|
41
|
+
authorization.confirm
|
42
|
+
dispatch.quantity = 100
|
43
|
+
dispatch.dispatch_status = Cats::Core::Dispatch::READY_TO_START
|
44
|
+
dispatch.save!
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
36
48
|
trait :started do
|
37
49
|
after(:create) do |dispatch, options|
|
38
50
|
authorization = create(:dispatch_authorization, dispatch: dispatch, store: options.stack.store)
|
39
51
|
dispatch.approve
|
40
52
|
create(:dispatch_transaction, dispatch_authorization: authorization, source: options.stack, quantity: 100)
|
53
|
+
authorization.confirm
|
54
|
+
dispatch.quantity = 100
|
55
|
+
dispatch.dispatch_status = Cats::Core::Dispatch::READY_TO_START
|
56
|
+
dispatch.save!
|
41
57
|
dispatch.start
|
42
58
|
end
|
43
59
|
end
|
@@ -1,19 +1,25 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :receipt_authorization, class: 'Cats::Core::ReceiptAuthorization' do
|
3
|
-
dispatch
|
4
|
-
dispatch = create(:dispatch, :with_transaction)
|
5
|
-
dispatch.start
|
6
|
-
dispatch
|
7
|
-
end
|
3
|
+
association :dispatch, :started
|
8
4
|
store
|
9
5
|
quantity { 100 }
|
10
|
-
|
6
|
+
received_quantity { 0 }
|
11
7
|
remark { FFaker::Name.name }
|
12
8
|
status { Cats::Core::ReceiptAuthorization::AUTHORIZED }
|
13
9
|
authorized_by factory: :user
|
14
10
|
|
11
|
+
trait :with_receipt do
|
12
|
+
after(:create) do |authorization|
|
13
|
+
create(:receipt, receipt_authorization: authorization, quantity: 100)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
15
17
|
trait :confirmed do
|
16
|
-
|
18
|
+
after(:create) do |authorization|
|
19
|
+
create(:receipt, receipt_authorization: authorization, quantity: 100)
|
20
|
+
authorization.status = Cats::Core::Authorization::CONFIRMED
|
21
|
+
authorization.save!
|
22
|
+
end
|
17
23
|
end
|
18
24
|
end
|
19
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cats_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.25
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henock L.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-05-
|
11
|
+
date: 2022-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -246,6 +246,7 @@ files:
|
|
246
246
|
- app/controllers/cats/core/notifications_controller.rb
|
247
247
|
- app/controllers/cats/core/receipt_authorizations_controller.rb
|
248
248
|
- app/controllers/cats/core/receipt_transactions_controller.rb
|
249
|
+
- app/controllers/cats/core/receipts_controller.rb
|
249
250
|
- app/controllers/cats/core/roles_controller.rb
|
250
251
|
- app/controllers/cats/core/round_plans_controller.rb
|
251
252
|
- app/controllers/cats/core/routes_controller.rb
|
@@ -292,6 +293,7 @@ files:
|
|
292
293
|
- app/models/cats/core/program.rb
|
293
294
|
- app/models/cats/core/purchase_order.rb
|
294
295
|
- app/models/cats/core/ration.rb
|
296
|
+
- app/models/cats/core/receipt.rb
|
295
297
|
- app/models/cats/core/receipt_authorization.rb
|
296
298
|
- app/models/cats/core/receipt_transaction.rb
|
297
299
|
- app/models/cats/core/rhn_request.rb
|
@@ -350,6 +352,7 @@ files:
|
|
350
352
|
- app/serializers/cats/core/unit_conversion_serializer.rb
|
351
353
|
- app/serializers/cats/core/unit_of_measure_serializer.rb
|
352
354
|
- app/serializers/cats/core/user_serializer.rb
|
355
|
+
- app/services/cats/core/authorization_service.rb
|
353
356
|
- app/services/cats/core/dispatch_plan_service.rb
|
354
357
|
- app/services/cats/core/dispatch_service.rb
|
355
358
|
- app/services/cats/core/menu_service.rb
|
@@ -396,6 +399,7 @@ files:
|
|
396
399
|
- db/migrate/20210719133710_create_cats_core_stacking_rules.rb
|
397
400
|
- db/migrate/20210724074657_create_cats_core_notifications.rb
|
398
401
|
- db/migrate/20210727074646_create_cats_core_receipt_authorizations.rb
|
402
|
+
- db/migrate/20210727105834_create_cats_core_receipts.rb
|
399
403
|
- db/migrate/20210728041505_create_cats_core_lost_commodities.rb
|
400
404
|
- db/migrate/20210814160628_create_cats_core_receipt_transactions.rb
|
401
405
|
- db/migrate/20210814175406_create_cats_core_stack_transactions.rb
|
@@ -465,6 +469,7 @@ files:
|
|
465
469
|
- spec/factories/cats/core/rations.rb
|
466
470
|
- spec/factories/cats/core/receipt_authorizations.rb
|
467
471
|
- spec/factories/cats/core/receipt_transactions.rb
|
472
|
+
- spec/factories/cats/core/receipts.rb
|
468
473
|
- spec/factories/cats/core/rhn_requests.rb
|
469
474
|
- spec/factories/cats/core/role_menus.rb
|
470
475
|
- spec/factories/cats/core/roles.rb
|