cats_core 1.0.13 → 1.0.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) 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 +18 -0
  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 +0 -1
  22. data/db/migrate/{20210717043620_create_cats_core_locations.rb → 20210716183620_create_cats_core_locations.rb} +0 -0
  23. data/db/migrate/20210716185529_create_cats_core_currencies.rb +10 -0
  24. data/db/migrate/20210716210635_create_cats_core_operators.rb +13 -0
  25. data/db/migrate/20210716210905_create_cats_core_suppliers.rb +14 -0
  26. data/db/migrate/20210717031216_create_cats_core_rations.rb +19 -0
  27. data/db/migrate/20210717031810_create_cats_core_hrps.rb +20 -0
  28. data/db/migrate/20210717032024_create_cats_core_hrp_items.rb +22 -0
  29. data/db/migrate/20210717032330_create_cats_core_donations.rb +24 -0
  30. data/db/migrate/20210717032602_create_cats_core_gift_certificates.rb +29 -0
  31. data/db/migrate/20210717032855_create_cats_core_purchase_orders.rb +21 -0
  32. data/db/migrate/20210717033223_create_cats_core_commodities.rb +2 -14
  33. data/db/migrate/20210718042823_create_cats_core_commodity_allocations.rb +23 -0
  34. data/db/migrate/20210718045516_create_cats_core_dispatches.rb +27 -0
  35. data/db/migrate/20210718202957_create_cats_core_dispatch_transactions.rb +19 -0
  36. data/db/migrate/20210727074646_create_cats_core_receipts.rb +20 -0
  37. data/db/migrate/20210814160628_create_cats_core_receipt_transactions.rb +19 -0
  38. data/db/migrate/20210814175406_create_cats_core_stack_transactions.rb +19 -0
  39. data/lib/cats/core/version.rb +1 -1
  40. data/spec/factories/cats/core/commodities.rb +2 -5
  41. data/spec/factories/cats/core/commodity_allocations.rb +10 -0
  42. data/spec/factories/cats/core/currencies.rb +6 -0
  43. data/spec/factories/cats/core/dispatch_transactions.rb +9 -0
  44. data/spec/factories/cats/core/dispatches.rb +13 -0
  45. data/spec/factories/cats/core/donations.rb +11 -0
  46. data/spec/factories/cats/core/gift_certificates.rb +17 -0
  47. data/spec/factories/cats/core/hrp_items.rb +9 -0
  48. data/spec/factories/cats/core/hrps.rb +10 -0
  49. data/spec/factories/cats/core/locations.rb +5 -0
  50. data/spec/factories/cats/core/operators.rb +9 -0
  51. data/spec/factories/cats/core/purchase_orders.rb +10 -0
  52. data/spec/factories/cats/core/rations.rb +9 -0
  53. data/spec/factories/cats/core/receipt_transactions.rb +9 -0
  54. data/spec/factories/cats/core/receipts.rb +10 -0
  55. data/spec/factories/cats/core/stack_transactions.rb +9 -0
  56. data/spec/factories/cats/core/suppliers.rb +10 -0
  57. metadata +49 -15
  58. data/app/models/cats/core/commodity_transaction.rb +0 -55
  59. data/app/models/cats/core/receipt_plan.rb +0 -24
  60. data/app/models/cats/core/way_bill.rb +0 -12
  61. data/app/models/cats/core/way_bill_item.rb +0 -15
  62. data/db/migrate/20210718045516_create_cats_core_way_bills.rb +0 -25
  63. data/db/migrate/20210718050751_create_cats_core_way_bill_items.rb +0 -18
  64. data/db/migrate/20210718202957_create_cats_core_commodity_transactions.rb +0 -14
  65. data/db/migrate/20210727074646_create_cats_core_receipt_plans.rb +0 -16
  66. data/spec/factories/cats/core/commodity_transactions.rb +0 -10
  67. data/spec/factories/cats/core/receipt_plans.rb +0 -9
  68. data/spec/factories/cats/core/way_bill_items.rb +0 -8
  69. 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: c166b58630fc770c2447694d5d57f59edd26ab7bee0caf07f762fc16d21f4069
4
- data.tar.gz: 7cc6aead85c41426225eb4d306e92cf85ac7024b4690324a62985b7c6b163756
3
+ metadata.gz: 66fc59d71ea65e00fe3b47393f62621052e7e376c65e504df71fa29b58adf26f
4
+ data.tar.gz: f79e7b8a4b5a7b3327c9975ec08e84d0c41b5e395789db0f279ce71d5cbf009e
5
5
  SHA512:
