comee_core 0.1.21 → 0.1.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/comee/core/back_orders_controller.rb +34 -0
  3. data/app/models/comee/core/back_order.rb +5 -6
  4. data/app/models/comee/core/back_order_item.rb +3 -2
  5. data/app/models/comee/core/client.rb +1 -0
  6. data/app/models/comee/core/inventory.rb +9 -0
  7. data/app/models/comee/core/master_price.rb +2 -1
  8. data/app/models/comee/core/product.rb +1 -0
  9. data/app/models/comee/core/sales_order_item.rb +22 -0
  10. data/app/models/comee/core/warehouse_shipment.rb +13 -0
  11. data/app/models/comee/core/warehouse_shipment_item.rb +26 -0
  12. data/app/notifications/comee/core/{new_order_notification.rb → back_order_notification.rb} +1 -1
  13. data/config/routes.rb +6 -0
  14. data/db/migrate/20230728125723_create_comee_core_back_order_items.rb +2 -0
  15. data/db/migrate/20230813235946_create_comee_core_master_prices.rb +1 -0
  16. data/db/migrate/20231003073316_create_comee_core_inventories.rb +13 -0
  17. data/db/migrate/20231003080017_create_comee_core_warehouse_shipments.rb +17 -0
  18. data/db/migrate/20231004105455_create_comee_core_warehouse_shipment_items.rb +17 -0
  19. data/db/migrate/20231008115247_add_quantity_to_comee_core_sales_order_item.rb +6 -0
  20. data/lib/comee/core/version.rb +1 -1
  21. data/spec/factories/comee/core/back_order_items.rb +2 -0
  22. data/spec/factories/comee/core/inventories.rb +6 -0
  23. data/spec/factories/comee/core/notifications.rb +1 -1
  24. data/spec/factories/comee/core/sales_order_items.rb +2 -0
  25. data/spec/factories/comee/core/warehouse_shipment_items.rb +7 -0
  26. data/spec/factories/comee/core/warehouse_shipments.rb +9 -0
  27. metadata +28 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4110e9f1c5556d8d519e9c4853886b4bdc836aee47a8e01f990f7d640f5a7144
4
- data.tar.gz: bd9a6c43ddd0d57a46cf57518fa21afe77430844a29923b0815d34de8ad9f80b
3
+ metadata.gz: 3a430ac3b0edb3d903589fc39cc548fee51235223e69f86463e9d17900417c28
4
+ data.tar.gz: 59601bbacfb140b0ad870f1b9a3c24d8a3218da8a3e096f969d8848846f5973b
5
5
  SHA512:
6
- metadata.gz: 2f9c11ca22065eff7004b72ca5494381469256775c2b4d3d391fc5d35640fe1a7e1fc64ef7a51f9d5f94f78281b350dd9fe21f62753a93fa648ca5e235f1d796
7
- data.tar.gz: 482433b0bf10ee4450ad5e93e811ae5c2db81461a991abd3c34a8bc49e0f57a8112a1e8294110d7bb695528d16376d2ade64ecef8e9bfd8e416f59727b937a5e
6
+ metadata.gz: 61165752dd893e613c16d3e020aa4049b356d6967248c699efd2b9d7ff85ec28a95934b857f12d350022ea1bb70512fb0e4d75556f30c10765185486dd98256c
7
+ data.tar.gz: 66ca0c7a8726797243347c47c7ca985b66ff67ded63f8fb05ac8119e5d9d1250084714f4c12f83d4a31efd768b98ee345623deb7021662d030ae0980ac13dda8
@@ -0,0 +1,34 @@
1
+ module Comee
2
+ module Core
3
+ class BackOrdersController < ApplicationController
4
+ include Common
5
+ before_action :set_object, only: %i[show update submit]
6
+
7
+ def index
8
+ super do
9
+ Comee::Core::BackOrder.includes(:back_order_items, :supplier)
10
+ end
11
+ end
12
+
13
+ def submit
14
+ ActiveRecord::Base.transaction do
15
+ @obj.submit
16
+ Comee::Core::BackOrderNotification.with(back_order: @obj).deliver(@obj.supplier.user)
17
+ render json: {success: true, data: serialize(@obj.reload)}
18
+ end
19
+ rescue => e
20
+ render json: {success: false, error: e.message}
21
+ end
22
+
23
+ def filter
24
+ query = Comee::Core::BackOrder.ransack(params[:q])
25
+ render json: {success: true, data: serialize(query.result.includes(:back_order_items, :supplier))}
26
+ end
27
+
28
+ def model_params
29
+ params.require(:payload).permit(:order_number, :order_date, :delivery_date, :supplier_id, :terms,
30
+ :delivery_address, :invoice_address, :status, :remark)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,9 +1,7 @@
1
1
  module Comee
