cats_core 1.4.7 → 1.4.10
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/access_controller.rb +2 -2
- data/app/controllers/cats/core/application_controller.rb +2 -2
- data/app/controllers/cats/core/commodities_controller.rb +2 -15
- data/app/controllers/cats/core/commodity_categories_controller.rb +8 -39
- data/app/controllers/cats/core/dispatch_plan_items_controller.rb +4 -3
- data/app/controllers/cats/core/dispatch_plans_controller.rb +3 -3
- data/app/controllers/cats/core/dispatch_transactions_controller.rb +3 -2
- data/app/controllers/cats/core/dispatches_controller.rb +16 -20
- data/app/controllers/cats/core/locations_controller.rb +5 -4
- data/app/controllers/cats/core/lost_commodities_controller.rb +3 -2
- data/app/controllers/cats/core/monthly_plans_controller.rb +5 -4
- data/app/controllers/cats/core/notifications_controller.rb +1 -0
- data/app/controllers/cats/core/receipt_transactions_controller.rb +16 -18
- data/app/controllers/cats/core/receipts_controller.rb +9 -13
- data/app/controllers/cats/core/roles_controller.rb +7 -7
- data/app/controllers/cats/core/routes_controller.rb +1 -1
- data/app/controllers/cats/core/stacks_controller.rb +3 -2
- data/app/controllers/cats/core/transporters_controller.rb +2 -2
- data/app/controllers/cats/core/unit_of_measures_controller.rb +1 -37
- data/app/controllers/cats/core/users_controller.rb +33 -44
- data/app/controllers/concerns/cats/core/common.rb +23 -6
- data/app/models/cats/core/commodity.rb +9 -0
- data/app/models/cats/core/transport_order.rb +24 -0
- data/app/models/cats/core/transport_order_item.rb +25 -0
- data/app/models/cats/core/transport_requisition.rb +28 -0
- data/db/migrate/20220506082329_create_cats_core_transport_orders.rb +21 -0
- data/db/migrate/20220506083042_create_cats_core_transport_order_items.rb +33 -0
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/transport_order_items.rb +10 -0
- data/spec/factories/cats/core/transport_orders.rb +13 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c497f5ed7c7fd9a82dd7a8f2450db08ab9e6ea307cfebf448819c15affe9baa
|
4
|
+
data.tar.gz: 0c7514559659448cf6b1b83381b3eda706b37497b7fc2d4e2556430c50cfe21a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cda6953720eb9492fd45083008ab61c38dc28ed1d7f1995f882335725d9f2beeb07b4e1bf1b012eddb6639bce628c6c3e98c939fe6ce59d18ad450d91bd17ffc
|
7
|
+
data.tar.gz: 8785eba470967b8c6b765363c9c88d27270e482a1196decc995182030a6448160590eabe0bb696fabcdceed73e59f17cfffd2c6edb88d9870b4c45fe496652e7
|
@@ -4,7 +4,7 @@ module Cats
|
|
4
4
|
skip_before_action :authenticate, only: [:login]
|
5
5
|
|
6
6
|
def login
|
7
|
-
user =
|
7
|
+
user = User.find_by(email: auth_params[:email])
|
8
8
|
if user
|
9
9
|
if user.authenticate(auth_params[:password])
|
10
10
|
roles = user.roles.map(&:name)
|
@@ -18,7 +18,7 @@ module Cats
|
|
18
18
|
id: user.id, email: user.email, first_name: user.first_name, last_name: user.last_name, roles: roles,
|
19
19
|
details: user.details
|
20
20
|
}
|
21
|
-
jwt =
|
21
|
+
jwt = TokenAuthService.issue(payload)
|
22
22
|
render json: { token: jwt, user: payload }
|
23
23
|
else
|
24
24
|
render json: { error: 'Invalid password.' }, status: 400
|
@@ -6,7 +6,7 @@ module Cats
|
|
6
6
|
def current_user
|
7
7
|
return if token.nil?
|
8
8
|
|
9
|
-
user =
|
9
|
+
user = User.find(auth['id'])
|
10
10
|
@current_user ||= user
|
11
11
|
end
|
12
12
|
|
@@ -27,7 +27,7 @@ module Cats
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def auth
|
30
|
-
|
30
|
+
TokenAuthService.decode(token)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -4,28 +4,15 @@ module Cats
|
|
4
4
|
include Common
|
5
5
|
|
6
6
|
def approve
|
7
|
-
commodity =
|
7
|
+
commodity = Commodity.find(params[:id])
|
8
8
|
result = commodity.approve
|
9
9
|
render json: { success: result, data: serialize(commodity) }
|
10
10
|
rescue StandardError => e
|
11
11
|
render json: { success: false, error: e.message }
|
12
12
|
end
|
13
13
|
|
14
|
-
def update
|
15
|
-
if @obj.status == Cats::Core::Commodity::APPROVED
|
16
|
-
render json: { success: false, error: 'An approved record cannot be edited.' }
|
17
|
-
return
|
18
|
-
end
|
19
|
-
|
20
|
-
if @obj.update(model_params)
|
21
|
-
render json: { success: true, data: serialize(@obj) }
|
22
|
-
else
|
23
|
-
render json: { success: false, error: @obj.errors.full_messages[0] }, status: :unprocessable_entity
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
14
|
def filter
|
28
|
-
query =
|
15
|
+
query = Commodity.ransack(params[:q])
|
29
16
|
render json: { success: true, data: serialize(query.result) }
|
30
17
|
end
|
31
18
|
|
@@ -1,62 +1,31 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class CommodityCategoriesController < ApplicationController
|
4
|
-
|
4
|
+
include Common
|
5
5
|
|
6
6
|
def index
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
super do
|
8
|
+
CommodityCategory.all.reject(&:has_children?)
|
9
|
+
end
|
10
10
|
end
|
11
11
|
|
12
12
|
def all
|
13
|
-
data =
|
13
|
+
data = CommodityCategory.all
|
14
14
|
render json: { success: true, data: data }
|
15
15
|
end
|
16
16
|
|
17
17
|
def root
|
18
|
-
data =
|
18
|
+
data = CommodityCategory.roots
|
19
19
|
render json: { success: true, data: serialize(data) }
|
20
20
|
end
|
21
21
|
|
22
|
-
def show
|
23
|
-
data = ActiveModelSerializers::SerializableResource.new(@commodity_category)
|
24
|
-
render json: { success: true, data: data }
|
25
|
-
end
|
26
|
-
|
27
22
|
def children
|
28
|
-
parent =
|
29
|
-
data
|
30
|
-
render json: { success: true, data: data }
|
31
|
-
end
|
32
|
-
|
33
|
-
def create
|
34
|
-
obj = Cats::Core::CommodityCategory.new(model_params)
|
35
|
-
if obj.save
|
36
|
-
data = ActiveModelSerializers::SerializableResource.new(obj)
|
37
|
-
render json: { success: true, data: data }, status: :created
|
38
|
-
else
|
39
|
-
render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def update
|
44
|
-
if @commodity_category.update(model_params)
|
45
|
-
data = ActiveModelSerializers::SerializableResource.new(@commodity_category)
|
46
|
-
render json: { success: true, data: data }
|
47
|
-
else
|
48
|
-
render json: {
|
49
|
-
success: false, error: @commodity_category.errors.full_messages[0]
|
50
|
-
}, status: :unprocessable_entity
|
51
|
-
end
|
23
|
+
parent = CommodityCategory.find(params[:id])
|
24
|
+
render json: { success: true, data: serialize(parent.children) }
|
52
25
|
end
|
53
26
|
|
54
27
|
private
|
55
28
|
|
56
|
-
def set_commodity_category
|
57
|
-
@commodity_category = Cats::Core::CommodityCategory.find(params[:id])
|
58
|
-
end
|
59
|
-
|
60
29
|
def model_params
|
61
30
|
params.require('payload').permit(:code, :name, :description, :parent_id)
|
62
31
|
end
|
@@ -4,12 +4,13 @@ module Cats
|
|
4
4
|
include Common
|
5
5
|
|
6
6
|
def index
|
7
|
-
|
8
|
-
|
7
|
+
super do
|
8
|
+
DispatchPlanItem.where(dispatch_plan_id: params[:id])
|
9
|
+
end
|
9
10
|
end
|
10
11
|
|
11
12
|
def filter
|
12
|
-
query =
|
13
|
+
query = DispatchPlanItem.ransack(params[:q])
|
13
14
|
render json: { success: true, data: serialize(query.result) }
|
14
15
|
end
|
15
16
|
|
@@ -4,12 +4,12 @@ module Cats
|
|
4
4
|
include Common
|
5
5
|
|
6
6
|
def plans_for_user
|
7
|
-
plans =
|
7
|
+
plans = DispatchPlan.where(prepared_by: current_user)
|
8
8
|
render json: { success: true, data: serialize(plans) }
|
9
9
|
end
|
10
10
|
|
11
11
|
def filter
|
12
|
-
query =
|
12
|
+
query = DispatchPlan.ransack(params[:q])
|
13
13
|
render json: { success: true, data: serialize(query.result) }
|
14
14
|
end
|
15
15
|
|
@@ -23,7 +23,7 @@ module Cats
|
|
23
23
|
|
24
24
|
def approve
|
25
25
|
service = DispatchPlanService.new
|
26
|
-
plan =
|
26
|
+
plan = DispatchPlan.find(params[:id])
|
27
27
|
plan = service.approve(plan)
|
28
28
|
render json: { success: true, data: serialize(plan) }
|
29
29
|
rescue StandardError => e
|
@@ -4,8 +4,9 @@ module Cats
|
|
4
4
|
include Common
|
5
5
|
|
6
6
|
def index
|
7
|
-
|
8
|
-
|
7
|
+
super do
|
8
|
+
DispatchTransaction.where(dispatch_id: params[:id])
|
9
|
+
end
|
9
10
|
end
|
10
11
|
|
11
12
|
# This end-point is used to create upstream dispatch transactions.
|
@@ -4,41 +4,41 @@ 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 commodity]
|
8
7
|
|
9
8
|
def index
|
10
|
-
|
11
|
-
|
9
|
+
super do
|
10
|
+
Dispatch.where(dispatch_plan_item_id: params[:id])
|
11
|
+
end
|
12
12
|
end
|
13
13
|
|
14
14
|
def create
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
else
|
21
|
-
render json: { success: false, error: dispatch.errors.full_messages[0] }, status: :unprocessable_entity
|
15
|
+
super do
|
16
|
+
dispatch = Dispatch.new(model_params)
|
17
|
+
dispatch.dispatch_status = Dispatch::DRAFT
|
18
|
+
dispatch.prepared_by = current_user
|
19
|
+
dispatch
|
22
20
|
end
|
23
21
|
end
|
24
22
|
|
25
23
|
def approve
|
26
|
-
|
27
|
-
|
24
|
+
dispatch = set_object
|
25
|
+
dispatch.approve
|
26
|
+
render json: { success: true, data: serialize(dispatch) }
|
28
27
|
rescue StandardError => e
|
29
28
|
render json: { success: false, error: e.message }
|
30
29
|
end
|
31
30
|
|
32
31
|
def start
|
33
|
-
dispatch = @service.start(
|
32
|
+
dispatch = @service.start(set_object)
|
34
33
|
render json: { success: true, data: serialize(dispatch) }
|
35
34
|
rescue StandardError => e
|
36
35
|
render json: { success: false, error: e.message }
|
37
36
|
end
|
38
37
|
|
39
38
|
def confirm
|
40
|
-
|
41
|
-
|
39
|
+
dispatch = set_object
|
40
|
+
dispatch.confirm
|
41
|
+
render json: { success: true, data: serialize(dispatch) }
|
42
42
|
rescue StandardError => e
|
43
43
|
render json: { success: false, error: e.message }
|
44
44
|
end
|
@@ -49,7 +49,7 @@ module Cats
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def commodity
|
52
|
-
data =
|
52
|
+
data = set_object.dispatch_plan_item.commodity
|
53
53
|
render json: { success: true, data: serialize(data) }
|
54
54
|
end
|
55
55
|
|
@@ -59,10 +59,6 @@ module Cats
|
|
59
59
|
@service = DispatchService.new
|
60
60
|
end
|
61
61
|
|
62
|
-
def set_dispatch
|
63
|
-
@dispatch = Cats::Core::Dispatch.find(params[:id])
|
64
|
-
end
|
65
|
-
|
66
62
|
def model_params
|
67
63
|
params.require(:payload).permit(:reference_no, :dispatch_plan_item_id, :transporter_id, :plate_no,
|
68
64
|
:driver_name, :driver_phone, :quantity, :remark)
|
@@ -4,17 +4,18 @@ module Cats
|
|
4
4
|
include Common
|
5
5
|
|
6
6
|
def index
|
7
|
-
|
8
|
-
|
7
|
+
super do
|
8
|
+
Location.where(location_type: params[:location_type])
|
9
|
+
end
|
9
10
|
end
|
10
11
|
|
11
12
|
def children
|
12
|
-
parent =
|
13
|
+
parent = Location.find(params[:id])
|
13
14
|
render json: { success: true, data: serialize(parent.children) }
|
14
15
|
end
|
15
16
|
|
16
17
|
def filter
|
17
|
-
query =
|
18
|
+
query = Location.ransack(params[:q])
|
18
19
|
render json: { success: true, data: serialize(query.result) }
|
19
20
|
end
|
20
21
|
|
@@ -6,17 +6,18 @@ module Cats
|
|
6
6
|
before_action :set_service, only: %i[generate remove_items generate_monthly_needs]
|
7
7
|
|
8
8
|
def index
|
9
|
-
|
10
|
-
|
9
|
+
super do
|
10
|
+
MonthlyPlan.where(plan: params[:id])
|
11
|
+
end
|
11
12
|
end
|
12
13
|
|
13
14
|
def filter
|
14
|
-
query =
|
15
|
+
query = MonthlyPlan.ransack(params[:q])
|
15
16
|
render json: { success: true, data: serialize(query.result) }
|
16
17
|
end
|
17
18
|
|
18
19
|
def approve
|
19
|
-
plan =
|
20
|
+
plan = MonthlyPlan.find(params[:id])
|
20
21
|
plan.approve
|
21
22
|
render json: { success: true, data: serialize(plan) }
|
22
23
|
rescue StandardError => e
|
@@ -2,6 +2,7 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class NotificationsController < ApplicationController
|
4
4
|
before_action :set_notification, only: %i[mark_as_read mark_as_unread]
|
5
|
+
|
5
6
|
def index
|
6
7
|
data = Notification.messages(current_user.notifications.newest_first)
|
7
8
|
render json: { success: true, data: data }
|
@@ -4,28 +4,26 @@ module Cats
|
|
4
4
|
include Common
|
5
5
|
|
6
6
|
def index
|
7
|
-
|
8
|
-
|
7
|
+
super do
|
8
|
+
ReceiptTransaction.where(receipt_id: params[:id])
|
9
|
+
end
|
9
10
|
end
|
10
11
|
|
11
12
|
def create
|
12
|
-
|
13
|
-
|
14
|
-
# Look for a transaction with the same destination as incoming
|
15
|
-
transaction = Cats::Core::ReceiptTransaction.find_by(
|
16
|
-
receipt_id: p[:receipt_id],
|
17
|
-
destination_id: p[:destination_id]
|
18
|
-
)
|
19
|
-
if transaction
|
20
|
-
transaction.quantity += p[:quantity]
|
21
|
-
else
|
22
|
-
transaction = Cats::Core::ReceiptTransaction.new(p)
|
23
|
-
end
|
13
|
+
super do
|
14
|
+
p = model_params
|
24
15
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
16
|
+
# Look for a transaction with the same destination as incoming
|
17
|
+
transaction = ReceiptTransaction.find_by(
|
18
|
+
receipt_id: p[:receipt_id],
|
19
|
+
destination_id: p[:destination_id]
|
20
|
+
)
|
21
|
+
if transaction
|
22
|
+
transaction.quantity += p[:quantity]
|
23
|
+
else
|
24
|
+
transaction = ReceiptTransaction.new(p)
|
25
|
+
end
|
26
|
+
transaction
|
29
27
|
end
|
30
28
|
end
|
31
29
|
|
@@ -4,25 +4,21 @@ module Cats
|
|
4
4
|
include Common
|
5
5
|
|
6
6
|
def index
|
7
|
-
|
8
|
-
|
7
|
+
super do
|
8
|
+
Receipt.where(dispatch_id: params[:id])
|
9
|
+
end
|
9
10
|
end
|
10
11
|
|
11
12
|
def create
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
render json: { success: true, data: serialize(receipt) }
|
17
|
-
else
|
18
|
-
render json: { success: false, error: receipt.errors.full_messages[0] }, status: :unprocessable_entity
|
13
|
+
super do
|
14
|
+
service = ReceiptService.new
|
15
|
+
receipt = service.init(model_params)
|
16
|
+
receipt
|
19
17
|
end
|
20
|
-
rescue StandardError => e
|
21
|
-
render json: { success: false, error: e.message }
|
22
18
|
end
|
23
19
|
|
24
20
|
def start_stacking
|
25
|
-
receipt =
|
21
|
+
receipt = Receipt.find(params[:id])
|
26
22
|
service = ReceiptService.new
|
27
23
|
result = service.start_stacking(receipt)
|
28
24
|
render json: { success: true, data: serialize(result) }
|
@@ -31,7 +27,7 @@ module Cats
|
|
31
27
|
end
|
32
28
|
|
33
29
|
def finish_stacking
|
34
|
-
receipt =
|
30
|
+
receipt = Receipt.find(params[:id])
|
35
31
|
service = ReceiptService.new
|
36
32
|
result = service.finish_stacking(receipt)
|
37
33
|
render json: { success: true, data: serialize(result) }
|
@@ -6,21 +6,21 @@ module Cats
|
|
6
6
|
before_action :set_role, only: [:users]
|
7
7
|
|
8
8
|
def index
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
super do
|
10
|
+
Role.joins(:application_module)
|
11
|
+
.where(cats_core_application_modules: { prefix: params[:prefix] })
|
12
|
+
end
|
12
13
|
end
|
13
14
|
|
14
15
|
def unassigned_roles
|
15
|
-
user =
|
16
|
-
roles =
|
16
|
+
user = User.find(params[:id])
|
17
|
+
roles = Role.where(application_module_id: user.application_module_id)
|
17
18
|
unassigned = roles - user.roles
|
18
19
|
render json: { success: true, data: serialize(unassigned) }
|
19
20
|
end
|
20
21
|
|
21
22
|
def users
|
22
|
-
data
|
23
|
-
render json: { success: true, data: data }
|
23
|
+
render json: { success: true, data: serialize(@role.users) }
|
24
24
|
end
|
25
25
|
|
26
26
|
private
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class TransportersController < ApplicationController
|
4
|
-
include
|
4
|
+
include Common
|
5
5
|
|
6
6
|
def filter
|
7
|
-
query =
|
7
|
+
query = Transporter.ransack(params[:q])
|
8
8
|
render json: { success: true, data: serialize(query.result) }
|
9
9
|
end
|
10
10
|
|
@@ -1,46 +1,10 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class UnitOfMeasuresController < ApplicationController
|
4
|
-
|
5
|
-
|
6
|
-
def index
|
7
|
-
data = ActiveModelSerializers::SerializableResource.new(Cats::Core::UnitOfMeasure.all)
|
8
|
-
render json: { success: true, data: data }
|
9
|
-
end
|
10
|
-
|
11
|
-
def show
|
12
|
-
data = ActiveModelSerializers::SerializableResource.new(@unit_of_measure)
|
13
|
-
render json: { success: true, data: data }
|
14
|
-
end
|
15
|
-
|
16
|
-
def create
|
17
|
-
obj = Cats::Core::UnitOfMeasure.new(model_params)
|
18
|
-
if obj.save
|
19
|
-
data = ActiveModelSerializers::SerializableResource.new(obj)
|
20
|
-
render json: { success: true, data: data }, status: :created
|
21
|
-
else
|
22
|
-
render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def update
|
27
|
-
if @unit_of_measure.update(model_params)
|
28
|
-
data = ActiveModelSerializers::SerializableResource.new(@unit_of_measure)
|
29
|
-
render json: { success: true, data: data }
|
30
|
-
else
|
31
|
-
render json: {
|
32
|
-
success: false,
|
33
|
-
error: @unit_of_measure.errors.full_messages[0]
|
34
|
-
}, status: :unprocessable_entity
|
35
|
-
end
|
36
|
-
end
|
4
|
+
include Common
|
37
5
|
|
38
6
|
private
|
39
7
|
|
40
|
-
def set_unit_of_measure
|
41
|
-
@unit_of_measure = Cats::Core::UnitOfMeasure.find(params[:id])
|
42
|
-
end
|
43
|
-
|
44
8
|
def model_params
|
45
9
|
params.require(:payload).permit(:abbreviation, :name, :unit_type)
|
46
10
|
end
|
@@ -3,95 +3,84 @@ module Cats
|
|
3
3
|
class UsersController < ApplicationController
|
4
4
|
include Common
|
5
5
|
|
6
|
-
before_action :set_user, only: %i[update roles assign_role revoke_role stores warehouse hub]
|
7
|
-
|
8
6
|
def index
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
super do
|
8
|
+
User.joins(:application_module).where(cats_core_application_modules: { prefix: params[:prefix] })
|
9
|
+
end
|
12
10
|
end
|
13
11
|
|
14
12
|
def create
|
15
|
-
|
16
|
-
|
13
|
+
super do
|
14
|
+
prefix = model_params[:application_prefix]
|
15
|
+
application_module = ApplicationModule.find_by(prefix: prefix)
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
render json: { success: true, data: serialize(obj) }, status: :created
|
22
|
-
else
|
23
|
-
render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
|
17
|
+
obj = User.new(model_params.except(:application_prefix))
|
18
|
+
obj.application_module = application_module
|
19
|
+
obj
|
24
20
|
end
|
25
21
|
end
|
26
22
|
|
27
23
|
def update
|
24
|
+
user = set_object
|
28
25
|
if model_params[:application_prefix]
|
29
26
|
prefix = model_params[:application_prefix]
|
30
|
-
application_module =
|
31
|
-
|
32
|
-
|
27
|
+
application_module = ApplicationModule.find_by(prefix: prefix)
|
28
|
+
user.assign_attributes(model_params.except(:application_prefix))
|
29
|
+
user.application_module = application_module
|
33
30
|
else
|
34
|
-
|
31
|
+
user.assign_attributes(model_params)
|
35
32
|
end
|
36
33
|
|
37
|
-
if
|
38
|
-
render json: { success: true, data: serialize(
|
34
|
+
if user.save
|
35
|
+
render json: { success: true, data: serialize(user) }
|
39
36
|
else
|
40
|
-
render json: { success: false, error:
|
37
|
+
render json: { success: false, error: user.errors.full_messages[0] }, status: :unprocessable_entity
|
41
38
|
end
|
42
39
|
end
|
43
40
|
|
44
41
|
def roles
|
45
|
-
data
|
46
|
-
render json: { success: true, data: data }
|
42
|
+
render json: { success: true, data: serialize(set_object.roles) }
|
47
43
|
end
|
48
44
|
|
49
45
|
def assign_role
|
50
|
-
role =
|
51
|
-
|
46
|
+
role = Role.find(params[:role_id])
|
47
|
+
user = set_object
|
48
|
+
user.roles << role
|
52
49
|
|
53
50
|
case role.name
|
54
51
|
when 'warehouse_manager'
|
55
|
-
|
52
|
+
user.add_detail(:warehouse, params[:warehouse_id])
|
56
53
|
when 'hub_manager'
|
57
|
-
|
54
|
+
user.add_detail(:hub, params[:hub_id])
|
58
55
|
when 'regional_manager'
|
59
|
-
|
56
|
+
user.add_detail(:region, params[:region_id])
|
60
57
|
end
|
61
58
|
|
62
|
-
data
|
63
|
-
render json: { success: true, data: data }
|
59
|
+
render json: { success: true, data: serialize(role) }
|
64
60
|
end
|
65
61
|
|
66
62
|
def revoke_role
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
render json: { success: true, data:
|
63
|
+
user = set_object
|
64
|
+
role = Role.find(params[:role_id])
|
65
|
+
user.roles.delete(role)
|
66
|
+
user.remove_detail(role.name) if %w[warehouse_manager hub_manager regional_manager].include?(role.name)
|
67
|
+
render json: { success: true, data: serialize(role) }
|
72
68
|
end
|
73
69
|
|
74
70
|
def stores
|
75
|
-
data
|
76
|
-
render json: { success: true, data: data }
|
71
|
+
render json: { success: true, data: serialize(set_object.stores) }
|
77
72
|
end
|
78
73
|
|
79
74
|
def warehouse
|
80
|
-
data
|
81
|
-
render json: { success: true, data: data }
|
75
|
+
render json: { success: true, data: serialize(set_object.warehouse) }
|
82
76
|
end
|
83
77
|
|
84
78
|
def hub
|
85
|
-
data
|
86
|
-
render json: { success: true, data: data }
|
79
|
+
render json: { success: true, data: serialize(set_object.hub) }
|
87
80
|
end
|
88
81
|
|
89
82
|
private
|
90
83
|
|
91
|
-
def set_user
|
92
|
-
@user = Cats::Core::User.find(params[:id])
|
93
|
-
end
|
94
|
-
|
95
84
|
def model_params
|
96
85
|
params.require(:payload).permit(
|
97
86
|
:first_name, :last_name, :email, :phone_number, :active, :password, :password_confirmation, :details,
|
@@ -9,8 +9,12 @@ module Cats
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def index
|
12
|
-
data =
|
13
|
-
|
12
|
+
data = if block_given?
|
13
|
+
yield
|
14
|
+
else
|
15
|
+
@clazz.all
|
16
|
+
end
|
17
|
+
render json: { success: true, data: serialize(data) }
|
14
18
|
end
|
15
19
|
|
16
20
|
def show
|
@@ -18,20 +22,33 @@ module Cats
|
|
18
22
|
end
|
19
23
|
|
20
24
|
def create
|
21
|
-
obj =
|
25
|
+
obj = if block_given?
|
26
|
+
yield
|
27
|
+
else
|
28
|
+
@clazz.new(model_params)
|
29
|
+
end
|
22
30
|
if obj.save
|
23
31
|
render json: { success: true, data: serialize(obj) }, status: :created
|
24
32
|
else
|
25
33
|
render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
|
26
34
|
end
|
35
|
+
rescue StandardError => e
|
36
|
+
render json: { success: false, error: e.message }
|
27
37
|
end
|
28
38
|
|
29
39
|
def update
|
30
|
-
if
|
31
|
-
|
40
|
+
obj = if block_given?
|
41
|
+
yield
|
42
|
+
else
|
43
|
+
obj = @obj
|
44
|
+
end
|
45
|
+
if obj.update(model_params)
|
46
|
+
render json: { success: true, data: serialize(obj) }
|
32
47
|
else
|
33
|
-
render json: { success: false, error:
|
48
|
+
render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
|
34
49
|
end
|
50
|
+
rescue StandardError => e
|
51
|
+
render json: { success: false, error: e.message }
|
35
52
|
end
|
36
53
|
|
37
54
|
private
|
@@ -37,6 +37,7 @@ module Cats
|
|
37
37
|
validates :volume_per_metric_ton, numericality: { greater_than: 0, allow_nil: true }
|
38
38
|
validates :arrival_status, presence: true, inclusion: { in: ARRIVAL_STATUSES }
|
39
39
|
validates :status, presence: true, inclusion: { in: STATUSES }
|
40
|
+
validate :validate_updateability, on: :update
|
40
41
|
|
41
42
|
delegate(:abbreviation, to: :unit_of_measure, prefix: 'unit')
|
42
43
|
delegate(:reference_no, to: :source, prefix: true)
|
@@ -45,6 +46,14 @@ module Cats
|
|
45
46
|
source.commodity_category.name
|
46
47
|
end
|
47
48
|
|
49
|
+
def validate_updateability
|
50
|
+
return unless status
|
51
|
+
|
52
|
+
return if status_changed?
|
53
|
+
|
54
|
+
errors.add(:base, 'Commodity cannot be updated because it is in approved state.') if status == APPROVED
|
55
|
+
end
|
56
|
+
|
48
57
|
def approve
|
49
58
|
raise(StandardError, 'Commodity already approved.') if status == APPROVED
|
50
59
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class TransportOrder < ApplicationRecord
|
4
|
+
DRAFT = 'Draft'.freeze
|
5
|
+
APPROVED = 'Approved'.freeze
|
6
|
+
STATUSES = [DRAFT, APPROVED].freeze
|
7
|
+
|
8
|
+
belongs_to :transport_requisition
|
9
|
+
belongs_to :prepared_by, class_name: 'Cats::Core::User'
|
10
|
+
belongs_to :approved_by, class_name: 'Cats::Core::User'
|
11
|
+
|
12
|
+
validates :status, presence: true, inclusion: { in: STATUSES }
|
13
|
+
validate :validate_against_requisition
|
14
|
+
|
15
|
+
def validate_against_requisition
|
16
|
+
return unless transport_requisition
|
17
|
+
|
18
|
+
return if transport_requisition.approved?
|
19
|
+
|
20
|
+
errors.add(:transport_requisition, 'is not approved.')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class TransportOrderItem < ApplicationRecord
|
4
|
+
belongs_to :transport_order
|
5
|
+
belongs_to :transporter
|
6
|
+
belongs_to :transport_requisition_item
|
7
|
+
belongs_to :transport_contract, optional: true
|
8
|
+
|
9
|
+
validates :order_date, :valid_for, presence: true
|
10
|
+
validates :valid_for, numericality: { greater_than: 0 }
|
11
|
+
validates :transport_requisition_item_id, uniqueness: true
|
12
|
+
validate :validate_requisition
|
13
|
+
|
14
|
+
def validate_requisition
|
15
|
+
return unless transport_requisition_item
|
16
|
+
|
17
|
+
return unless transport_order
|
18
|
+
|
19
|
+
return if transport_order.transport_requisition_id == transport_requisition_item.transport_requisition_id
|
20
|
+
|
21
|
+
errors.add(:transport_requisition_item, 'does not belong to the requisition of the order.')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -14,6 +14,7 @@ module Cats
|
|
14
14
|
|
15
15
|
validates :reference_no, presence: true, uniqueness: true
|
16
16
|
validates :status, presence: true, inclusion: { in: STATUSES }
|
17
|
+
validate :validate_status
|
17
18
|
|
18
19
|
delegate(:full_name, to: :requested_by, prefix: 'requestor')
|
19
20
|
delegate(:full_name, to: :approved_by, prefix: 'approver', allow_nil: true)
|
@@ -24,6 +25,33 @@ module Cats
|
|
24
25
|
quantities = transport_requisition_items.map { |item| UnitConversion.convert(item.unit, unit, item.quantity) }
|
25
26
|
quantities.sum
|
26
27
|
end
|
28
|
+
|
29
|
+
def approve
|
30
|
+
raise(StandardError, 'Transport requisition is already approved.') if status == APPROVED
|
31
|
+
|
32
|
+
begin
|
33
|
+
self.status = APPROVED
|
34
|
+
save!
|
35
|
+
self
|
36
|
+
rescue ActiveRecord::RecordInvalid => e
|
37
|
+
error = e.record.errors.full_messages_for(:status)[0]
|
38
|
+
raise(StandardError, error)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def approved?
|
43
|
+
status == APPROVED
|
44
|
+
end
|
45
|
+
|
46
|
+
def validate_status
|
47
|
+
return unless status
|
48
|
+
|
49
|
+
return if status == DRAFT
|
50
|
+
|
51
|
+
return if transport_requisition_items.count.positive?
|
52
|
+
|
53
|
+
errors.add(:status, 'cannot be set to "APPROVED" because the requisition has no items.') if status == APPROVED
|
54
|
+
end
|
27
55
|
end
|
28
56
|
end
|
29
57
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class CreateCatsCoreTransportOrders < ActiveRecord::Migration[7.0]
|
2
|
+
def change
|
3
|
+
create_table :cats_core_transport_orders do |t|
|
4
|
+
t.references :transport_requisition,
|
5
|
+
null: false,
|
6
|
+
index: { name: 'tr_on_to_indx' },
|
7
|
+
foreign_key: { to_table: :cats_core_transport_requisitions }
|
8
|
+
t.references :prepared_by,
|
9
|
+
null: false,
|
10
|
+
index: { name: 'pb_on_to_indx' },
|
11
|
+
foreign_key: { to_table: :cats_core_users }
|
12
|
+
t.references :approved_by,
|
13
|
+
null: false,
|
14
|
+
index: { name: 'ab_on_to_indx' },
|
15
|
+
foreign_key: { to_table: :cats_core_users }
|
16
|
+
t.string :status, null: false, default: 'Draft'
|
17
|
+
|
18
|
+
t.timestamps
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class CreateCatsCoreTransportOrderItems < ActiveRecord::Migration[7.0]
|
2
|
+
def change
|
3
|
+
create_table :cats_core_transport_order_items do |t|
|
4
|
+
t.references :transport_order,
|
5
|
+
null: false,
|
6
|
+
index: { name: 'to_on_toi_indx' },
|
7
|
+
foreign_key: { to_table: :cats_core_transport_orders }
|
8
|
+
t.references :transporter,
|
9
|
+
null: false,
|
10
|
+
index: { name: 'transporter_on_toi_indx' },
|
11
|
+
foreign_key: { to_table: :cats_core_transporters }
|
12
|
+
t.references :transport_contract,
|
13
|
+
null: true,
|
14
|
+
index: { name: 'tc_on_toi_indx' },
|
15
|
+
foreign_key: { to_table: :cats_core_transport_contracts }
|
16
|
+
t.references :transport_requisition_item,
|
17
|
+
null: false,
|
18
|
+
index: { name: 'tri_on_toi_indx' },
|
19
|
+
foreign_key: { to_table: :cats_core_transport_requisition_items }
|
20
|
+
t.date :order_date, null: false, default: Date.today
|
21
|
+
t.integer :valid_for, null: false, default: 10
|
22
|
+
|
23
|
+
t.timestamps
|
24
|
+
end
|
25
|
+
|
26
|
+
add_index(
|
27
|
+
:cats_core_transport_order_items,
|
28
|
+
:transport_requisition_item_id,
|
29
|
+
unique: true,
|
30
|
+
name: 'tri_on_toi_uniq_indx'
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
data/lib/cats/core/version.rb
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
FactoryBot.define do
|
2
|
+
factory :transport_order_item, class: 'Cats::Core::TransportOrderItem' do
|
3
|
+
transport_order
|
4
|
+
transporter
|
5
|
+
transport_contract
|
6
|
+
transport_requisition_item { transport_order.transport_requisition.transport_requisition_items.first }
|
7
|
+
order_date { Date.today }
|
8
|
+
valid_for { 10 }
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
FactoryBot.define do
|
2
|
+
factory :transport_order, class: 'Cats::Core::TransportOrder' do
|
3
|
+
transport_requisition do
|
4
|
+
requisition = create(:transport_requisition)
|
5
|
+
create(:transport_requisition_item, transport_requisition: requisition)
|
6
|
+
requisition.approve
|
7
|
+
requisition
|
8
|
+
end
|
9
|
+
prepared_by factory: :user
|
10
|
+
approved_by factory: :user
|
11
|
+
status { Cats::Core::TransportOrder::DRAFT }
|
12
|
+
end
|
13
|
+
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.10
|
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-
|
11
|
+
date: 2022-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -307,6 +307,8 @@ files:
|
|
307
307
|
- app/models/cats/core/transport_bid_item.rb
|
308
308
|
- app/models/cats/core/transport_contract.rb
|
309
309
|
- app/models/cats/core/transport_offer.rb
|
310
|
+
- app/models/cats/core/transport_order.rb
|
311
|
+
- app/models/cats/core/transport_order_item.rb
|
310
312
|
- app/models/cats/core/transport_plan.rb
|
311
313
|
- app/models/cats/core/transport_plan_item.rb
|
312
314
|
- app/models/cats/core/transport_requisition.rb
|
@@ -410,6 +412,8 @@ files:
|
|
410
412
|
- db/migrate/20220417105839_create_cats_core_transport_requisitions.rb
|
411
413
|
- db/migrate/20220417123835_create_cats_core_transport_requisition_items.rb
|
412
414
|
- db/migrate/20220417151821_create_cats_core_transport_requisition_details.rb
|
415
|
+
- db/migrate/20220506082329_create_cats_core_transport_orders.rb
|
416
|
+
- db/migrate/20220506083042_create_cats_core_transport_order_items.rb
|
413
417
|
- lib/cats/core.rb
|
414
418
|
- lib/cats/core/engine.rb
|
415
419
|
- lib/cats/core/version.rb
|
@@ -464,6 +468,8 @@ files:
|
|
464
468
|
- spec/factories/cats/core/transport_bids.rb
|
465
469
|
- spec/factories/cats/core/transport_contracts.rb
|
466
470
|
- spec/factories/cats/core/transport_offers.rb
|
471
|
+
- spec/factories/cats/core/transport_order_items.rb
|
472
|
+
- spec/factories/cats/core/transport_orders.rb
|
467
473
|
- spec/factories/cats/core/transport_plan_items.rb
|
468
474
|
- spec/factories/cats/core/transport_plans.rb
|
469
475
|
- spec/factories/cats/core/transport_requisition_details.rb
|