cats_core 1.5.23 → 1.5.25

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: '0913c502d73b044d84e08daf43fb9fc7fb67df1a6fbda3ef7ca7748d610a1082'
4
- data.tar.gz: 2f9cec73382125463e3624d48f5f7f852097d90120c98579347a32ecb87df085
3
+ metadata.gz: 78f6d9a4f2c81fd8ba524a604d6e8bf4fc8429807bce72b8af05e93b1496c321
4
+ data.tar.gz: ba5e35b1b7b4e6b84ca9fe72ed81a756ae42e5d8b7584b61048586c53cc29d21
5
5
  SHA512:
6
- metadata.gz: d030d99a36bc3c42e0f1a906e10cde70bd4a52a816534cbfe87eed1050721f93d1eaf0e3a8a634cdcc199bf0188bd60a2aead8630aa797e6318b2a961f455861
7
- data.tar.gz: a0c790f3e8def0e808fd71df23b9473e1d78d079a5d15231b2bbaccb321412ed6b02a23afd7d60f01e50ddb582eb1a950603623f2a66ee51c29947bf134a864f
6
+ metadata.gz: 91d369fba469a5457a771c39ebafe8253f8f249609ffeaf4f0c1a953e5a29ec6b7411bfca0b66cb406a2471298b549669a5a8f424f5fbd082121bd199a98d03d
7
+ data.tar.gz: 9bee3cbd46f8255981c1bf9dd338f82783edc82b90f885a4a12d09d983a0aaa38069a9aed56dbc49f162c68559dc45d30e421d8237e2227dcf57ab56d38fdcdd
@@ -76,6 +76,13 @@ module Cats
76
76
  render json: {success: true, data: serialize(data)}
77
77
  end
78
78
 
79
+ def revert
80
+ data = set_object.revert
81
+ render json: {success: true, data: serialize(data)}
82
+ rescue StandardError => e
83
+ render json: {success: false, error: e.message}
84
+ end
85
+
79
86
  private
80
87
 
81
88
  def set_service
@@ -5,7 +5,8 @@ module Cats
5
5
 
6
6
  def index
7
7
  super do
8
- StackTransaction.joins({source: :store}, :unit)
8
+ StackTransaction.joins(source: :store)
9
+ .includes(:unit)
9
10
  .where(cats_core_stacks: {cats_core_stores: {warehouse_id: params[:id]}})
10
11
  end
11
12
  end
@@ -15,6 +16,12 @@ module Cats
15
16
  render json: {success: true, data: serialize(query.result)}
16
17
  end
17
18
 
19
+ def commit
20
+ transaction = set_object
21
+ transaction.commit
22
+ render json: {success: true, data: serialize(transaction)}
23
+ end
24
+
18
25
  private
19
26
 
20
27
  def model_params
@@ -54,6 +54,14 @@ module Cats
54
54
  save!
55
55
  end
56
56
 
57
+ def revert
58
+ raise(StandardError, "Dispatch has to be in approved state.") unless dispatch_status == Dispatch::APPROVED
59
+
60
+ self.dispatch_status = DRAFT
61
+ self.quantity = 0
62
+ save!
63
+ end
64
+
57
65
  def all_authorizations_confirmed?
58
66
  statuses = dispatch_authorizations.map(&:status).uniq
59
67
  return true if statuses.length == 1 && statuses[0] == Authorization::CONFIRMED
@@ -5,6 +5,8 @@ module Cats
5
5
  belongs_to :destination, class_name: "Cats::Core::Stack"
6
6
  belongs_to :unit, class_name: "Cats::Core::UnitOfMeasure"
7
7
 
8
+ validate :validate_commodity
9
+
8
10
  def validate_quantity
9
11
  return unless quantity.present? && source.present?
10
12
 
@@ -15,6 +17,25 @@ module Cats
15
17
 
16
18
  errors.add(:quantity, "total is higher than source quantity (Max = #{available}).") if quantity > available
17
19
  end