6
- metadata.gz: 8a6c48372747e4c159c7fae9d51af746740fe7d556fc9b0cee36d9ba814ccd33aa25be298681729ad474b63c7c30881b79dcdb5da2a2da47d9962f6b3df325a2
7
- data.tar.gz: 30805a86c89f24e1472a177c7cedf1c18a5ccbc18756bf316eca62138d63247a05ee42c18004b06a1ce898ac4343341045eff7f59921d16ea70a22ac2c33d4d9
6
+ metadata.gz: bdbc87018bb880d2ffc8680b6165e0e24dfe5fe9fd8b7a6502fe3ecd4c8463e91b7c2d899276d6b903bb21dfe8ed948b37456333d08aea3f43daeff2bfc9badf
7
+ data.tar.gz: 93eddf1ab8dd21dfd5413505ebdfb9b3ec3735612dcb09be0430451ef622b10c95076dd9bdbf9d523b016c63dd78fdcfca7026b5151f8510ff0a786a3c71f80d
@@ -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
+ CASH = 'Cash'.freeze
5
+ KIND = 'Kind'.freeze
6
+ DONATION_TYPES = [CASH, 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 == CASH }
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
@@ -15,6 +15,8 @@ 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
 
@@ -25,6 +27,22 @@ module Cats
25
27
  "#{store_keeper.first_name} #{store_keeper.last_name}"
26
28
  end
27
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
+
28
46
  delegate(:phone_number, to: :store_keeper, prefix: true)
29
47
  end
30
48
  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
@@ -5,7 +5,6 @@ module Cats
5
5
  rolify role_cname: 'Cats::Core::Role'
6
6
 
7
7
  belongs_to :application_module
8
- has_and_belongs_to_many :roles, join_table: :cats_core_users_cats_core_roles
9
8
  has_many :notifications, as: :recipient
10
9
 
11
10
  validates :password, length: { minimum: 6 }, if: proc { |u| u.password.present? }, on: :update
@@ -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
@@ -0,0 +1,19 @@
1
+ class CreateCatsCoreRations < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_rations do |t|
4
+ t.string :reference_no, unique: true
5
+ t.references :program,
6
+ null: false,
7
+ index: { name: 'program_on_ration_indx' },
8
+ foreign_key: { to_table: :cats_core_programs }
9
+ t.references :commodity_category,
10
+ null: false,
11
+ index: { name: 'cc_on_ration_indx' },
12
+ foreign_key: { to_table: :cats_core_commodity_categories }
13
+ t.float :amount, null: false
14
+ t.boolean :current, null: false, default: true
15
+
16
+ t.timestamps
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ class CreateCatsCoreHrps < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_hrps do |t|
4
+ t.string :reference_no, unique: true
5
+ t.integer :year, null: false
6
+ t.string :season, null: false
7
+ t.string :status, null: false, default: 'Draft'
8
+ t.references :program,
9
+ null: false,
10
+ index: { name: 'program_on_hrp_indx' },
11
+ foreign_key: { to_table: :cats_core_programs }
12
+ t.references :ration,
13
+ null: false,
14
+ index: { name: 'ration_on_hrp_indx' },
15
+ foreign_key: { to_table: :cats_core_rations }
16
+
17
+ t.timestamps
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ class CreateCatsCoreHrpItems < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_hrp_items do |t|
4
+ t.references :hrp,
5
+ null: false,
6
+ index: { name: 'hrp_on_hrp_items_indx' },
7
+ foreign_key: { to_table: :cats_core_hrps }
8
+ t.references :woreda,
9
+ null: false,
10
+ index: { name: 'woreda_on_hrp_items_idnx' },
11
+ foreign_key: { to_table: :cats_core_locations }
12
+ t.integer :beneficiaries, null: false
13
+ t.float :commodity_amount, null: false
14
+ t.references :operator,
15
+ null: false,
16
+ index: { name: 'operator_on_hrp_items_indx' },
17
+ foreign_key: { to_table: :cats_core_operators }
18
+
19
+ t.timestamps
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ class CreateCatsCoreDonations < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_donations do |t|
4
+ t.string :reference_no, unique: true
5
+ t.string :donation_type, null: false
6
+ t.date :donated_on, null: false
7
+ t.references :donor,
8
+ null: false,
9
+ index: { name: 'donor_on_donation_indx' },
10
+ foreign_key: { to_table: :cats_core_donors }
11
+ t.references :hrp,
12
+ null: false,
13
+ index: { name: 'hrp_on_donation_indx' },
14
+ foreign_key: { to_table: :cats_core_hrps }
15
+ t.float :amount
16
+ t.references :currency,
17
+ null: true,
18
+ index: { name: 'currency_on_donation_indx' },
19
+ foreign_key: { to_table: :cats_core_currencies }
20
+
21
+ t.timestamps
22
+ end
23
+ end
24
+ end