cats_core 1.0.12 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/cats/core/commodity.rb +2 -3
  3. data/app/models/cats/core/commodity_allocation.rb +19 -0
  4. data/app/models/cats/core/currency.rb +8 -0
  5. data/app/models/cats/core/dispatch.rb +14 -0
  6. data/app/models/cats/core/dispatch_transaction.rb +8 -0
  7. data/app/models/cats/core/donation.rb +18 -0
  8. data/app/models/cats/core/gift_certificate.rb +11 -0
  9. data/app/models/cats/core/hrp.rb +16 -0
  10. data/app/models/cats/core/hrp_item.rb +12 -0
  11. data/app/models/cats/core/operator.rb +8 -0
  12. data/app/models/cats/core/purchase_order.rb +11 -0
  13. data/app/models/cats/core/ration.rb +12 -0
  14. data/app/models/cats/core/receipt.rb +19 -0
  15. data/app/models/cats/core/receipt_transaction.rb +8 -0
  16. data/app/models/cats/core/stack.rb +2 -2
  17. data/app/models/cats/core/stack_transaction.rb +8 -0
  18. data/app/models/cats/core/store.rb +26 -2
  19. data/app/models/cats/core/supplier.rb +8 -0
  20. data/app/models/cats/core/transaction.rb +32 -0
  21. data/app/models/cats/core/user.rb +13 -1
  22. data/app/services/cats/core/notification_service.rb +3 -6
  23. data/db/migrate/20210715114910_create_cats_core_users.rb +1 -0
  24. data/db/migrate/{20210717043620_create_cats_core_locations.rb → 20210716183620_create_cats_core_locations.rb} +0 -0
  25. data/db/migrate/20210716185529_create_cats_core_currencies.rb +10 -0
  26. data/db/migrate/20210716210635_create_cats_core_operators.rb +13 -0
  27. data/db/migrate/20210716210905_create_cats_core_suppliers.rb +14 -0
  28. data/db/migrate/20210717031216_create_cats_core_rations.rb +19 -0
  29. data/db/migrate/20210717031810_create_cats_core_hrps.rb +20 -0
  30. data/db/migrate/20210717032024_create_cats_core_hrp_items.rb +22 -0
  31. data/db/migrate/20210717032330_create_cats_core_donations.rb +24 -0
  32. data/db/migrate/20210717032602_create_cats_core_gift_certificates.rb +29 -0
  33. data/db/migrate/20210717032855_create_cats_core_purchase_orders.rb +21 -0
  34. data/db/migrate/20210717033223_create_cats_core_commodities.rb +2 -14
  35. data/db/migrate/20210717140855_create_cats_core_stores.rb +4 -3
  36. data/db/migrate/20210718042823_create_cats_core_commodity_allocations.rb +23 -0
  37. data/db/migrate/20210718045516_create_cats_core_dispatches.rb +27 -0
  38. data/db/migrate/20210718202957_create_cats_core_dispatch_transactions.rb +19 -0
  39. data/db/migrate/20210727074646_create_cats_core_receipts.rb +20 -0
  40. data/db/migrate/20210814160628_create_cats_core_receipt_transactions.rb +19 -0
  41. data/db/migrate/20210814175406_create_cats_core_stack_transactions.rb +19 -0
  42. data/lib/cats/core/version.rb +1 -1
  43. data/spec/factories/cats/core/commodities.rb +2 -5
  44. data/spec/factories/cats/core/commodity_allocations.rb +10 -0
  45. data/spec/factories/cats/core/currencies.rb +6 -0
  46. data/spec/factories/cats/core/dispatch_transactions.rb +9 -0
  47. data/spec/factories/cats/core/dispatches.rb +13 -0
  48. data/spec/factories/cats/core/donations.rb +11 -0
  49. data/spec/factories/cats/core/gift_certificates.rb +17 -0
  50. data/spec/factories/cats/core/hrp_items.rb +9 -0
  51. data/spec/factories/cats/core/hrps.rb +10 -0
  52. data/spec/factories/cats/core/locations.rb +5 -0
  53. data/spec/factories/cats/core/operators.rb +9 -0
  54. data/spec/factories/cats/core/purchase_orders.rb +10 -0
  55. data/spec/factories/cats/core/rations.rb +8 -0
  56. data/spec/factories/cats/core/receipt_transactions.rb +9 -0
  57. data/spec/factories/cats/core/receipts.rb +10 -0
  58. data/spec/factories/cats/core/stack_transactions.rb +9 -0
  59. data/spec/factories/cats/core/stores.rb +2 -2
  60. data/spec/factories/cats/core/suppliers.rb +10 -0
  61. data/spec/factories/cats/core/users.rb +1 -0
  62. metadata +49 -15
  63. data/app/models/cats/core/commodity_transaction.rb +0 -55
  64. data/app/models/cats/core/receipt_plan.rb +0 -24
  65. data/app/models/cats/core/way_bill.rb +0 -12
  66. data/app/models/cats/core/way_bill_item.rb +0 -15
  67. data/db/migrate/20210718045516_create_cats_core_way_bills.rb +0 -25
  68. data/db/migrate/20210718050751_create_cats_core_way_bill_items.rb +0 -18
  69. data/db/migrate/20210718202957_create_cats_core_commodity_transactions.rb +0 -14
  70. data/db/migrate/20210727074646_create_cats_core_receipt_plans.rb +0 -16
  71. data/spec/factories/cats/core/commodity_transactions.rb +0 -10
  72. data/spec/factories/cats/core/receipt_plans.rb +0 -9
  73. data/spec/factories/cats/core/way_bill_items.rb +0 -8
  74. data/spec/factories/cats/core/way_bills.rb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad0f19c4e9e9d38a4038b2f94ca78ea18fb730dccb1c04bacf403a8fe5b29de5