20
+
21
+ def validate_commodity
22
+ return unless source && destination
23
+
24
+ return if source.commodity.batch_no == destination.commodity.batch_no
25
+
26
+ errors.add(:commodity, "batch number should be the same.")
27
+ end
28
+
29
+ def commit
30
+ StackTransaction.transaction do
31
+ source.quantity -= UnitConversion.convert(unit, source.unit, quantity)
32
+ source.save!
33
+ destination.quantity += UnitConversion.convert(unit, destination.unit, quantity)
34
+ destination.save!
35
+ self.status = COMMITTED
36
+ save!
37
+ end
38
+ end
18
39
  end
19
40
  end
20
41
  end
@@ -14,6 +14,7 @@ module Cats
14
14
  Commodity with the following details has been dispatched to you:
15
15
  Authorization no. = #{dispatch.dispatch_plan_item.reference_no}
16
16
  Dispatch Ref. = #{dispatch.reference_no}
17
+ Shipping Ref. = #{commodity.shipping_reference}
17
18
  Batch No. = #{commodity.batch_no}
18
19
  Commodity = #{commodity.name}
19
20
  Allocated Quantity = #{dispatch.dispatch_plan_item.quantity}
@@ -0,0 +1,7 @@
1
+ module Cats
2
+ module Core
3
+ class StackTransactionSerializer < ActiveModel::Serializer
4
+ attributes :id, :source_id, :destination_id, :quantity, :transaction_date, :status, :unit_id, :unit_abbreviation
5
+ end
6
+ end
7
+ end
data/config/routes.rb CHANGED
@@ -122,6 +122,7 @@ Cats::Core::Engine.routes.draw do
122
122
  get "receipts", controller: :receipts, action: :index
123
123
  get "commodity"
124
124
  post "approve"
125
+ post "revert"
125
126
  post "start"
126
127
  post "confirm"
127
128
  post "start_with_pin"
@@ -192,7 +193,11 @@ Cats::Core::Engine.routes.draw do
192
193
  resources :dispatch_transactions, except: %i[index new edit destroy]
193
194
  post "/receipt_transactions/filter", controller: :receipt_transactions, action: :filter
194
195
  resources :receipt_transactions, except: %i[index new edit destroy]
195
- resources :stack_transactions, except: %i[index new edit destroy]
196
+ resources :stack_transactions, except: %i[index new edit destroy] do
197
+ member do
198
+ post "commit"
199
+ end
200
+ end
196
201
  resources :lost_commodities, except: %i[index destroy]
197
202
  get "/plans/:id/round_plans", controller: :round_plans, action: :index, as: :round_plans_plan
198
203
 
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = "1.5.23".freeze
3
+ VERSION = "1.5.25".freeze
4
4
  end
5
5
  end
@@ -1,10 +1,14 @@
1
1
  FactoryBot.define do
2
2
  factory :stack_transaction, class: "Cats::Core::StackTransaction" do
3
- source factory: :stack
4
- destination factory: :stack
3
+ transient do
4
+ unit_of_measure { create(:unit_of_measure) }
5
+ commodity { create(:commodity, unit: unit_of_measure) }
6
+ end
7
+ source { association :stack, commodity: commodity }
8
+ destination { association :stack, commodity: commodity }
5
9
  transaction_date { Date.today }
6
10
  quantity { 25 }
7
- unit { source.unit }
11
+ unit { unit_of_measure }
8
12
  status { Cats::Core::Transaction::DRAFT }
9
13
  end
10
14
  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.5.23
4
+ version: 1.5.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-29 00:00:00.000000000 Z
11
+ date: 2023-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -428,6 +428,7 @@ files:
428
428
  - app/serializers/cats/core/round_plan_serializer.rb
429
429
  - app/serializers/cats/core/route_serializer.rb
430
430
  - app/serializers/cats/core/stack_serializer.rb
431
+ - app/serializers/cats/core/stack_transaction_serializer.rb
431
432
  - app/serializers/cats/core/store_serializer.rb
432
433
  - app/serializers/cats/core/swap_serializer.rb
433
434
  - app/serializers/cats/core/transporter_serializer.rb