cats_core 1.0.13 → 1.0.17

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 (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
@@ -1,55 +0,0 @@
1
- module Cats
2
- module Core
3
- class CommodityTransaction < ApplicationRecord
4
- # Transaction statuses
5
- DRAFT = 'Draft'.freeze
6
- COMMITTED = 'Committed'.freeze
7
- STATUSES = [DRAFT, COMMITTED].freeze
8
-
9
- # Transaction types
10
- STACK_TO_STACK = 'Stack to Stack'.freeze
11
- STACK_TO_WAY_BILL = 'Stack to Way Bill'.freeze
12
- WAY_BILL_TO_STACK = 'Way Bill to Stack'.freeze
13
- TRANSACTION_TYPES = [STACK_TO_STACK, STACK_TO_WAY_BILL, WAY_BILL_TO_STACK].freeze
14
-
15
- belongs_to :source, polymorphic: true
16
- belongs_to :destination, polymorphic: true
17
-
18
- validates :transaction_date, :quantity, :status, presence: true
19
- validates :quantity, numericality: { greater_than: 0 }
20
- validates :status, inclusion: { in: STATUSES }
21
- validate :validate_quantity
22
-
23
- before_validation :set_transaction_type
24
-
25
- def validate_quantity
26
- return unless quantity.present? && source.present?
27
-
28
- errors.add(:quantity, 'cannot be more than source quantity') if quantity > source.quantity
29
- end
30
-
31
- def commit
32
- CommodityTransaction.transaction do
33
- source.quantity -= quantity
34
- destination.quantity += quantity
35
- source.save
36
- destination.save
37
- end
38
- end
39
-
40
- private
41
-
42
- def set_transaction_type
43
- return unless transaction_type.nil? && source.present? && destination.present?
44
-
45
- if source.instance_of?(Cats::Core::Stack) && destination.instance_of?(Cats::Core::Stack)
46
- self.transaction_type = STACK_TO_STACK
47
- elsif source.instance_of?(Cats::Core::Stack) && destination.instance_of?(Cats::Core::WayBillItem)
48
- self.transaction_type = STACK_TO_WAY_BILL
49
- else
50
- self.transaction_type = WAY_BILL_TO_STACK
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,24 +0,0 @@
1
- module Cats
2
- module Core
3
- class ReceiptPlan < ApplicationRecord
4
- # receipt plan status
5
- DRAFT = 'Draft'.freeze
6
- ACCEPTED = 'Accepted'.freeze
7
- DECLINED = 'Declined'.freeze
8
- RECEIPT_PLAN_STATUSES = [DRAFT, ACCEPTED, DECLINED].freeze
9
-
10
- validates :quantity, :status, presence: true
11
- belongs_to :commodity
12
- belongs_to :plan_recipient, polymorphic: true
13
- validates :quantity, numericality: { greater_than: 0 }
14
- validates :status, inclusion: { in: RECEIPT_PLAN_STATUSES }
15
- validate :validate_reason_for_decline
16
-
17
- def validate_reason_for_decline
18
- return unless reason_for_decline.nil? || reason_for_decline == 'Accepted'
19
-
20
- errors.add(:reason_for_decline, 'must be specified')
21
- end
22
- end
23
- end
24
- end
@@ -1,12 +0,0 @@
1
- module Cats
2
- module Core
3
- class WayBill < ApplicationRecord
4
- belongs_to :source, class_name: 'Cats::Core::Location'
5
- belongs_to :destination, class_name: 'Cats::Core::Location'
6
- belongs_to :transporter
7
-
8
- validates :ref_no, :plate_no, :driver_name, :driver_phone, :date_prepared, presence: true
9
- validates :ref_no, uniqueness: true
10
- end
11
- end
12
- end
@@ -1,15 +0,0 @@
1
- module Cats
2
- module Core
3
- class WayBillItem < ApplicationRecord
4
- belongs_to :way_bill
5
- belongs_to :commodity
6
-
7
- has_many :source_transactions, class_name: 'Cats::Core::CommodityTransaction', as: :source
8
- has_many :destination_transactions, class_name: 'Cats::Core::CommodityTransaction', as: :destination
9
-
10
- validates :quantity, :commodity_status, presence: true
11
- validates :quantity, numericality: { greater_than: 0 }
12
- validates :commodity_status, inclusion: { in: Cats::Core::Commodity::COMMODITY_STATUSES }
13
- end
14
- end
15
- end
@@ -1,25 +0,0 @@
1
- class CreateCatsCoreWayBills < ActiveRecord::Migration[6.1]
2
- def change
3
- create_table :cats_core_way_bills do |t|
4
- t.string :ref_no, unique: true
5
- t.references :source,
6
- null: false,
7
- index: { name: 'source_on_wb_indx' },
8
- foreign_key: { to_table: :cats_core_locations }
9
- t.references :destination,
10
- null: false,
11
- index: { name: 'destination_on_wb_indx' },
12
- foreign_key: { to_table: :cats_core_locations }
13
- t.references :transporter,
14
- null: false,
15
- index: { name: 'transporter_on_wb_indx' },
16
- foreign_key: { to_table: :cats_core_transporters }
17
- t.string :plate_no, null: false
18
- t.string :driver_name, null: false
19
- t.string :driver_phone, null: false
20
- t.date :date_prepared, null: false
21
-
22
- t.timestamps
23
- end
24
- end
25
- end
@@ -1,18 +0,0 @@
1
- class CreateCatsCoreWayBillItems < ActiveRecord::Migration[6.1]
2
- def change
3
- create_table :cats_core_way_bill_items do |t|
4
- t.references :way_bill,
5
- null: false,
6
- index: { name: 'wb_on_wbi_indx' },
7
- foreign_key: { to_table: :cats_core_way_bills }
8
- t.references :commodity,
9
- null: false,
10
- index: { name: 'commodity_on_wbi_indx' },
11
- foreign_key: { to_table: :cats_core_commodities }
12
- t.float :quantity, null: false
13
- t.string :commodity_status, null: false
14
-
15
- t.timestamps
16
- end
17
- end
18
- end
@@ -1,14 +0,0 @@
1
- class CreateCatsCoreCommodityTransactions < ActiveRecord::Migration[6.1]
2
- def change
3
- create_table :cats_core_commodity_transactions do |t|
4
- t.references :source, polymorphic: true
5
- t.references :destination, polymorphic: true
6
- t.date :transaction_date, null: false
7
- t.float :quantity, null: false
8
- t.string :status, null: false, default: 'Draft'
9
- t.string :transaction_type, null: false, default: 'Stack to Stack'
10
-
11
- t.timestamps
12
- end
13
- end
14
- end
@@ -1,16 +0,0 @@
1
- class CreateCatsCoreReceiptPlans < ActiveRecord::Migration[6.1]
2
- def change
3
- create_table :cats_core_receipt_plans do |t|
4
- t.float :quantity, null: false
5
- t.string :status, default: 'Draft'
6
- t.references :commodity,
7
- null: false,
8
- index: { name: 'commodity_on_receipt_plan_indx' },
9
- foreign_key: { to_table: :cats_core_commodities }
10
- t.string :reason_for_decline
11
- t.references :plan_recipient, polymorphic: true
12
-
13
- t.timestamps
14
- end
15
- end
16
- end
@@ -1,10 +0,0 @@
1
- FactoryBot.define do
2
- factory :commodity_transaction, class: 'Cats::Core::CommodityTransaction' do
3
- source factory: :stack
4
- destination factory: :stack
5
- transaction_date { Date.today }
6
- quantity { 10 }
7
- status { Cats::Core::CommodityTransaction::DRAFT }
8
- transaction_type { Cats::Core::CommodityTransaction::STACK_TO_STACK }
9
- end
10
- end
@@ -1,9 +0,0 @@
1
- FactoryBot.define do
2
- factory :receipt_plan, class: 'Cats::Core::ReceiptPlan' do
3
- plan_recipient factory: :store
4
- commodity
5
- quantity { 1.5 }
6
- status { 'Accepted' }
7
- reason_for_decline { FFaker::Name.name }
8
- end
9
- end
@@ -1,8 +0,0 @@
1
- FactoryBot.define do
2
- factory :way_bill_item, class: 'Cats::Core::WayBillItem' do
3
- way_bill
4
- commodity
5
- quantity { 20 }
6
- commodity_status { Cats::Core::Commodity::GOOD }
7
- end
8
- end
@@ -1,12 +0,0 @@
1
- FactoryBot.define do
2
- factory :way_bill, class: 'Cats::Core::WayBill' do
3
- ref_no { FFaker::Name.name }
4
- source factory: :location
5
- destination factory: :location
6
- transporter
7
- plate_no { FFaker::Name.name }
8
- driver_name { FFaker::Name.name }
9
- driver_phone { FFaker::Name.name }
10
- date_prepared { Date.today }
11
- end
12
- end