cats_core 1.1.14 → 1.1.18

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: 849c78b04184a39a42337994d2cf68e4be874dff4e0420e34a890ce0584658cd
4
- data.tar.gz: 85b1a1ff55a91d353329eaebb38e5ff19bb2590bfa8ab2942dd5feb31a7b11c6
3
+ metadata.gz: eced600b25c5d8bf5d8a0b55ba7a5d116879c5ee3f346f9e5128144066c14d8c
4
+ data.tar.gz: e88b60c25cd88cba88f0cce8ca83fe4acf6873b99b757c791a9806f3b22569c4
5
5
  SHA512:
6
- metadata.gz: 18cb896b37d1c7449e8955e7209bcf663e02b0e43d42fe0c7137f9f8a0e4be5ed1f664d8bc2b2f4e777e15b6f8b6c8efb57114cdb283cdffbc8f51dff6c75d7a
7
- data.tar.gz: e477156c701bee3b6dfb5c337fb344bcb1e86d16978e0208e8a9616a7721af364ff63862045f85db2ac825dd8fc876b0198ec87f857a4844064cdf7336a8a315
6
+ metadata.gz: fb400975341e0ee1361e41f9cf93fdd1473af06f0bed0f06d75d36b0622766556110b3a3f75ab8b283776ff2c23a3263b5d493dd0035b27b965d2c31141eca78
7
+ data.tar.gz: edc3f5744ff0f9b4dde1f0b8d07649927b720540004fc891e357bcba30c9561963e4f3ece3238707496f23eb1fdf0d141fad44adbcf5c4ede25a59129c3e8717
@@ -8,6 +8,29 @@ module Cats
8
8
  render json: { success: true, data: serialize(receipts) }
9
9
  end
10
10
 
11
+ def create
12
+ p = model_params
13
+ receipt = Cats::Core::Receipt.find_by(
14
+ dispatch_id: p[:dispatch_id],
15
+ commodity_status: p[:commodity_status]
16
+ )
17
+ if receipt
18
+ receipt.quantity += p[:quantity]
19
+ if receipt.save
20
+ render json: { success: true, data: serialize(receipt) }
21
+ else
22
+ render json: { success: false, error: receipt.errors.full_messages[0] }, status: :unprocessable_entity
23
+ end
24
+ else
25
+ obj = Cats::Core::Receipt.new(model_params)
26
+ if obj.save
27
+ render json: { success: true, data: serialize(obj) }, status: :created
28
+ else
29
+ render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
30
+ end
31
+ end
32
+ end
33
+
11
34
  def start_stacking
12
35
  receipt = Cats::Core::Receipt.find(params[:id])
13
36
  service = ReceiptService.new
@@ -16,7 +16,6 @@ module Cats
16
16
 
17
17
  belongs_to :unit_of_measure
18
18
  belongs_to :source, polymorphic: true
19
- belongs_to :commodity_category
20
19
 
21
20
  validates :best_use_before, presence: true
22
21
  validates :batch_no, presence: true, uniqueness: true
@@ -25,7 +24,6 @@ module Cats
25
24
  validates :arrival_status, presence: true, inclusion: { in: ARRIVAL_STATUSES }
26
25
 
27
26
  delegate(:abbreviation, to: :unit_of_measure, prefix: true)
28
- delegate(:name, to: :commodity_category, prefix: true)
29
27
  delegate(:reference_no, to: :source, prefix: true)
30
28
 
31
29
  def set_approved
@@ -33,6 +31,10 @@ module Cats
33
31
 
34
32
  self.approved = false
35
33
  end
34
+
35
+ def name
36
+ source.commodity_category.name
37
+ end
36
38
  end
37
39
  end
38
40
  end
@@ -2,10 +2,17 @@ module Cats
2
2
  module Core
3
3
  class GiftCertificate < ApplicationRecord
4
4
  belongs_to :donation
5
+ belongs_to :commodity_category
6
+ belongs_to :unit_of_measure
5
7
 
6
8
  validates :reference_no, presence: true, uniqueness: true
7
- validates :gift_date, presence: true
9
+ validates :gift_date, :quantity, presence: true
10
+ validates :quantity, numericality: { greater_than: 0 }
8
11
 
12
+ delegate(:name, to: :commodity_category, prefix: true)
13
+ delegate(:abbreviation, to: :unit_of_measure, prefix: true)
14
+
15
+ before_validation :set_commodity_category
9
16
  after_create :update_donation
10
17
 
11
18
  def update_donation
@@ -15,6 +22,14 @@ module Cats
15
22
  donation.active = true
16
23
  donation.save!
17
24
  end
25
+
26
+ def set_commodity_category
27
+ return unless donation
28
+
29
+ return if commodity_category == donation.commodity_category
30
+
31
+ self.commodity_category = donation.commodity_category
32
+ end
18
33
  end
19
34
  end
20
35
  end
@@ -0,0 +1,27 @@
1
+ module Cats
2
+ module Core
3
+ class DispatchNotification < Noticed::Base
4
+ deliver_by :database
5
+
6
+ param :dispatch
7
+
8
+ def message
9
+ dispatch = params[:dispatch]
10
+ title = 'Dispatch Notification'
11
+ date = Date.today
12
+ body = <<~BODY
13
+ Commodity with the following details has been dispatched to you:
14
+ Dispatch Ref. = #{dispatch.reference_no}
15
+ Batch No. = #{dispatch.allocation_item.allocation.commodity.batch_no}
16
+ Commodity = #{dispatch.allocation_item.allocation.commodity.name}
17
+ Allocated Quantity = #{dispatch.allocation_item.quantity}
18
+ Quantity = #{dispatch.quantity}
19
+ Truck Plate No. = #{dispatch.plate_no}
20
+ Driver Name = #{dispatch.driver_name}
21
+ Driver Phone = #{dispatch.driver_phone}
22
+ BODY
23
+ { title: title, date: date, body: body }
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,9 +1,9 @@
1
1
  module Cats
