cats_core 1.1.2 → 1.1.6
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/dispatches_controller.rb +6 -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 +14 -6
- 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 +1 -1
- data/app/services/cats/core/receipt_service.rb +32 -0
- data/config/routes.rb +8 -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: dc868538b2dd7c7fc157b0fd2c78c79a38b868c60a12e0e1ce6662a7dac01e3a
|
4
|
+
data.tar.gz: d20518593e2a0bc565a47d2b426794c16790bf45f1650feb2c3a7550fb610637
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5447be874ddfaa36956f09550a313ce4078440e0b0be91ceb0cc5d8f035236c71f823ce6f4adf88efba0e4db44a047595e9a56fa84032fe3f3b7c14f9b602126
|
7
|
+
data.tar.gz: 44ab9de9141a4957e53f7739a761e1127940b0dfa813ea8503a579a4036b71a6e522a86b029facf406354d0d826e007d1260023ea4daa99e5531a15407288567
|
@@ -4,7 +4,7 @@ module Cats
|
|
4
4
|
include Common
|
5
5
|
|
6
6
|
before_action :set_service, only: %i[create_receipt_authorization approve start search confirm]
|
7
|
-
before_action :set_dispatch, only: %i[approve start confirm]
|
7
|
+
before_action :set_dispatch, only: %i[approve start confirm commodity]
|
8
8
|
|
9
9
|
def index
|
10
10
|
dispatches = Cats::Core::Dispatch.where(allocation_item_id: params[:id])
|
@@ -56,6 +56,11 @@ module Cats
|
|
56
56
|
render json: { success: true, data: serialize(data) }
|
57
57
|
end
|
58
58
|
|
59
|
+
def commodity
|
60
|
+
data = @dispatch.allocation_item.allocation.commodity
|
61
|
+
render json: { success: true, data: serialize(data) }
|
62
|
+
end
|
63
|
+
|
59
64
|
private
|
60
65
|
|
61
66
|
def set_service
|
@@ -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
|
@@ -10,6 +10,7 @@ module Cats
|
|
10
10
|
|
11
11
|
belongs_to :dispatch
|
12
12
|
belongs_to :prepared_by, class_name: 'Cats::Core::User'
|
13
|
+
has_many :receipt_transactions, foreign_key: :source_id
|
13
14
|
|
14
15
|
validates :quantity, :commodity_status, :status, presence: true
|
15
16
|
validates :quantity, numericality: { greater_than: 0 }
|
@@ -23,19 +24,26 @@ module Cats
|
|
23
24
|
def validate_dispatch_status
|
24
25
|
return unless dispatch
|
25
26
|
|
26
|
-
|
27
|
+
statuses = [Cats::Core::Dispatch::STARTED, Cats::Core::Dispatch::RECEIVED]
|
28
|
+
return if statuses.include?(dispatch.dispatch_status)
|
27
29
|
|
28
|
-
errors.add(:dispatch, '
|
30
|
+
errors.add(:dispatch, 'should be in "Started" state.')
|
29
31
|
end
|
30
32
|
|
31
33
|
def validate_total_quantity
|
32
34
|
return unless dispatch && quantity
|
33
35
|
|
34
|
-
received =
|
35
|
-
|
36
|
-
|
36
|
+
received = dispatch.receipts.sum(:quantity)
|
37
|
+
diff = dispatch.quantity - received
|
38
|
+
if new_record?
|
39
|
+
return if quantity <= diff
|
37
40
|
|
38
|
-
|
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
|
39
47
|
end
|
40
48
|
end
|
41
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
|
|
@@ -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
@@ -60,11 +60,18 @@ Cats::Core::Engine.routes.draw do
|
|
60
60
|
resources :dispatches, except: %i[index destroy] do
|
61
61
|
member do
|
62
62
|
get 'receipts', controller: :receipts, action: :index
|
63
|
+
get 'commodity'
|
63
64
|
post 'approve'
|
64
65
|
post 'start'
|
65
66
|
post 'confirm'
|
66
67
|
end
|
67
68
|
end
|
68
69
|
resources :dispatch_transactions, except: %i[new edit destroy]
|
69
|
-
resources :receipts, except: %i[index new edit destroy]
|
70
|
+
resources :receipts, except: %i[index new edit destroy] do
|
71
|
+
member do
|
72
|
+
post 'start_stacking'
|
73
|
+
post 'stack'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
resources :receipt_transactions, except: %i[new edit destroy]
|
70
77
|
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.6
|
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
|