4
- data.tar.gz: 452ec1bb9126955274e5adae51d60a903e88674da97610b1b9945c43995d1ab6
3
+ metadata.gz: 38525dbc996619fc301d108816acab2e97b65362a5feca9251a6c112b53dc3c6
4
+ data.tar.gz: 465da29b3725b9f51bd9b9b34857e5b4edfefeaaf24f7d8b7b3cffbd485067c7
5
5
  SHA512:
6
- metadata.gz: 40dcc3d2d091d837d24da04a8889bca46b8afa22662c27fa518fb3ef9b98c2b20aad829f3f5126e444566e6229ca67d954dfa0ac7f76e93c4f03ef80c40fded4
7
- data.tar.gz: ad35c7773f8b1ea0bf10193d70e0857096da4768029c4b1de675b1a9c005e0d6fba86f8201739fafde97122a137a2122bd4aa12b506b965a053a2606f963d418
6
+ metadata.gz: 02b4f3b1693f0eb5a1e4108861a65f0a27a8852682a80a9ee62060cdc58d28849258e9c518909a850157eec2bd963a50bd7cedd6a6439ffbb9dc3e62c175b761
7
+ data.tar.gz: e6a6d7d6d7af63671e28ae6f48d8128811e5bc04125a70c2027aae0d5604478ff3c0ea056cb33a12b8c0e6105b7db1eea762f2fbd187365c55e3be0738c60b7c
@@ -6,11 +6,10 @@ module Cats
6
6
  DAMAGED = 'Damaged'.freeze
7
7
  COMMODITY_STATUSES = [GOOD, DAMAGED].freeze
8
8
 
9
- belongs_to :commodity_category
10
- belongs_to :donor
11
- belongs_to :program
12
9
  belongs_to :unit_of_measure
10
+ belongs_to :source, polymorphic: true
13
11
 
12
+ validates :best_use_before, presence: true
14
13
  validates :quantity, presence: true, numericality: { greater_than: 0 }
15
14
  validates :volume_per_metric_ton, numericality: { greater_than: 0, allow_nil: true }
16
15
  end