2
2
  module Core
3
3
  class CommoditySerializer < ActiveModel::Serializer
4
- attributes :id, :batch_no, :description, :unit_of_measure_id, :unit_of_measure_abbreviation, :source_id,
4
+ attributes :id, :name, :batch_no, :description, :unit_of_measure_id, :unit_of_measure_abbreviation, :source_id,
5
5
  :source_type, :source_reference_no, :quantity, :best_use_before, :volume_per_metric_ton,
6
- :commodity_category_id, :commodity_category_name, :arrival_status, :approved
6
+ :arrival_status, :approved
7
7
  end
8
8
  end
9
9
  end
@@ -109,6 +109,7 @@ module Cats
109
109
  dispatch.save
110
110
  transactions = Cats::Core::DispatchTransaction.where(destination: dispatch)
111
111
  transactions.each(&:commit)
112
+ send_notification(dispatch)
112
113
  dispatch
113
114
  end
114
115
 
@@ -131,6 +132,25 @@ module Cats
131
132
 
132
133
  dispatch
133
134
  end
135
+
136
+ def send_notification(dispatch)
137
+ notification_rule = Cats::Core::NotificationRule.find_by(code: 'dispatch')
138
+ raise(StandardError, 'Notification rule not found for dispatch notification.') unless notification_rule
139
+
140
+ users = Cats::Core::User.joins(:roles).where(cats_core_roles: { name: notification_rule.roles })
141
+ location_id = dispatch.allocation_item.destination_id
142
+ recipients = users.map do |user|
143
+ details = user.details
144
+ if (details.key?('warehouse') && details['warehouse'] == location_id) ||
145
+ (details.key?('hub') && details['hub'] == location_id)
146
+ user
147
+ end
148
+ end.compact
149
+ return if recipients.empty?
150
+
151
+ notification = DispatchNotification.with(dispatch: dispatch)
152
+ notification.deliver(recipients)
153
+ end
134
154
  end
135
155
  end
136
156
  end
@@ -15,7 +15,15 @@ class CreateCatsCoreGiftCertificates < ActiveRecord::Migration[6.1]
15
15
  t.integer :purchase_year
16
16
  t.date :expiry_date
17
17
  t.string :bill_of_lading_no
18
- t.float :amount, null: false
18
+ t.float :quantity, null: false
19
+ t.references :commodity_category,
20
+ null: false,
21
+ index: { name: 'gc_on_cc_indx' },
22
+ foreign_key: { to_table: :cats_core_commodity_categories }
23
+ t.references :unit_of_measure,
24
+ null: false,
25
+ index: { name: 'uom_on_gc_indx' },
26
+ foreign_key: { to_table: :cats_core_unit_of_measures }
19
27
  t.float :estimated_price
20
28
  t.float :estimated_tax
21
29
 
@@ -6,10 +6,6 @@ class CreateCatsCoreCommodities < ActiveRecord::Migration[6.1]
6
6
  null: false,
7
7
  index: { name: 'uom_on_commodities_indx' },
8
8
  foreign_key: { to_table: :cats_core_unit_of_measures }
9
- t.references :commodity_category,
10
- null: false,
11
- index: { name: 'cc_on_commodities_indx' },
12
- foreign_key: { to_table: :cats_core_commodity_categories }
13
9
  t.references :source, polymorphic: true
14
10
  t.float :quantity, null: false
15
11
  t.string :description
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.1.14'.freeze
3
+ VERSION = '1.1.18'.freeze
4
4
  end
5
5
  end
@@ -3,7 +3,6 @@ FactoryBot.define do
3
3
  batch_no { FFaker::Name.name }
4
4
  description { FFaker::Name.name }
5
5
  unit_of_measure
6
- commodity_category
7
6
  source factory: :gift_certificate
8
7
  quantity { 100 }
9
8
  best_use_before { Date.today + 2.month }
@@ -3,13 +3,15 @@ FactoryBot.define do
3
3
  reference_no { FFaker::Name.name }
4
4
  gift_date { Date.today - 1.month }
5
5
  donation
6
+ commodity_category { donation.commodity_category }
7
+ unit_of_measure
6
8
  vessel { FFaker::Name.name }
7
9
  port { FFaker::Name.name }
8
10
  customs_declaration_no { FFaker::Name.name }
9
11
  purchase_year { 1 }
10
12
  expiry_date { Date.today + 6.month }
11
13
  bill_of_lading_no { FFaker::Name.name }
12
- amount { 1.5 }
14
+ quantity { 1.5 }
13
15
  estimated_price { 1.5 }
14
16
  estimated_tax { 1.5 }
15
17
  end
@@ -20,4 +20,9 @@ FactoryBot.define do
20
20
  location_type { Cats::Core::Location::WOREDA }
21
21
  parent
22
22
  end
23
+
24
+ factory :zone, parent: :location, class: 'Cats::Core::Location' do
25
+ location_type { Cats::Core::Location::ZONE }
26
+ parent
27
+ end
23
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cats_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.14
4
+ version: 1.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
@@ -286,6 +286,7 @@ files:
286
286
  - app/models/cats/core/transporter.rb
287
287
  - app/models/cats/core/unit_of_measure.rb
288
288
  - app/models/cats/core/user.rb
289
+ - app/notifications/cats/core/dispatch_notification.rb
289
290
  - app/notifications/cats/core/simple_notification.rb
290
291
  - app/serializers/cats/core/commodity_category_serializer.rb
291
292
  - app/serializers/cats/core/commodity_serializer.rb