cats_core 1.5.23 → 1.5.24

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: e90178cd66acd3f96313a3663036ba07bbf157e092e672adc393d840f701cfde
4
+ data.tar.gz: 7236c8485554e65bc5058bc600bfe25b38465b5d760823c3e96aec29c37ae951
5
5
  SHA512:
6
- metadata.gz: d030d99a36bc3c42e0f1a906e10cde70bd4a52a816534cbfe87eed1050721f93d1eaf0e3a8a634cdcc199bf0188bd60a2aead8630aa797e6318b2a961f455861
7
- data.tar.gz: a0c790f3e8def0e808fd71df23b9473e1d78d079a5d15231b2bbaccb321412ed6b02a23afd7d60f01e50ddb582eb1a950603623f2a66ee51c29947bf134a864f
6
+ metadata.gz: 80fff7d2dae7ed8e2d0fe77339bc0dbcd433d1fba6be6083e0c1e3b118c222912a957c0eee129908016a1fd7b25b1f4c4c931b8ef632fe12943d5b5facd620ce
7
+ data.tar.gz: '0765604991129318a519ad3960f32a43582f561492972264b027dda9846d87c1255c3009743a3f493386abda67ca9c373184f1d809b06ce5109017a1b96a6da4'
@@ -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
@@ -15,6 +15,12 @@ module Cats
15
15
  render json: {success: true, data: serialize(query.result)}
16
16
  end
17
17
 
18
+ def commit
19
+ transaction = set_object
20
+ transaction.commit
21
+ render json: {success: true, data: serialize(transaction)}
22
+ end
23
+
18
24
  private
19
25
 
20
26
  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}
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.24".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.24
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-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers