cats_core 1.1.1 → 1.1.5
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/dispatches_controller.rb +1 -1
- data/app/controllers/cats/core/locations_controller.rb +3 -33
- data/app/controllers/cats/core/receipt_transactions_controller.rb +13 -0
- data/app/controllers/cats/core/receipts_controller.rb +18 -0
- data/app/models/cats/core/gift_certificate.rb +10 -0
- data/app/models/cats/core/purchase_order.rb +10 -0
- data/app/models/cats/core/receipt.rb +17 -7
- data/app/models/cats/core/receipt_transaction.rb +2 -0
- data/app/models/cats/core/transaction.rb +18 -3
- data/app/serializers/cats/core/receipt_transaction_serializer.rb +8 -0
- data/app/services/cats/core/dispatch_service.rb +7 -7
- data/app/services/cats/core/receipt_service.rb +32 -0
- data/config/routes.rb +7 -1
- data/db/migrate/20210717032330_create_cats_core_donations.rb +1 -0
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/donations.rb +1 -0
- data/spec/factories/cats/core/receipt_transactions.rb +1 -1
- data/spec/factories/cats/core/receipts.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1edf27e2257545cf71d59da4348838a7d413911a3977e505e9ea38788bbf6bc0
|
4
|
+
data.tar.gz: 7b11450abaf98eed4cde168465e0f778be42026895d52883760bbe5cb0b571ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26de9f25dc8533a8ad33089cedacf51feff5b7ecfba6c08bfa55d811e7672cd4892955bccdd853a7281ec677a31478c9e3f8ecc2e421c79cbdeb34559b15c7d2
|
7
|
+
data.tar.gz: 26c4b80b13de8a60a02545382205877c8a252beebf2943ca990860a5bd32652d1152b865a90940dc0a55eebfca1c3bde974bfb6dfa07addaf174c59a5e74674a
|
@@ -1,50 +1,20 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class LocationsController < ApplicationController
|
4
|
-
|
4
|
+
include Common
|
5
5
|
|
6
6
|
def index
|
7
7
|
locations = Cats::Core::Location.where(location_type: params[:location_type])
|
8
|
-
data
|
9
|
-
render json: { success: true, data: data }
|
10
|
-
end
|
11
|
-
|
12
|
-
def show
|
13
|
-
data = ActiveModelSerializers::SerializableResource.new(@location)
|
14
|
-
render json: { success: true, data: data }
|
8
|
+
render json: { success: true, data: serialize(locations) }
|
15
9
|
end
|
16
10
|
|
17
11
|
def children
|
18
12
|
parent = Cats::Core::Location.find(params[:id])
|
19
|
-
data
|
20
|
-
render json: { success: true, data: data }
|
21
|
-
end
|
22
|
-
|
23
|
-
def create
|
24
|
-
obj = Cats::Core::Location.new(model_params)
|
25
|
-
if obj.save
|
26
|
-
data = ActiveModelSerializers::SerializableResource.new(obj)
|
27
|
-
render json: { success: true, data: data }, status: :created
|
28
|
-
else
|
29
|
-
render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def update
|
34
|
-
if @location.update(model_params)
|
35
|
-
data = ActiveModelSerializers::SerializableResource.new(@location)
|
36
|
-
render json: { success: true, data: data }
|
37
|
-
else
|
38
|
-
render json: { success: false, error: @location.errors.full_messages[0] }, status: :unprocessable_entity
|
39
|
-
end
|
13
|
+
render json: { success: true, data: serialize(parent.children) }
|
40
14
|
end
|
41
15
|
|
42
16
|
private
|
43
17
|
|
44
|
-
def set_location
|
45
|
-
@location = Cats::Core::Location.find(params[:id])
|
46
|
-
end
|
47
|
-
|
48
18
|
def model_params
|
49
19
|
params.require(:payload).permit(:code, :name, :location_type, :description, :parent_id)
|
50
20
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class ReceiptTransactionsController < ApplicationController
|
4
|
+
include Common
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def model_params
|
9
|
+
params.require(:payload).permit(:source_id, :destination_id, :transaction_date, :quantity)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -8,6 +8,24 @@ module Cats
|
|
8
8
|
render json: { success: true, data: serialize(receipts) }
|
9
9
|
end
|
10
10
|
|
11
|
+
def start_stacking
|
12
|
+
receipt = Cats::Core::Receipt.find(params[:id])
|
13
|
+
service = ReceiptService.new
|
14
|
+
result = service.start_stacking(receipt)
|
15
|
+
render json: { success: true, data: serialize(result) }
|
16
|
+
rescue StandardError => e
|
17
|
+
render json: { success: false, error: e.message }
|
18
|
+
end
|
19
|
+
|
20
|
+
def stack
|
21
|
+
receipt = Cats::Core::Receipt.find(params[:id])
|
22
|
+
service = ReceiptService.new
|
23
|
+
result = service.stack(receipt)
|
24
|
+
render json: { success: true, data: serialize(result) }
|
25
|
+
rescue StandardError => e
|
26
|
+
render json: { success: false, error: e.message }
|
27
|
+
end
|
28
|
+
|
11
29
|
private
|
12
30
|
|
13
31
|
def model_params
|
@@ -5,6 +5,16 @@ module Cats
|
|
5
5
|
|
6
6
|
validates :reference_no, presence: true, uniqueness: true
|
7
7
|
validates :gift_date, presence: true
|
8
|
+
|
9
|
+
after_create :update_donation
|
10
|
+
|
11
|
+
def update_donation
|
12
|
+
donation = self.donation
|
13
|
+
return if donation.active
|
14
|
+
|
15
|
+
donation.active = true
|
16
|
+
donation.save!
|
17
|
+
end
|
8
18
|
end
|
9
19
|
end
|
10
20
|
end
|
@@ -8,6 +8,16 @@ module Cats
|
|
8
8
|
validates :reference_no, uniqueness: true
|
9
9
|
|
10
10
|
delegate(:name, to: :commodity_category, prefix: true)
|
11
|
+
|
12
|
+
after_create :update_donation
|
13
|
+
|
14
|
+
def update_donation
|
15
|
+
donation = self.donation
|
16
|
+
return if donation.active
|
17
|
+
|
18
|
+
donation.active = true
|
19
|
+
donation.save!
|
20
|
+
end
|
11
21
|
end
|
12
22
|
end
|
13
23
|
end
|
@@ -4,10 +4,13 @@ module Cats
|
|
4
4
|
# Receipt status
|
5
5
|
DRAFT = 'Draft'.freeze
|
6
6
|
CONFIRMED = 'Confirmed'.freeze
|
7
|
-
|
7
|
+
STACKING = 'Stacking'.freeze
|
8
|
+
STACKED = 'Stacked'.freeze
|
9
|
+
RECEIPT_STATUSES = [DRAFT, CONFIRMED, STACKING, STACKED].freeze
|
8
10
|
|
9
11
|
belongs_to :dispatch
|
10
12
|
belongs_to :prepared_by, class_name: 'Cats::Core::User'
|
13
|
+
has_many :receipt_transactions, foreign_key: :source_id
|
11
14
|
|
12
15
|
validates :quantity, :commodity_status, :status, presence: true
|
13
16
|
validates :quantity, numericality: { greater_than: 0 }
|
@@ -21,19 +24,26 @@ module Cats
|
|
21
24
|
def validate_dispatch_status
|
22
25
|
return unless dispatch
|
23
26
|
|
24
|
-
|
27
|
+
statuses = [Cats::Core::Dispatch::STARTED, Cats::Core::Dispatch::RECEIVED]
|
28
|
+
return if statuses.include?(dispatch.dispatch_status)
|
25
29
|
|
26
|
-
errors.add(:dispatch, '
|
30
|
+
errors.add(:dispatch, 'should be in "Started" state.')
|
27
31
|
end
|
28
32
|
|
29
33
|
def validate_total_quantity
|
30
34
|
return unless dispatch && quantity
|
31
35
|
|
32
|
-
received =
|
33
|
-
|
34
|
-
|
36
|
+
received = dispatch.receipts.sum(:quantity)
|
37
|
+
diff = dispatch.quantity - received
|
38
|
+
if new_record?
|
39
|
+
return if quantity <= diff
|
35
40
|
|
36
|
-
|
41
|
+
errors.add(:quantity, "total is higher than dispatch quantity (Max = #{diff}).")
|
42
|
+
else
|
43
|
+
return unless diff.negative?
|
44
|
+
|
45
|
+
errors.add(:quantity, "total is higher than dispatch quantity (Max = #{diff.abs}).")
|
46
|
+
end
|
37
47
|
end
|
38
48
|
end
|
39
49
|
end
|
@@ -12,12 +12,14 @@ 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
|
15
|
+
validate :validate_quantity, unless: :skip_quantity_validation
|
16
16
|
|
17
17
|
def validate_quantity
|
18
18
|
return unless quantity.present? && source.present?
|
19
19
|
|
20
|
-
|
20
|
+
total = self.class.where(source: source).sum(:quantity)
|
21
|
+
diff = source.quantity - total
|
22
|
+
errors.add(:quantity, "total is higher than source quantity (Max = #{diff}).") if quantity > diff
|
21
23
|
end
|
22
24
|
|
23
25
|
def commit
|
@@ -27,10 +29,23 @@ module Cats
|
|
27
29
|
source.save
|
28
30
|
destination.save
|
29
31
|
self.status = COMMITTED
|
30
|
-
save
|
32
|
+
save!
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
36
|
+
def skip_quantity_validation
|
37
|
+
# Quantity validation should be skipped if we are commiting transactions.
|
38
|
+
(
|
39
|
+
instance_of?(Cats::Core::DispatchTransaction) &&
|
40
|
+
destination &&
|
41
|
+
destination.dispatch_status == Cats::Core::Dispatch::STARTED
|
42
|
+
) || (
|
43
|
+
instance_of?(Cats::Core::ReceiptTransaction) &&
|
44
|
+
source &&
|
45
|
+
source.status == Cats::Core::Receipt::STACKING
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
34
49
|
def set_status
|
35
50
|
return unless new_record?
|
36
51
|
|
@@ -40,7 +40,7 @@ module Cats
|
|
40
40
|
dispatch
|
41
41
|
end
|
42
42
|
|
43
|
-
def search(user)
|
43
|
+
def search(user, status)
|
44
44
|
details = user.details
|
45
45
|
|
46
46
|
unless details['stores'] || details['warehouse'] || details['hub']
|
@@ -54,12 +54,12 @@ module Cats
|
|
54
54
|
dispatches = Cats::Core::Dispatch.joins(:allocation_item)
|
55
55
|
.where(
|
56
56
|
allocation_item: { destination: hub },
|
57
|
-
dispatch_status:
|
57
|
+
dispatch_status: status
|
58
58
|
).or(
|
59
59
|
Cats::Core::Dispatch.joins(:allocation_item)
|
60
60
|
.where(
|
61
61
|
allocation_item: { destination: warehouse },
|
62
|
-
dispatch_status:
|
62
|
+
dispatch_status: status
|
63
63
|
)
|
64
64
|
)
|
65
65
|
elsif details['warehouse']
|
@@ -68,12 +68,12 @@ module Cats
|
|
68
68
|
dispatches = Cats::Core::Dispatch.joins(:allocation_item)
|
69
69
|
.where(
|
70
70
|
allocation_item: { destination: hub },
|
71
|
-
dispatch_status:
|
71
|
+
dispatch_status: status
|
72
72
|
).or(
|
73
73
|
Cats::Core::Dispatch.joins(:allocation_item)
|
74
74
|
.where(
|
75
75
|
allocation_item: { destination: warehouse },
|
76
|
-
dispatch_status:
|
76
|
+
dispatch_status: status
|
77
77
|
)
|
78
78
|
)
|
79
79
|
elsif details['hub']
|
@@ -81,7 +81,7 @@ module Cats
|
|
81
81
|
dispatches = Cats::Core::Dispatch.joins(:allocation_item)
|
82
82
|
.where(
|
83
83
|
allocation_item: { destination: hub },
|
84
|
-
dispatch_status:
|
84
|
+
dispatch_status: status
|
85
85
|
)
|
86
86
|
end
|
87
87
|
dispatches
|
@@ -126,7 +126,7 @@ module Cats
|
|
126
126
|
dispatch.dispatch_status = Cats::Core::Dispatch::RECEIVED
|
127
127
|
dispatch.receipts.each { |r| r.status = Cats::Core::Receipt::CONFIRMED }
|
128
128
|
dispatch.save
|
129
|
-
dispatch.receipts.each(&:save)
|
129
|
+
dispatch.receipts.each(&:save!)
|
130
130
|
end
|
131
131
|
|
132
132
|
dispatch
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class ReceiptService
|
4
|
+
def start_stacking(receipt)
|
5
|
+
raise(StandardError, 'Receipt should be confirmed.') unless receipt.status == Cats::Core::Receipt::CONFIRMED
|
6
|
+
|
7
|
+
raise(StandardError, 'There are no stack assignments in receipt.') if receipt.receipt_transactions.count.zero?
|
8
|
+
|
9
|
+
receipt.status = Cats::Core::Receipt::STACKING
|
10
|
+
receipt.save!
|
11
|
+
receipt
|
12
|
+
end
|
13
|
+
|
14
|
+
def stack(receipt)
|
15
|
+
unless receipt.status == Cats::Core::Receipt::STACKING
|
16
|
+
raise(StandardError, 'Receipt should be in stacking state.')
|
17
|
+
end
|
18
|
+
|
19
|
+
receipt.status = Cats::Core::Receipt::STACKED
|
20
|
+
stacks = receipt.receipt_transactions.map(&:destination)
|
21
|
+
stacks.each { |stack| stack.stack_status = Cats::Core::Stack::ALLOCATED }
|
22
|
+
|
23
|
+
Cats::Core::Receipt.transaction do
|
24
|
+
receipt.receipt_transactions.each(&:commit)
|
25
|
+
stacks.each(&:save!)
|
26
|
+
receipt.save!
|
27
|
+
end
|
28
|
+
receipt
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/config/routes.rb
CHANGED
@@ -66,5 +66,11 @@ Cats::Core::Engine.routes.draw do
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
resources :dispatch_transactions, except: %i[new edit destroy]
|
69
|
-
resources :receipts, except: %i[index new edit destroy]
|
69
|
+
resources :receipts, except: %i[index new edit destroy] do
|
70
|
+
member do
|
71
|
+
post 'start_stacking'
|
72
|
+
post 'stack'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
resources :receipt_transactions, except: %i[new edit destroy]
|
70
76
|
end
|
data/lib/cats/core/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :receipt, class: 'Cats::Core::Receipt' do
|
3
3
|
dispatch factory: :dispatch, dispatch_status: Cats::Core::Dispatch::STARTED
|
4
|
-
quantity {
|
4
|
+
quantity { 50 }
|
5
5
|
commodity_status { Cats::Core::Commodity::GOOD }
|
6
6
|
status { Cats::Core::Receipt::DRAFT }
|
7
7
|
remark { FFaker::Name.name }
|
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.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henock L.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -225,6 +225,7 @@ files:
|
|
225
225
|
- app/controllers/cats/core/locations_controller.rb
|
226
226
|
- app/controllers/cats/core/menus_controller.rb
|
227
227
|
- app/controllers/cats/core/notifications_controller.rb
|
228
|
+
- app/controllers/cats/core/receipt_transactions_controller.rb
|
228
229
|
- app/controllers/cats/core/receipts_controller.rb
|
229
230
|
- app/controllers/cats/core/roles_controller.rb
|
230
231
|
- app/controllers/cats/core/spaces_controller.rb
|
@@ -277,11 +278,13 @@ files:
|
|
277
278
|
- app/serializers/cats/core/dispatch_transaction_serializer.rb
|
278
279
|
- app/serializers/cats/core/location_serializer.rb
|
279
280
|
- app/serializers/cats/core/receipt_serializer.rb
|
281
|
+
- app/serializers/cats/core/receipt_transaction_serializer.rb
|
280
282
|
- app/serializers/cats/core/role_menu_serializer.rb
|
281
283
|
- app/serializers/cats/core/unit_of_measure_serializer.rb
|
282
284
|
- app/services/cats/core/dispatch_service.rb
|
283
285
|
- app/services/cats/core/menu_service.rb
|
284
286
|
- app/services/cats/core/notification_service.rb
|
287
|
+
- app/services/cats/core/receipt_service.rb
|
285
288
|
- app/services/cats/core/space_service.rb
|
286
289
|
- app/services/cats/core/token_auth_service.rb
|
287
290
|
- config/routes.rb
|