@@ -0,0 +1,19 @@
1
+ module Cats
2
+ module Core
3
+ class CommodityAllocation < ApplicationRecord
4
+ belongs_to :commodity
5
+ belongs_to :source, class_name: 'Cats::Core::Location'
6
+ belongs_to :destination, class_name: 'Cats::Core::Location'
7
+
8
+ validates :quantity, :commodity_status, presence: true
9
+ validates :commodity_status, inclusion: { in: Cats::Core::Commodity::COMMODITY_STATUSES }
10
+ validate :validate_source_and_destination
11
+
12
+ def validate_source_and_destination
13
+ return unless source.present? && destination.present?
14
+
15
+ errors.add(:base, 'source and destination cannot be the same') if source == destination
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ module Cats
2
+ module Core
3
+ class Currency < ApplicationRecord
4
+ validates :code, :name, presence: true
5
+ validates :code, uniqueness: true
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ module Cats
2
+ module Core
3
+ class Dispatch < ApplicationRecord
4
+ belongs_to :prepared_by, class_name: 'Cats::Core::User'
5
+ belongs_to :transporter
6
+ belongs_to :commodity_allocation
7
+
8
+ validates :reference_no, :plate_no, :driver_name, :driver_phone, :quantity, :commodity_status, presence: true
9
+ validates :reference_no, uniqueness: true
10
+ validates :quantity, numericality: { greater_than: 0 }
11
+ validates :commodity_status, inclusion: { in: Cats::Core::Commodity::COMMODITY_STATUSES }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ module Cats
2
+ module Core
3
+ class DispatchTransaction < Transaction
4
+ belongs_to :source, class_name: 'Cats::Core::Stack'
5
+ belongs_to :destination, class_name: 'Cats::Core::Dispatch'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,18 @@
1
+ module Cats
2
+ module Core
3
+ class Donation < ApplicationRecord
4
+ FUND = 'Fund'.freeze
5
+ KIND = 'Kind'.freeze
6
+ DONATION_TYPES = [FUND, KIND].freeze
7
+
8
+ belongs_to :donor
9
+ belongs_to :hrp
10
+ belongs_to :currency, optional: true
11
+
12
+ validates :reference_no, :donation_type, :donated_on, presence: true
13
+ validates :reference_no, uniqueness: true
14
+ validates :donation_type, inclusion: { in: DONATION_TYPES }
15
+ validates :currency, :amount, presence: true, if: -> { donation_type == FUND }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ module Cats
2
+ module Core
3
+ class GiftCertificate < ApplicationRecord
4
+ belongs_to :donation
5
+ belongs_to :commodity_category
6
+
7
+ validates :reference_no, presence: true, uniqueness: true
8
+ validates :gift_date, presence: true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ module Cats
2
+ module Core
3
+ class Hrp < ApplicationRecord
4
+ DRAFT = 'Draft'.freeze
5
+ APPROVED = 'Approved'.freeze
6
+ STATUSES = [DRAFT, APPROVED].freeze
7
+
8
+ belongs_to :program
9
+ belongs_to :ration
10
+
11
+ validates :reference_no, :year, :season, :status, presence: true
12
+ validates :reference_no, uniqueness: true
13
+ validates :status, inclusion: { in: STATUSES }
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ module Cats
2
+ module Core
3
+ class HrpItem < ApplicationRecord
4
+ belongs_to :hrp
5
+ belongs_to :woreda, -> { where(location_type: Cats::Core::Location::WOREDA) }, class_name: 'Cats::Core::Location'
6
+ belongs_to :operator
7
+
8
+ validates :beneficiaries, presence: true, numericality: { greater_than: 0 }
9
+ validates :commodity_amount, presence: true, numericality: { greater_than: 0 }
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ module Cats
2
+ module Core
3
+ class Operator < ApplicationRecord
4
+ validates :code, :name, :contact_name, :contact_phone, presence: true
5
+ validates :code, uniqueness: true
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ module Cats
2
+ module Core
3
+ class PurchaseOrder < ApplicationRecord
4
+ belongs_to :donation
5
+ belongs_to :commodity_category
6
+
7
+ validates :reference_no, :order_date, :supplier, presence: true
8
+ validates :reference_no, uniqueness: true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module Cats
2
+ module Core
3
+ class Ration < ApplicationRecord
4
+ belongs_to :program
5
+ belongs_to :commodity_category
6
+
7
+ validates :reference_no, :amount, presence: true
8
+ validates :reference_no, uniqueness: true
9
+ validates :amount, numericality: { greater_than: 0 }
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ module Cats
2
+ module Core
3
+ class Receipt < ApplicationRecord
4
+ # Receipt status
5
+ DRAFT = 'Draft'.freeze
6
+ ACCEPTED = 'Accepted'.freeze
7
+ DECLINED = 'Declined'.freeze
8
+ RECEIPT_STATUSES = [DRAFT, ACCEPTED, DECLINED].freeze
9
+
10
+ belongs_to :dispatch
11
+ belongs_to :prepared_by, class_name: 'Cats::Core::User'
12
+
13
+ validates :quantity, :commodity_status, :status, presence: true
14
+ validates :quantity, numericality: { greater_than: 0 }
15
+ validates :status, inclusion: { in: RECEIPT_STATUSES }
16
+ validates :commodity_status, inclusion: { in: Cats::Core::Commodity::COMMODITY_STATUSES }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ module Cats
2
+ module Core
3
+ class ReceiptTransaction < Transaction
4
+ belongs_to :source, class_name: 'Cats::Core::Receipt'
5
+ belongs_to :destination, class_name: 'Cats::Core::Stack'
6
+ end
7
+ end
8
+ end
@@ -9,8 +9,8 @@ module Cats
9
9
 
10
10
  belongs_to :commodity
11
11
  belongs_to :store
12
- has_many :source_transactions, class_name: 'Cats::Core::CommodityTransaction', as: :source
13
- has_many :destination_transactions, class_name: 'Cats::Core::CommodityTransaction', as: :destination
12
+ has_many :dispatch_transactions, foreign_key: :source_id
13
+ has_many :receipt_transactions, foreign_key: :destination_id
14
14
 
15
15
  validates :code, :length, :width, :height, :start_x, :start_y, :commodity_status, :stack_status,
16
16
  :quantity, presence: true
@@ -0,0 +1,8 @@
1
+ module Cats
2
+ module Core
3
+ class StackTransaction < Transaction
4
+ belongs_to :source, class_name: 'Cats::Core::Stack'
5
+ belongs_to :destination, class_name: 'Cats::Core::Stack'
6
+ end
7
+ end
8
+ end
@@ -2,10 +2,10 @@ module Cats
2
2
  module Core
3
3
  class Store < ApplicationRecord
4
4
  belongs_to :warehouse, class_name: 'Cats::Core::Location'
5
+ belongs_to :store_keeper, class_name: 'Cats::Core::User'
5
6
  has_many :stacks
6
- has_many :receipt_plans, as: :receivable
7
7
 
8
- validates :name, :store_keeper_name, :length, :width, :height, presence: true
8
+ validates :name, :length, :width, :height, presence: true
9
9
  validates :length, :width, :height, numericality: { greater_than: 0 }
10
10
  validates :gangway_length, :gangway_width, :gangway_corner_dist, presence: true, if: :has_gangway?
11
11
  validates :gangway_length,
@@ -15,11 +15,35 @@ module Cats
15
15
  allow_nil: true
16
16
  validate :validate_location
17
17
 
18
+ after_save :update_store_keeper
19
+
18
20
  def validate_location
19
21
  return if warehouse.nil?
20
22
 
21
23
  errors.add(:warehouse, 'must be a valid warehouse') unless warehouse.location_type == Location::WAREHOUSE
22
24
  end
25
+
26
+ def store_keeper_name
27
+ "#{store_keeper.first_name} #{store_keeper.last_name}"
28
+ end
29
+
30
+ def update_store_keeper
31
+ return unless store_keeper_id_previously_changed?
32
+
33
+ unless id_previously_changed?
34
+ old_storekeeper = Cats::Core::User.find(store_keeper_id_previously_was)
35
+ old_storekeeper.details['stores'].delete(id)
36
+ old_storekeeper.save
37
+ end
38
+ if store_keeper.details.key?('stores')
39
+ store_keeper.details['stores'] << id
40
+ else
41
+ store_keeper.details['stores'] = [id]
42
+ end
43
+ store_keeper.save
44
+ end
45
+
46
+ delegate(:phone_number, to: :store_keeper, prefix: true)
23
47
  end
24
48
  end
25
49
  end
