cats_core 1.1.24 → 1.1.28

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e1e8fc9828a237ea12abdb6c0cf964aa9e0801ea7c5cb95c638071363c728b6
4
- data.tar.gz: 2bc4c46c50608f1c12e99f4dbb50562bde3d255922bfb09fa905e15e24ed277e
3
+ metadata.gz: 3bb7f4884a8008cb1804e3b27f2dd5794209ea373d7a417a97efba3e4999fd2c
4
+ data.tar.gz: d584449483c92b6c6b012de61fbeb89f330544fd1bba69737ff4bbc0fff5acae
5
5
  SHA512:
6
- metadata.gz: d66571c610864eda20aea1815fef61697bf83d8cba9063de6623914cdbfdd66d9160bc36575d8e4e688076c813f5982ad6623b8cbc0302340cc42fa35f0eaccc
7
- data.tar.gz: 2e2205cfc0c14723a269dc4e7d9f4e0d09c67234ab8375a403c05c35ec05c37ec2027acff491b82df87b85c93aa0c5993f4352ea2988d9efc28f5cd28a3a242b
6
+ metadata.gz: 354676867bc3fa31abb3e368791e70e3ef97af8efe4900e55aa38200b0a3ca5cefb6c0b53ecd937df97eccbf90f86e3611956027505e954f9dd94436356cd382
7
+ data.tar.gz: d804eb6c6735fc5179d3a48408a1b25be1b04a3e7fa9f323648a34051f2c1d64ed9f41fe09a7f7e7b9accc1eaf6de544a32f74bfe8f4e768a8cf865d7d144a4e
@@ -8,6 +8,27 @@ module Cats
8
8
  render json: { success: true, data: serialize(transactions) }
9
9
  end
10
10
 