2
2
  module Core
3
3
  class BackOrder < ApplicationRecord
4
- enum :status, {draft: 0, submitted: 1, confirmed: 2}
5
-
6
- after_create_commit :notify_supplier
4
+ enum :status, {draft: 0, submitted: 1, confirmed: 2, accepted: 3}
7
5
 
8
6
  belongs_to :supplier
9
7
  has_many :back_order_items
@@ -38,10 +36,11 @@ module Comee
38
36
  save!
39
37
  end
40
38
 
41
- private
39
+ def submit
40
+ raise(StandardError, "Back order can't be submitted if it is not in draft state.") unless BackOrder.statuses[status] == BackOrder.statuses[:draft]
42
41
 
43
- def notify_supplier
44
- Comee::Core::NewOrderNotification.with(back_order: self).deliver_later(supplier.user)
42
+ self.status = BackOrder.statuses[:submitted]
43
+ save
45
44
  end
46
45
  end
47
46
  end
@@ -6,8 +6,9 @@ module Comee
6
6
  belongs_to :back_order
7
7
  belongs_to :product
8
8
 
9
- validates :item_status, presence: true
10
- validates :requested_quantity, :requested_unit_price, :supplier_quantity, :supplier_unit_price, presence: true, numericality: {greater_than: 0}
9
+ validates :item_status, :from, :to, presence: true
10
+ validates :requested_quantity, :requested_unit_price, :supplier_quantity, :supplier_unit_price,
11
+ presence: true, numericality: {greater_than: 0}
11
12
 
12
13
  delegate(:code, :name, :description, to: :product, prefix: true)
13
14
  delegate(:unit_code, :unit_name, to: :product, prefix: false)
@@ -2,6 +2,7 @@ module Comee
2
2
  module Core
3
3
  class Client < ApplicationRecord
4
4
  belongs_to :user, optional: true
5
+ has_many :warehouse_shipments
5
6
 
6
7
  validates :code, :name, :address, :locale, presence: true
7
8
  validates :code, uniqueness: true
@@ -0,0 +1,9 @@
1
+ module Comee
2
+ module Core
3
+ class Inventory < ApplicationRecord
4
+ belongs_to :product
5
+
6
+ validates :quantity, presence: true, numericality: {greater_than: 0}
7
+ end
8
+ end
9
+ end
@@ -1,11 +1,12 @@
1
1
  module Comee
2
2
  module Core
3
3
  class MasterPrice < ApplicationRecord
4
+ enum :status, {old: 0, current: 1, future: 2}
4
5
  belongs_to :supplier
5
6
  belongs_to :product
6
7
  belongs_to :previous_price, class_name: "Comee::Core::MasterPrice", optional: true
7
8
 
8
- validates :purchase_price, :selling_price, :pp_valid_from, :pp_valid_to, :sp_valid_from, :sp_valid_to, presence: true
9
+ validates :purchase_price, :status, :selling_price, :pp_valid_from, :pp_valid_to, :sp_valid_from, :sp_valid_to, presence: true
9
10
  validates :margin, presence: true, numericality: {greater_than_or_equal_to: 0, less_than_or_equal_to: 100}
10
11
  validates :product_id, uniqueness: {scope: [:supplier_id, :previous_price_id]}
11
12
  validate :validate_primary_price, :validate_purchase_price_validity_dates, :validate_selling_price_validity_dates
@@ -3,6 +3,7 @@ module Comee
3
3
  class Product < ApplicationRecord
4
4
  belongs_to :product_type
5
5
  belongs_to :unit
6
+ has_many :inventories
6
7
 
