cats_core 1.4.20 → 1.4.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/cats/core/dispatch_authorizations_controller.rb +35 -0
- data/app/controllers/cats/core/dispatch_plan_items_controller.rb +2 -2
- data/app/controllers/cats/core/dispatch_transactions_controller.rb +4 -4
- data/app/controllers/cats/core/dispatches_controller.rb +7 -2
- data/app/controllers/cats/core/lost_commodities_controller.rb +2 -2
- data/app/controllers/cats/core/receipt_authorizations_controller.rb +27 -0
- data/app/controllers/cats/core/receipt_transactions_controller.rb +2 -20
- data/app/controllers/cats/core/receipts_controller.rb +2 -28
- data/app/models/cats/core/authorization.rb +77 -0
- data/app/models/cats/core/dispatch.rb +30 -47
- data/app/models/cats/core/dispatch_authorization.rb +13 -0
- data/app/models/cats/core/dispatch_plan_item.rb +1 -0
- data/app/models/cats/core/dispatch_transaction.rb +39 -2
- data/app/models/cats/core/lost_commodity.rb +2 -3
- data/app/models/cats/core/receipt.rb +3 -37
- data/app/models/cats/core/receipt_authorization.rb +22 -0
- data/app/models/cats/core/receipt_transaction.rb +17 -14
- data/app/models/cats/core/transaction.rb +0 -30
- data/app/serializers/cats/core/dispatch_authorization_serializer.rb +8 -0
- data/app/serializers/cats/core/dispatch_plan_item_serializer.rb +1 -1
- data/app/serializers/cats/core/dispatch_transaction_serializer.rb +1 -2
- data/app/serializers/cats/core/lost_commodity_serializer.rb +1 -1
- data/app/serializers/cats/core/receipt_authorization_serializer.rb +8 -0
- 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 +25 -0
- data/config/routes.rb +26 -9
- data/db/migrate/20210718043401_create_cats_core_dispatch_plan_items.rb +1 -0
- data/db/migrate/20210718045516_create_cats_core_dispatches.rb +4 -0
- data/db/migrate/20210718055414_create_cats_core_dispatch_authorizations.rb +22 -0
- data/db/migrate/20210718202957_create_cats_core_dispatch_transactions.rb +9 -3
- data/db/migrate/20210727074646_create_cats_core_receipt_authorizations.rb +24 -0
- data/db/migrate/20210727105834_create_cats_core_receipts.rb +15 -0
- data/db/migrate/20210728041505_create_cats_core_lost_commodities.rb +3 -4
- data/db/migrate/20210814160628_create_cats_core_receipt_transactions.rb +3 -3
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/dispatch_authorizations.rb +26 -0
- data/spec/factories/cats/core/dispatch_plan_items.rb +1 -0
- data/spec/factories/cats/core/dispatch_transactions.rb +2 -7
- data/spec/factories/cats/core/dispatches.rb +38 -3
- data/spec/factories/cats/core/lost_commodities.rb +1 -2
- data/spec/factories/cats/core/receipt_authorizations.rb +25 -0
- data/spec/factories/cats/core/receipt_transactions.rb +2 -22
- data/spec/factories/cats/core/receipts.rb +2 -9
- data/spec/factories/cats/core/stacks.rb +1 -1
- metadata +15 -4
- data/app/services/cats/core/receipt_service.rb +0 -48
- data/db/migrate/20210727074646_create_cats_core_receipts.rb +0 -20
@@ -12,41 +12,11 @@ module Cats
|
|
12
12
|
validates :transaction_date, :quantity, :status, presence: true
|
13
13
|
validates :quantity, numericality: { greater_than: 0 }
|
14
14
|
validates :status, inclusion: { in: STATUSES }
|
15
|
-
validate :validate_quantity, unless: :skip_quantity_validation
|
16
|
-
|
17
|
-
def validate_quantity
|
18
|
-
return unless quantity.present? && source.present? && dispatch.present?
|
19
|
-
|
20
|
-
dispatched = self.class.joins(:source, :dispatch).where(
|
21
|
-
source: { store_id: source.store_id },
|
22
|
-
dispatch: { dispatch_plan_item_id: dispatch.dispatch_plan_item_id }
|
23
|
-
).sum(:quantity)
|
24
|
-
dispatched -= quantity_was if quantity_was
|
25
|
-
|
26
|
-
# Get quantity in hub authorization for source
|
27
|
-
authorized = dispatch.dispatch_plan_item.hub_authorizations.where(store_id: source.store_id).sum(:quantity)
|
28
|
-
available = authorized - dispatched
|
29
|
-
|
30
|
-
errors.add(:quantity, "exceeds authorized quantity (Max = #{available}).") if quantity > available
|
31
|
-
end
|
32
15
|
|
33
16
|
def commit
|
34
17
|
raise(NotImplementedError, 'Method should be implemented in child classes.')
|
35
18
|
end
|
36
19
|
|
37
|
-
def skip_quantity_validation
|
38
|
-
# Quantity validation should be skipped if we are commiting transactions.
|
39
|
-
(
|
40
|
-
instance_of?(Cats::Core::DispatchTransaction) &&
|
41
|
-
dispatch &&
|
42
|
-
status == COMMITTED
|
43
|
-
) || (
|
44
|
-
instance_of?(Cats::Core::ReceiptTransaction) &&
|
45
|
-
receipt &&
|
46
|
-
receipt.status == Cats::Core::Receipt::STACKING
|
47
|
-
)
|
48
|
-
end
|
49
|
-
|
50
20
|
def set_status
|
51
21
|
return unless new_record?
|
52
22
|
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class DispatchAuthorizationSerializer < ActiveModel::Serializer
|
4
|
+
attributes :id, :dispatch_id, :dispatch_reference_no, :store_id, :store_name, :quantity, :authorized_by_id,
|
5
|
+
:authorizer_full_name, :dispatch_status, :plate_no, :driver_name
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class DispatchPlanItemSerializer < ActiveModel::Serializer
|
4
|
-
attributes :id, :dispatch_plan_id, :plan_reference_no, :source_id, :source_name, :destination_id,
|
4
|
+
attributes :id, :reference_no, :dispatch_plan_id, :plan_reference_no, :source_id, :source_name, :destination_id,
|
5
5
|
:destination_name, :quantity, :source_location_type, :destination_location_type, :commodity_status,
|
6
6
|
:status, :commodity_id, :commodity_name, :commodity_batch_no
|
7
7
|
end
|
@@ -1,8 +1,7 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class DispatchTransactionSerializer < ActiveModel::Serializer
|
4
|
-
attributes :id, :source_id, :source_code, :
|
5
|
-
:transaction_date, :status
|
4
|
+
attributes :id, :source_id, :source_code, :dispatch_authorization_id, :quantity, :transaction_date, :status
|
6
5
|
end
|
7
6
|
end
|
8
7
|
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class ReceiptAuthorizationSerializer < ActiveModel::Serializer
|
4
|
+
attributes :id, :dispatch_id, :dispatch_reference_no, :store_id, :store_name, :quantity, :received_quantity,
|
5
|
+
:remark, :status, :authorized_by_id, :authorizer_full_name
|
6
|
+
end
|
7
|
+
end
|
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, :
|
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.dispatch.reference_no
|
9
|
-
end
|
10
6
|
end
|
11
7
|
end
|
12
8
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class AuthorizationService
|
4
|
+
# A method to confirm a dispatch authorization. This method
|
5
|
+
# also checks if all authorizations under a dispatch are confirmed
|
6
|
+
# and if so it sets the dispatch status to READY_TO_START.
|
7
|
+
def confirm(id)
|
8
|
+
authorization = DispatchAuthorization.find(id)
|
9
|
+
|
10
|
+
ActiveRecord::Base.transaction do
|
11
|
+
authorization.confirm
|
12
|
+
|
13
|
+
# Check if all authorizations under the dispatch are confirmed.
|
14
|
+
dispatch = authorization.dispatch
|
15
|
+
if dispatch.all_authorizations_confirmed?
|
16
|
+
dispatch.quantity = dispatch.dispatch_transactions.sum(:quantity)
|
17
|
+
dispatch.dispatch_status = Dispatch::READY_TO_START
|
18
|
+
dispatch.save!
|
19
|
+
end
|
20
|
+
end
|
21
|
+
authorization
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/config/routes.rb
CHANGED
@@ -96,12 +96,13 @@ 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
|
-
get '
|
103
|
+
get 'dispatch_authorizations', controller: :dispatch_authorizations, action: :index
|
104
|
+
get 'receipt_authorizations', controller: :receipt_authorizations, action: :index
|
103
105
|
get 'receipts', controller: :receipts, action: :index
|
104
|
-
get 'lost', controller: :lost_commodities, action: :index
|
105
106
|
get 'commodity'
|
106
107
|
post 'approve'
|
107
108
|
post 'start'
|
@@ -109,6 +110,29 @@ Cats::Core::Engine.routes.draw do
|
|
109
110
|
end
|
110
111
|
end
|
111
112
|
|
113
|
+
resources :dispatch_authorizations, except: %i[index destory] do
|
114
|
+
member do
|
115
|
+
get 'transactions', controller: :dispatch_transactions, action: :index
|
116
|
+
post 'confirm', controller: :dispatch_authorizations, action: :confirm
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
get(
|
121
|
+
'/storekeeper/:id/authorizations',
|
122
|
+
controller: :dispatch_authorizations,
|
123
|
+
action: :storekeeper_authorizations,
|
124
|
+
as: :storekeeper_authorizations
|
125
|
+
)
|
126
|
+
resources :receipt_authorizations, except: %i[index destroy] do
|
127
|
+
member do
|
128
|
+
get 'transactions', controller: :receipt_transactions, action: :index
|
129
|
+
get 'lost', controller: :lost_commodities, action: :index
|
130
|
+
get 'receipts', controller: :receipts, action: :index
|
131
|
+
post 'confirm', controller: :receipt_authorizations, action: :confirm
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
resources :receipts, except: %i[index destroy]
|
112
136
|
post(
|
113
137
|
'dispatch_transactions/allocation',
|
114
138
|
controller: :dispatch_transactions,
|
@@ -116,13 +140,6 @@ Cats::Core::Engine.routes.draw do
|
|
116
140
|
as: :allocation_transaction
|
117
141
|
)
|
118
142
|
resources :dispatch_transactions, except: %i[index new edit destroy]
|
119
|
-
resources :receipts, except: %i[index new edit destroy] do
|
120
|
-
member do
|
121
|
-
get 'transactions', controller: :receipt_transactions, action: :index
|
122
|
-
post 'start_stacking'
|
123
|
-
post 'finish_stacking'
|
124
|
-
end
|
125
|
-
end
|
126
143
|
resources :receipt_transactions, except: %i[index new edit destroy]
|
127
144
|
resources :lost_commodities, except: %i[index destroy]
|
128
145
|
get '/plans/:id/round_plans', controller: :round_plans, action: :index, as: :round_plans_plan
|
@@ -1,6 +1,7 @@
|
|
1
1
|
class CreateCatsCoreDispatchPlanItems < ActiveRecord::Migration[6.1]
|
2
2
|
def change
|
3
3
|
create_table :cats_core_dispatch_plan_items do |t|
|
4
|
+
t.string :reference_no, null: false, unique: true
|
4
5
|
t.references :dispatch_plan,
|
5
6
|
null: false,
|
6
7
|
index: { name: 'dpi_on_dp_indx' },
|
@@ -14,6 +14,10 @@ class CreateCatsCoreDispatches < ActiveRecord::Migration[6.1]
|
|
14
14
|
t.string :driver_name, null: false
|
15
15
|
t.string :driver_phone, null: false
|
16
16
|
t.float :quantity, null: false, default: 0
|
17
|
+
t.references :unit,
|
18
|
+
null: false,
|
19
|
+
index: { name: 'unit_on_dispatches_indx' },
|
20
|
+
foreign_key: { to_table: :cats_core_unit_of_measures }
|
17
21
|
t.string :commodity_status, null: false, default: 'Good'
|
18
22
|
t.string :remark
|
19
23
|
t.references :prepared_by,
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class CreateCatsCoreDispatchAuthorizations < ActiveRecord::Migration[7.0]
|
2
|
+
def change
|
3
|
+
create_table :cats_core_dispatch_authorizations do |t|
|
4
|
+
t.references :dispatch,
|
5
|
+
null: false,
|
6
|
+
index: { name: 'dispatch_on_da_indx' },
|
7
|
+
foreign_key: { to_table: :cats_core_dispatches }
|
8
|
+
t.references :store,
|
9
|
+
null: false,
|
10
|
+
index: { name: 'store_on_da_indx' },
|
11
|
+
foreign_key: { to_table: :cats_core_stores }
|
12
|
+
t.float :quantity, null: false
|
13
|
+
t.string :status, null: false, default: 'Authorized'
|
14
|
+
t.references :authorized_by,
|
15
|
+
null: false,
|
16
|
+
index: { name: 'ab_on_da_indx' },
|
17
|
+
foreign_key: { to_table: :cats_core_users }
|
18
|
+
|
19
|
+
t.timestamps
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -5,15 +5,21 @@ class CreateCatsCoreDispatchTransactions < ActiveRecord::Migration[6.1]
|
|
5
5
|
null: false,
|
6
6
|
index: { name: 'stack_on_dt_indx' },
|
7
7
|
foreign_key: { to_table: :cats_core_stacks }
|
8
|
-
t.references :
|
8
|
+
t.references :dispatch_authorization,
|
9
9
|
null: false,
|
10
|
-
index: { name: '
|
11
|
-
foreign_key: { to_table: :
|
10
|
+
index: { name: 'da_on_dt_indx' },
|
11
|
+
foreign_key: { to_table: :cats_core_dispatch_authorizations }
|
12
12
|
t.date :transaction_date, null: false
|
13
13
|
t.float :quantity, null: false
|
14
14
|
t.string :status, null: false, default: 'Draft'
|
15
15
|
|
16
16
|
t.timestamps
|
17
17
|
end
|
18
|
+
add_index(
|
19
|
+
:cats_core_dispatch_transactions,
|
20
|
+
[:source_id, :dispatch_authorization_id],
|
21
|
+
unique: true,
|
22
|
+
name: 'sda_on_dt_uniq_indx'
|
23
|
+
)
|
18
24
|
end
|
19
25
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class CreateCatsCoreReceiptAuthorizations < ActiveRecord::Migration[6.1]
|
2
|
+
def change
|
3
|
+
create_table :cats_core_receipt_authorizations do |t|
|
4
|
+
t.references :dispatch,
|
5
|
+
null: false,
|
6
|
+
index: { name: 'dispatch_on_receipt_authorizations_indx' },
|
7
|
+
foreign_key: { to_table: :cats_core_dispatches }
|
8
|
+
t.references :store,
|
9
|
+
null: false,
|
10
|
+
index: { name: 'store_on_ra_indx' },
|
11
|
+
foreign_key: { to_table: :cats_core_stores }
|
12
|
+
t.float :quantity, null: false
|
13
|
+
t.float :received_quantity, null: false, default: 0
|
14
|
+
t.string :status, null: false, default: 'Authorized'
|
15
|
+
t.string :remark
|
16
|
+
t.references :authorized_by,
|
17
|
+
null: false,
|
18
|
+
index: { name: 'ab_on_receipt_authorizations_indx' },
|
19
|
+
foreign_key: { to_table: :cats_core_users }
|
20
|
+
|
21
|
+
t.timestamps
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -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
|
@@ -1,10 +1,10 @@
|
|
1
1
|
class CreateCatsCoreReceiptTransactions < ActiveRecord::Migration[6.1]
|
2
2
|
def change
|
3
3
|
create_table :cats_core_receipt_transactions 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: 'receipt_authorization_on_rt_indx' },
|
7
|
+
foreign_key: { to_table: :cats_core_receipt_authorizations }
|
8
8
|
t.references :destination,
|
9
9
|
null: false,
|
10
10
|
index: { name: 'stack_on_rt_indx' },
|
data/lib/cats/core/version.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
FactoryBot.define do
|
2
|
+
factory :dispatch_authorization, class: 'Cats::Core::DispatchAuthorization' do
|
3
|
+
transient do
|
4
|
+
s { create(:store) }
|
5
|
+
stack { create(:stack, quantity: 100, store: s) }
|
6
|
+
end
|
7
|
+
dispatch
|
8
|
+
store { s }
|
9
|
+
quantity { 100 }
|
10
|
+
status { Cats::Core::ReceiptAuthorization::AUTHORIZED }
|
11
|
+
authorized_by factory: :user
|
12
|
+
|
13
|
+
trait :approved do
|
14
|
+
after(:create) do |obj|
|
15
|
+
obj.dispatch.approve
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
trait :with_transaction do
|
20
|
+
after(:create) do |obj, options|
|
21
|
+
obj.dispatch.approve
|
22
|
+
create(:dispatch_transaction, dispatch_authorization: obj, source: options.stack, quantity: 100)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -4,14 +4,9 @@ FactoryBot.define do
|
|
4
4
|
stack { create(:stack) }
|
5
5
|
end
|
6
6
|
source { stack }
|
7
|
-
|
8
|
-
plan_item = create(:dispatch_plan_item, quantity: 100)
|
9
|
-
plan_item.dispatch_plan.approve
|
10
|
-
create(:hub_authorization, dispatch_plan_item: plan_item, quantity: 100, store: stack.store)
|
11
|
-
create(:dispatch, dispatch_plan_item: plan_item, transaction?: false)
|
12
|
-
end
|
7
|
+
association :dispatch_authorization, :approved
|
13
8
|
transaction_date { Date.today }
|
14
|
-
quantity {
|
9
|
+
quantity { 100 }
|
15
10
|
status { Cats::Core::Transaction::DRAFT }
|
16
11
|
end
|
17
12
|
end
|
@@ -2,7 +2,6 @@ FactoryBot.define do
|
|
2
2
|
factory :dispatch, class: 'Cats::Core::Dispatch' do
|
3
3
|
transient do
|
4
4
|
stack { create(:stack, quantity: 100) }
|
5
|
-
transaction? { true }
|
6
5
|
end
|
7
6
|
reference_no { FFaker::Name.name }
|
8
7
|
dispatch_plan_item do
|
@@ -11,6 +10,7 @@ FactoryBot.define do
|
|
11
10
|
create(:hub_authorization, dispatch_plan_item: plan_item, quantity: 100, store: stack.store)
|
12
11
|
plan_item
|
13
12
|
end
|
13
|
+
unit factory: :unit_of_measure
|
14
14
|
transporter
|
15
15
|
plate_no { FFaker::Name.name }
|
16
16
|
driver_name { FFaker::Name.name }
|
@@ -19,8 +19,43 @@ FactoryBot.define do
|
|
19
19
|
prepared_by factory: :user
|
20
20
|
dispatch_status { Cats::Core::Dispatch::DRAFT }
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
trait :with_authorization do
|
23
|
+
after(:create) do |dispatch, options|
|
24
|
+
create(:dispatch_authorization, dispatch: dispatch, store: options.stack.store)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
trait :with_transaction do
|
29
|
+
after(:create) do |dispatch, options|
|
30
|
+
authorization = create(:dispatch_authorization, dispatch: dispatch, store: options.stack.store)
|
31
|
+
dispatch.approve
|
32
|
+
create(:dispatch_transaction, dispatch_authorization: authorization, source: options.stack, quantity: 100)
|
33
|
+
end
|
34
|
+
end
|
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
|
+
|
48
|
+
trait :started do
|
49
|
+
after(:create) do |dispatch, options|
|
50
|
+
authorization = create(:dispatch_authorization, dispatch: dispatch, store: options.stack.store)
|
51
|
+
dispatch.approve
|
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!
|
57
|
+
dispatch.start
|
58
|
+
end
|
24
59
|
end
|
25
60
|
end
|
26
61
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
FactoryBot.define do
|
2
|
+
factory :receipt_authorization, class: 'Cats::Core::ReceiptAuthorization' do
|
3
|
+
association :dispatch, :started
|
4
|
+
store
|
5
|
+
quantity { 100 }
|
6
|
+
received_quantity { 0 }
|
7
|
+
remark { FFaker::Name.name }
|
8
|
+
status { Cats::Core::ReceiptAuthorization::AUTHORIZED }
|
9
|
+
authorized_by factory: :user
|
10
|
+
|
11
|
+
trait :with_receipt do
|
12
|
+
after(:create) do |authorization|
|
13
|
+
create(:receipt, receipt_authorization: authorization, quantity: 100)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
trait :confirmed do
|
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
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,27 +1,7 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :receipt_transaction, class: 'Cats::Core::ReceiptTransaction' do
|
3
|
-
|
4
|
-
|
5
|
-
end
|
6
|
-
transient do
|
7
|
-
stack { create(:stack) }
|
8
|
-
end
|
9
|
-
|
10
|
-
destination { stack }
|
11
|
-
receipt do
|
12
|
-
dispatch.approve
|
13
|
-
dispatch.start
|
14
|
-
receipt = create(:receipt, dispatch: dispatch)
|
15
|
-
dispatch.confirm
|
16
|
-
create(
|
17
|
-
:hub_authorization,
|
18
|
-
authorization_type: Cats::Core::HubAuthorization::DESTINATION,
|
19
|
-
dispatch_plan_item: dispatch.dispatch_plan_item,
|
20
|
-
store: stack.store,
|
21
|
-
quantity: 100
|
22
|
-
)
|
23
|
-
receipt
|
24
|
-
end
|
3
|
+
association :receipt_authorization, :confirmed
|
4
|
+
destination factory: :stack
|
25
5
|
transaction_date { Date.today }
|
26
6
|
quantity { 100 }
|
27
7
|
status { Cats::Core::Transaction::DRAFT }
|
@@ -1,15 +1,8 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :receipt, class: 'Cats::Core::Receipt' do
|
3
|
-
|
4
|
-
dispatch = create(:dispatch)
|
5
|
-
dispatch.approve
|
6
|
-
dispatch.start
|
7
|
-
dispatch
|
8
|
-
end
|
9
|
-
quantity { 100 }
|
3
|
+
receipt_authorization
|
10
4
|
commodity_status { Cats::Core::Commodity::GOOD }
|
11
|
-
|
5
|
+
quantity { 50 }
|
12
6
|
remark { FFaker::Name.name }
|
13
|
-
prepared_by factory: :user
|
14
7
|
end
|
15
8
|
end
|