11
+ def create
12
+ p = model_params
13
+
14
+ # Look for a transaction with the same destination as incoming
15
+ transaction = Cats::Core::ReceiptTransaction.find_by(
16
+ source_id: p[:source_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
24
+
25
+ if transaction.save
26
+ render json: { success: true, data: serialize(transaction) }, status: :created
27
+ else
28
+ render json: { success: false, error: transaction.errors.full_messages[0] }, status: :unprocessable_entity
29
+ end
30
+ end
31
+
11
32
  private
12
33
 
13
34
  def model_params
@@ -49,9 +49,11 @@ module Cats
49
49
  def assign_role
50
50
  role = Cats::Core::Role.find(params[:role_id])
51
51
  @user.roles << role
52
- if role.name == 'warehouse_manager'
52
+
53
+ case role.name
54
+ when 'warehouse_manager'
53
55
  @user.add_detail(:warehouse, params[:warehouse_id])
54
- elsif role.name =='hub_manager'
56
+ when 'hub_manager'
55
57
  @user.add_detail(:hub, params[:hub_id])
56
58
  end
57
59
 
@@ -62,7 +64,7 @@ module Cats
62
64
  def revoke_role
63
65
  role = Cats::Core::Role.find(params[:role_id])
64
66
  @user.roles.delete(role)
65
- @user.remove_detail(role.name) if ['warehouse_manager', 'hub_manager'].include?(role.name)
67
+ @user.remove_detail(role.name) if %w[warehouse_manager hub_manager].include?(role.name)
66
68
  data = ActiveModelSerializers::SerializableResource.new(role)
67
69
  render json: { success: true, data: data }
68
70
  end
@@ -5,6 +5,16 @@ module Cats
5
5
  belongs_to :destination, class_name: 'Cats::Core::Stack'
6
6
 
7
7
  delegate(:code, to: :destination, prefix: true)
8
+
9
+ def commit
10
+ ReceiptTransaction.transaction do
11
+ destination.quantity += quantity
12
+ destination.stack_status = Cats::Core::Stack::ALLOCATED
13
+ destination.save
14
+ self.status = COMMITTED
15
+ save!
16
+ end
17
+ end
8
18
  end
9
19
  end
10
20
  end
@@ -18,6 +18,9 @@ module Cats
18
18
  return unless quantity.present? && source.present?
19
19
 
20
20
  total = self.class.where(source: source).sum(:quantity)
21
+
22
+ total -= quantity_was if id
23
+
21
24
  diff = source.quantity - total
22
25
  errors.add(:quantity, "total is higher than source quantity (Max = #{diff}).") if quantity > diff
23
26
  end
@@ -1,3 +1,7 @@
1
- class CommodityCategorySerializer < ActiveModel::Serializer
2
- attributes :id, :code, :name, :description, :parent_id
1
+ module Cats
2
+ module Core
3
+ class CommodityCategorySerializer < ActiveModel::Serializer
4
+ attributes :id, :code, :name, :description, :parent_id
5
+ end
6
+ end
3
7
  end
@@ -1,3 +1,7 @@
1
- class CurrencySerializer < ActiveModel::Serializer
2
- attributes :id, :code, :name
1
+ module Cats
2
+ module Core
3
+ class CurrencySerializer < ActiveModel::Serializer
4
+ attributes :id, :code, :name
5
+ end
6
+ end
3
7
  end
@@ -1,8 +1,12 @@
1
- class DispatchSerializer < ActiveModel::Serializer
2
- attributes :id, :reference_no, :allocation_item_id, :transporter_id, :transporter_name, :plate_no, :driver_name,
3
- :driver_phone, :quantity, :remark, :prepared_by_id, :prepared_by_email, :dispatch_status, :destination
1
+ module Cats
2
+ module Core
3
+ class DispatchSerializer < ActiveModel::Serializer
4
+ attributes :id, :reference_no, :allocation_item_id, :transporter_id, :transporter_name, :plate_no, :driver_name,
5
+ :driver_phone, :quantity, :remark, :prepared_by_id, :prepared_by_email, :dispatch_status, :destination
4
6
 
5
- def destination
6
- object.allocation_item.destination.name
7
+ def destination
8
+ object.allocation_item.destination.name
9
+ end
10
+ end
7
11
  end
8
12
  end
@@ -1,4 +1,8 @@
1
- class DispatchTransactionSerializer < ActiveModel::Serializer
2
- attributes :id, :source_id, :source_code, :destination_id, :destination_reference_no, :quantity, :transaction_date,
3
- :status
1
+ module Cats
2
+ module Core
3
+ class DispatchTransactionSerializer < ActiveModel::Serializer
4
+ attributes :id, :source_id, :source_code, :destination_id, :destination_reference_no, :quantity, :transaction_date,
5
+ :status
6
+ end
7
+ end
4
8
  end
@@ -1,3 +1,7 @@
1
- class LocationSerializer < ActiveModel::Serializer
2
- attributes :id, :code, :name, :location_type, :description, :parent_id
1
+ module Cats
2
+ module Core
3
+ class LocationSerializer < ActiveModel::Serializer
4
+ attributes :id, :code, :name, :location_type, :description, :parent_id
5
+ end
6
+ end
3
7
  end
@@ -1,4 +1,8 @@
1
- class ReceiptSerializer < ActiveModel::Serializer
2
- attributes :id, :dispatch_id, :dispatch_reference_no, :commodity_status, :quantity, :status, :remark,
3
- :prepared_by_id, :prepared_by_email
1
+ module Cats
2
+ module Core
3
+ class ReceiptSerializer < ActiveModel::Serializer
4
+ attributes :id, :dispatch_id, :dispatch_reference_no, :commodity_status, :quantity, :status, :remark,
5
+ :prepared_by_id, :prepared_by_email
6
+ end
7
+ end
4
8
  end
@@ -1,8 +1,12 @@
1
- class ReceiptTransactionSerializer < ActiveModel::Serializer
2
- attributes :id, :source_id, :dispatch_reference, :destination_id, :destination_code, :quantity, :transaction_date,
3
- :status
1
+ module Cats
2
+ module Core
3
+ class ReceiptTransactionSerializer < ActiveModel::Serializer
4
+ attributes :id, :source_id, :dispatch_reference, :destination_id, :destination_code, :quantity, :transaction_date,
5
+ :status
4
6
 
5
- def dispatch_reference
6
- object.source.dispatch.reference_no
7
+ def dispatch_reference
8
+ object.source.dispatch.reference_no
9
+ end
10
+ end
7
11
  end
8
12
  end
@@ -1,3 +1,7 @@
1
- class RoleSerializer < ActiveModel::Serializer
2
- attributes :id, :name, :application_module_id
1
+ module Cats
2
+ module Core
3
+ class RoleSerializer < ActiveModel::Serializer
4
+ attributes :id, :name, :application_module_id
5
+ end
6
+ end
3
7
  end
@@ -1,3 +1,7 @@
1
- class UnitOfMeasureSerializer < ActiveModel::Serializer
2
- attributes :id, :abbreviation, :name, :unit_type
1
+ module Cats
2
+ module Core
3
+ class UnitOfMeasureSerializer < ActiveModel::Serializer
4
+ attributes :id, :abbreviation, :name, :unit_type
5
+ end
6
+ end
3
7
  end
@@ -1,3 +1,7 @@
1
- class UserSerializer < ActiveModel::Serializer
2
- attributes :id, :first_name, :last_name, :email, :phone_number, :active, :details, :application_module_id
1
+ module Cats
2
+ module Core
3
+ class UserSerializer < ActiveModel::Serializer
4
+ attributes :id, :first_name, :last_name, :email, :phone_number, :active, :details, :application_module_id
5
+ end
6
+ end
3
7
  end
@@ -17,14 +17,7 @@ module Cats
17
17
  end
18
18
 
19
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
20
+ receipt.receipt_transactions.each(&:commit)
28
21
  receipt
29
22
  end
30
23
  end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.1.24'.freeze
3
+ VERSION = '1.1.28'.freeze
4
4
  end
5
5
  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.1.24
4
+ version: 1.1.28
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-10-05 00:00:00.000000000 Z
11
+ date: 2021-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -409,7 +409,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
409
409
  - !ruby/object:Gem::Version
410
410
  version: '0'
411
411
  requirements: []
412
- rubygems_version: 3.2.15
412
+ rubygems_version: 3.2.22
413
413
  signing_key:
414
414
  specification_version: 4
415
415
  summary: Core module for CATS applications