7
8
  validates :code, presence: true, uniqueness: true
8
9
  validates :name, presence: true
@@ -2,12 +2,16 @@ module Comee
2
2
  module Core
3
3
  class SalesOrderItem < ApplicationRecord
4
4
  before_validation :set_delivery_date, if: proc { delivery_date.nil? }
5
+ before_validation :update_quantity_remaining, if: proc { quantity_remaining.nil? }
5
6
 
6
7
  belongs_to :sales_order
7
8
  belongs_to :product
9
+ has_many :warehouse_shipment_items
8
10
 
9
11
  validates :delivery_date, presence: true
10
12
  validates :quantity, :price, presence: true, numericality: {greater_than: 0}
13
+ validates :quantity_en_route, numericality: {greater_than_or_equal_to: 0}
14
+ validates :quantity_remaining, numericality: {greater_than: 0}
11
15
 
12
16
  delegate(:name, to: :product, prefix: true)
13
17
  delegate(:code, to: :product, prefix: true)
@@ -15,6 +19,24 @@ module Comee
15
19
  def set_delivery_date
16
20
  self.delivery_date = sales_order.expected_delivery_date
17
21
  end
22
+
23
+ def update_quantity_remaining
24
+ self.quantity_remaining = quantity
25
+ if quantity_en_route_changed? && quantity_en_route_was > 0 && quantity_en_route == 0
26
+ self.quantity_remaining -= quantity_en_route_was
27
+ end
28
+ end
29
+
30
+ def update_quantity_en_route(quantity)
31
+ self.quantity_en_route = quantity
32
+ save
33
+ end
34
+
35
+ def confirm_delivery
36
+ self.quantity_remaining -= quantity_en_route
37
+ self.quantity_en_route = 0
38
+ save
39
+ end
18
40
  end
19
41
  end
20
42
  end
@@ -0,0 +1,13 @@
1
+ module Comee
2
+ module Core
3
+ class WarehouseShipment < ApplicationRecord
4
+ belongs_to :client
5
+ has_many :warehouse_shipment_items
6
+
7
+ enum :status, {draft: 0, submitted: 1, acknowledged: 2, delivered: 3}
8
+
9
+ validates :reference_number, presence: true, uniqueness: true
10
+ validates :destination, :delivery_date, :status, presence: true
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ module Comee
2
+ module Core
3
+ class WarehouseShipmentItem < ApplicationRecord
4
+ after_create :update_inventory_and_sales_order_item
5
+
6
+ belongs_to :warehouse_shipment
7
+ belongs_to :sales_order_item
8
+
9
+ validates :quantity, presence: true
10
+
11
+ def update_inventory_and_sales_order_item
12
+ update_inventory(sales_order_item.product_id, quantity)
13
+
14
+ sales_order_item.update_quantity_en_route(quantity)
15
+ end
16
+
17
+ def update_inventory(product_id, quantity_change)
18
+ inventory = Inventory.find_by(product_id: product_id)
19
+ if inventory
20
+ inventory.quantity -= quantity_change
21
+ inventory.save
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,6 +1,6 @@
1
1
  module Comee
2
2
  module Core
3
- class NewOrderNotification < Noticed::Base
3
+ class BackOrderNotification < Noticed::Base
4
4
  deliver_by :database
5
5
  deliver_by :email, mailer: "Comee::Core::SupplierMailer", method: :new_order_notification
6
6
 
data/config/routes.rb CHANGED
@@ -21,4 +21,10 @@ Comee::Core::Engine.routes.draw do
21
21
  resources :clients
22
22
  post "/client_prices/filter", controller: :client_prices, action: :filter
23
23
  resources :client_prices
24
+ post "/back_orders/filter", controller: :back_orders, action: :filter
25
+ resources :back_orders do
26
+ member do
27
+ post "submit"
28
+ end
29
+ end
24
30
  end
@@ -13,6 +13,8 @@ class CreateComeeCoreBackOrderItems < ActiveRecord::Migration[7.0]
13
13
  t.float :requested_unit_price, null: false
14
14
  t.float :supplier_quantity, null: false
15
15
  t.float :supplier_unit_price, null: false