@@ -0,0 +1,8 @@
1
+ module Cats
2
+ module Core
3
+ class Supplier < ApplicationRecord
4
+ validates :code, :name, :contact_name, :contact_phone, presence: true
5
+ validates :code, uniqueness: true
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,32 @@
1
+ module Cats
2
+ module Core
3
+ class Transaction < ApplicationRecord
4
+ self.abstract_class = true
5
+
6
+ # Transaction statuses
7
+ DRAFT = 'Draft'.freeze
8
+ COMMITTED = 'Committed'.freeze
9
+ STATUSES = [DRAFT, COMMITTED].freeze
10
+
11
+ validates :transaction_date, :quantity, :status, presence: true
12
+ validates :quantity, numericality: { greater_than: 0 }
13
+ validates :status, inclusion: { in: STATUSES }
14
+ validate :validate_quantity
15
+
16
+ def validate_quantity
17
+ return unless quantity.present? && source.present?
18
+
19
+ errors.add(:quantity, 'cannot be more than source quantity') if quantity > source.quantity
20
+ end
21
+
22
+ def commit
23
+ Transaction.transaction do
24
+ source.quantity -= quantity
25
+ destination.quantity += quantity
26
+ source.save
27
+ destination.save
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -8,9 +8,11 @@ module Cats
8
8
  has_and_belongs_to_many :roles, join_table: :cats_core_users_cats_core_roles
9
9
  has_many :notifications, as: :recipient
10
10
 
11
+ validates :password, length: { minimum: 6 }, if: proc { |u| u.password.present? }, on: :update
11
12
  validates :first_name, :last_name, :email, presence: true
12
- validates :password, length: { minimum: 6 }
13
+ validates :password, presence: true, length: { minimum: 6 }, on: :create
13
14
  validates :email, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP }
15
+ validate :validate_phone_number
14
16
 
15
17
  def warehouses
16
18
  return unless details.key?('warehouses')
@@ -23,6 +25,16 @@ module Cats
23
25
 
24
26
  Cats::Core::Store.where(id: details['stores'])
25
27
  end
28
+
29
+ def validate_phone_number
30
+ return unless phone_number.present?
31
+
32
+ return if phone_number.length == 10 && /0\d{9}/.match(phone_number)
33
+
34
+ return if phone_number.length == 12 && /251\d{9}/.match(phone_number)
35
+
36
+ errors.add(:phone_number, 'must be 10 or 12 digits and should match with local phone pattern')
37
+ end
26
38
  end
27
39
  end
28
40
  end
@@ -16,22 +16,19 @@ module Cats
16
16
  }
17
17
  }.freeze
18
18
 
19
- def initialize(code, params)
19
+ def initialize(rules, code, params)
20
+ @rules = rules
20
21
  @code = code
21
22
  @params = params
22
23
  end
23
24
 
24
- def notification_rules
25
- NOTIFICATION_RULES
26
- end
27
-
28
25
  def create_notifier(rule)
29
26
  clazz = rule[:notification].constantize
30
27
  clazz.with(**@params)
31
28
  end
32
29
 
33
30
  def notify
34
- rule = notification_rules[@code]
31
+ rule = @rules[@code]
35
32
  notifier = create_notifier(rule)
36
33
  app_code = rule[:application]
37
34
  roles = rule[:recipients]
@@ -7,6 +7,7 @@ class CreateCatsCoreUsers < ActiveRecord::Migration[6.1]
7
7
  t.boolean :active, null: false, default: true
8
8
  t.string :password_digest
9
9
  t.jsonb :details
10
+ t.string :phone_number
10
11
  t.references :application_module,
11
12
  null: false,
12
13
  index: { name: 'am_on_users_indx' },
@@ -0,0 +1,10 @@
1
+ class CreateCatsCoreCurrencies < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_currencies do |t|
4
+ t.string :code, unique: true
5
+ t.string :name, null: false
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ class CreateCatsCoreOperators < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_operators do |t|
4
+ t.string :code, unique: true
5
+ t.string :name, null: false
6
+ t.string :description
7
+ t.string :contact_name, null: false
8
+ t.string :contact_phone, null: false
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ class CreateCatsCoreSuppliers < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_suppliers do |t|
4
+ t.string :code, unique: true
5
+ t.string :name, null: false
6
+ t.string :description
7
+ t.string :address
8
+ t.string :contact_name, null: false
9
+ t.string :contact_phone, null: false
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+ end