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.
- checksums.yaml +4 -4
- data/app/controllers/comee/core/back_orders_controller.rb +34 -0
- data/app/models/comee/core/back_order.rb +5 -6
- data/app/models/comee/core/back_order_item.rb +3 -2
- data/app/models/comee/core/client.rb +1 -0
- data/app/models/comee/core/inventory.rb +9 -0
- data/app/models/comee/core/master_price.rb +2 -1
- data/app/models/comee/core/product.rb +1 -0
- data/app/models/comee/core/sales_order_item.rb +22 -0
- data/app/models/comee/core/warehouse_shipment.rb +13 -0
- data/app/models/comee/core/warehouse_shipment_item.rb +26 -0
- data/app/notifications/comee/core/{new_order_notification.rb → back_order_notification.rb} +1 -1
- data/config/routes.rb +6 -0
- data/db/migrate/20230728125723_create_comee_core_back_order_items.rb +2 -0
- data/db/migrate/20230813235946_create_comee_core_master_prices.rb +1 -0
- data/db/migrate/20231003073316_create_comee_core_inventories.rb +13 -0
- data/db/migrate/20231003080017_create_comee_core_warehouse_shipments.rb +17 -0
- data/db/migrate/20231004105455_create_comee_core_warehouse_shipment_items.rb +17 -0
- data/db/migrate/20231008115247_add_quantity_to_comee_core_sales_order_item.rb +6 -0
- data/lib/comee/core/version.rb +1 -1
- data/spec/factories/comee/core/back_order_items.rb +2 -0
- data/spec/factories/comee/core/inventories.rb +6 -0
- data/spec/factories/comee/core/notifications.rb +1 -1
- data/spec/factories/comee/core/sales_order_items.rb +2 -0
- data/spec/factories/comee/core/warehouse_shipment_items.rb +7 -0
- data/spec/factories/comee/core/warehouse_shipments.rb +9 -0
- metadata +28 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a430ac3b0edb3d903589fc39cc548fee51235223e69f86463e9d17900417c28
|
4
|
+
data.tar.gz: 59601bbacfb140b0ad870f1b9a3c24d8a3218da8a3e096f969d8848846f5973b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
44
|
-
|
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,
|
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)
|
@@ -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
|
@@ -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
|
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
|
data/lib/comee/core/version.rb
CHANGED
@@ -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::
|
4
|
+
type { "Comee::Core::BackOrderNotification" }
|
5
5
|
params { {back_order: create(:back_order)} }
|
6
6
|
read_at { Date.current }
|
7
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.
|
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
|
+
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/
|
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
|