16
+ t.date :from, null: false
17
+ t.date :to, null: false
16
18
  t.integer :item_status, null: false, default: 0
17
19
  t.string :remark
18
20
 
@@ -6,6 +6,7 @@ class CreateComeeCoreMasterPrices < ActiveRecord::Migration[7.0]
6
6
  t.date :pp_valid_from, null: false
7
7
  t.date :pp_valid_to, null: false
8
8
  t.date :sp_valid_from, null: false
9
+ t.float :status, null: false, default: 0
9
10
  t.date :sp_valid_to, null: false
10
11
  t.boolean :active, null: false
11
12
  t.boolean :primary, null: false
@@ -0,0 +1,13 @@
1
+ class CreateComeeCoreInventories < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :comee_core_inventories do |t|
4
+ t.references :product,
5
+ null: false,
6
+ index: {name: "product_on_cci_indx"},
7
+ foreign_key: {to_table: :comee_core_products}
8
+ t.integer :quantity, null: false
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ class CreateComeeCoreWarehouseShipments < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :comee_core_warehouse_shipments do |t|
4
+ t.string :reference_number, null: false
5
+ t.string :destination, null: false
6
+ t.date :delivery_date, null: false
7
+ t.references :client,
8
+ null: false,
9
+ index: {name: "client_on_ccws_indx"},
10
+ foreign_key: {to_table: :comee_core_clients}
11
+ t.integer :status, null: false, default: 0
12
+
13
+ t.timestamps
14
+ end
15
+ add_index :comee_core_warehouse_shipments, :reference_number, unique: true
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ class CreateComeeCoreWarehouseShipmentItems < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :comee_core_warehouse_shipment_items do |t|
4
+ t.references :warehouse_shipment,
5
+ null: false,
6
+ index: {name: "ws_on_ccwsi_indx"},
7
+ foreign_key: {to_table: :comee_core_warehouse_shipments}
8
+ t.references :sales_order_item,
9
+ null: false,
10
+ index: {name: "soi_on_ccwsi_indx"},
11
+ foreign_key: {to_table: :comee_core_sales_order_items}
12
+ t.integer :quantity, null: false
13
+
14
+ t.timestamps
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,6 @@
1
+ class AddQuantityToComeeCoreSalesOrderItem < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :comee_core_sales_order_items, :quantity_remaining, :integer
4
+ add_column :comee_core_sales_order_items, :quantity_en_route, :integer, default: 0
5
+ end
6
+ end
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.1.21"
3
+ VERSION = "0.1.23"
4
4
  end
5
5
  end
@@ -6,6 +6,8 @@ FactoryBot.define do
6
6
  requested_unit_price { 50 }
7
7
  supplier_quantity { 5 }
8
8
  supplier_unit_price { 55 }
9
+ from { Date.current }
10
+ to { Date.current.advance(months: 1) }
9
11
  item_status { Comee::Core::BackOrderItem.item_statuses[:available] }
10
12
  end
11
13
  end
@@ -0,0 +1,6 @@
1
+ FactoryBot.define do
2
+ factory :inventory, class: "Comee::Core::Inventory" do
3
+ quantity { 10 }
4
+ product
5
+ end
6
+ end
@@ -1,7 +1,7 @@
1
1
  FactoryBot.define do
2
2
  factory :notification, class: "Comee::Core::Notification" do
3
3
  recipient { create(:user) }
4
- type { "Comee::Core::NewOrderNotification" }
4
+ type { "Comee::Core::BackOrderNotification" }
5
5
  params { {back_order: create(:back_order)} }
6
6
  read_at { Date.current }
7
7
  end
@@ -3,6 +3,8 @@ FactoryBot.define do
3
3
  sales_order
4
4
  product
5
5
  quantity { 100 }
6
+ quantity_en_route { 0 }
7
+ quantity_remaining { 100 }
6
8
  price { 50 }
7
9
  delivery_date { Date.current.advance(months: 1) }
8
10
  end
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :warehouse_shipment_item, class: "Comee::Core::WarehouseShipmentItem" do
3
+ warehouse_shipment
4
+ sales_order_item
5
+ quantity { 10 }
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ FactoryBot.define do
2
+ factory :warehouse_shipment, class: "Comee::Core::WarehouseShipment" do
3
+ reference_number { Faker::Alphanumeric.alpha(number: 8) }
4
+ destination { Faker::Lorem.sentence }
5
+ delivery_date { Date.current.advance(month: 1) }
6
+ status { Comee::Core::WarehouseShipment.statuses[:draft] }
7
+ client
8
+ end
9
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comee_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.21
4
+ version: 0.1.23
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-11 00:00:00.000000000 Z
11
+ date: 2023-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -220,6 +220,20 @@ dependencies:
220
220
  - - ">="
221
221
  - !ruby/object:Gem::Version
222
222
  version: 1.30.1
223
+ - !ruby/object:Gem::Dependency
224
+ name: letter_opener
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
223
237
  description: An engine which contains core models and end-points for the COMee ERP.
224
238
  email:
225
239
  - henockl@live.com
@@ -232,6 +246,7 @@ files:
232
246
  - Rakefile
233
247
  - app/controllers/comee/core/access_controller.rb
234
248
  - app/controllers/comee/core/application_controller.rb
249
+ - app/controllers/comee/core/back_orders_controller.rb
235
250
  - app/controllers/comee/core/client_prices_controller.rb
236
251
  - app/controllers/comee/core/clients_controller.rb
237
252
  - app/controllers/comee/core/currencies_controller.rb
@@ -253,6 +268,7 @@ files:
253
268
  - app/models/comee/core/client_price.rb
254
269
  - app/models/comee/core/currency.rb
255
270
  - app/models/comee/core/field_mapping.rb
271
+ - app/models/comee/core/inventory.rb
256
272
  - app/models/comee/core/invoice.rb
257
273
  - app/models/comee/core/invoice_item.rb
258
274
  - app/models/comee/core/master_price.rb
@@ -266,7 +282,9 @@ files:
266
282
  - app/models/comee/core/supplier.rb
267
283
  - app/models/comee/core/unit.rb
268
284
  - app/models/comee/core/user.rb
269
- - app/notifications/comee/core/new_order_notification.rb
285
+ - app/models/comee/core/warehouse_shipment.rb
286
+ - app/models/comee/core/warehouse_shipment_item.rb
287
+ - app/notifications/comee/core/back_order_notification.rb
270
288
  - app/serializers/comee/core/client_price_serializer.rb
271
289
  - app/serializers/comee/core/client_serializer.rb
272
290
  - app/serializers/comee/core/currency_serializer.rb
@@ -305,6 +323,10 @@ files:
305
323
  - db/migrate/20230929115336_create_comee_core_order_sources.rb
306
324
  - db/migrate/20230929120051_create_comee_core_field_mappings.rb
307
325
  - db/migrate/20230929130910_create_comee_core_client_orders.rb
326
+ - db/migrate/20231003073316_create_comee_core_inventories.rb
327
+ - db/migrate/20231003080017_create_comee_core_warehouse_shipments.rb
328
+ - db/migrate/20231004105455_create_comee_core_warehouse_shipment_items.rb
329
+ - db/migrate/20231008115247_add_quantity_to_comee_core_sales_order_item.rb
308
330
  - lib/comee/core.rb
309
331
  - lib/comee/core/engine.rb
310
332
  - lib/comee/core/version.rb
@@ -317,6 +339,7 @@ files:
317
339
  - spec/factories/comee/core/clients.rb
318
340
  - spec/factories/comee/core/currencies.rb
319
341
  - spec/factories/comee/core/field_mappings.rb
342
+ - spec/factories/comee/core/inventories.rb
320
343
  - spec/factories/comee/core/invoice_items.rb
321
344
  - spec/factories/comee/core/invoices.rb
322
345
  - spec/factories/comee/core/master_prices.rb
@@ -330,6 +353,8 @@ files:
330
353
  - spec/factories/comee/core/suppliers.rb
331
354
  - spec/factories/comee/core/units.rb
332
355
  - spec/factories/comee/core/users.rb
356
+ - spec/factories/comee/core/warehouse_shipment_items.rb
357
+ - spec/factories/comee/core/warehouse_shipments.rb
333
358
  homepage: https://www.mks.com
334
359
  licenses:
335
360
  - MIT