comee_core 0.1.96 → 0.1.98

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/comee/core/agents_controller.rb +13 -0
  3. data/app/controllers/comee/core/application_controller.rb +15 -2
  4. data/app/controllers/comee/core/back_orders_controller.rb +2 -2
  5. data/app/controllers/comee/core/client_prices_controller.rb +3 -10
  6. data/app/controllers/comee/core/client_warehouses_controller.rb +13 -0
  7. data/app/controllers/comee/core/clients_controller.rb +42 -9
  8. data/app/controllers/comee/core/contacts_controller.rb +13 -0
  9. data/app/controllers/comee/core/customer_order_items_controller.rb +3 -2
  10. data/app/controllers/comee/core/customer_orders_controller.rb +3 -3
  11. data/app/controllers/comee/core/item_statuses_controller.rb +2 -2
  12. data/app/controllers/comee/core/notifications_controller.rb +4 -4
  13. data/app/controllers/comee/core/product_lookups_controller.rb +2 -2
  14. data/app/controllers/comee/core/products_controller.rb +7 -9
  15. data/app/controllers/comee/core/purchase_order_items_controller.rb +2 -2
  16. data/app/controllers/comee/core/purchase_orders_controller.rb +2 -2
  17. data/app/controllers/comee/core/quotation_request_items_controller.rb +2 -2
  18. data/app/controllers/comee/core/quotation_requests_controller.rb +8 -9
  19. data/app/controllers/comee/core/sales_order_items_controller.rb +1 -1
  20. data/app/controllers/comee/core/sales_orders_controller.rb +13 -7
  21. data/app/controllers/comee/core/shipment_items_controller.rb +13 -13
  22. data/app/controllers/comee/core/suppliers_controller.rb +4 -6
  23. data/app/controllers/comee/core/unit_conversions_controller.rb +1 -1
  24. data/app/controllers/comee/core/units_controller.rb +1 -1
  25. data/app/controllers/concerns/comee/core/common.rb +33 -7
  26. data/app/models/comee/core/agent.rb +7 -0
  27. data/app/models/comee/core/client.rb +4 -1
  28. data/app/models/comee/core/client_warehouse.rb +8 -0
  29. data/app/models/comee/core/contact.rb +7 -0
  30. data/app/models/comee/core/customer_order_item.rb +6 -0
  31. data/app/models/comee/core/master_price.rb +1 -0
  32. data/app/models/comee/core/price.rb +2 -1
  33. data/app/models/comee/core/sales_order.rb +1 -2
  34. data/app/models/comee/core/sales_order_item.rb +6 -1
  35. data/app/models/comee/core/supplier.rb +2 -0
  36. data/app/serializers/comee/core/agent_serializer.rb +7 -0
  37. data/app/serializers/comee/core/client_serializer.rb +4 -1
  38. data/app/serializers/comee/core/client_warehouse_serializer.rb +8 -0
  39. data/app/serializers/comee/core/contact_serializer.rb +7 -0
  40. data/app/serializers/comee/core/product_serializer.rb +2 -2
  41. data/app/serializers/comee/core/sales_order_item_serializer.rb +1 -1
  42. data/app/serializers/comee/core/supplier_serializer.rb +1 -0
  43. data/app/services/comee/core/customer_order_service.rb +7 -2
  44. data/config/routes.rb +7 -1
  45. data/db/migrate/20230728122618_create_comee_core_suppliers.rb +4 -0
  46. data/db/migrate/20230728123039_create_comee_core_clients.rb +4 -0
  47. data/db/migrate/20230728123458_create_comee_core_agents.rb +23 -0
  48. data/db/migrate/20230728123559_create_comee_core_contacts.rb +34 -0
  49. data/db/migrate/20230811102708_create_comee_core_customer_order_items.rb +1 -0
  50. data/db/migrate/20230812212844_create_comee_core_sales_order_items.rb +1 -0
  51. data/db/migrate/20230813235946_create_comee_core_master_prices.rb +2 -1
  52. data/db/migrate/20230814151601_create_comee_core_client_prices.rb +2 -1
  53. data/db/migrate/20240119100125_create_comee_core_client_warehouses.rb +15 -0
  54. data/lib/comee/core/version.rb +1 -1
  55. data/spec/factories/comee/core/agents.rb +8 -0
  56. data/spec/factories/comee/core/client_prices.rb +1 -1
  57. data/spec/factories/comee/core/client_warehouses.rb +8 -0
  58. data/spec/factories/comee/core/clients.rb +2 -1
  59. data/spec/factories/comee/core/contacts.rb +8 -0
  60. data/spec/factories/comee/core/customer_order_items.rb +1 -0
  61. data/spec/factories/comee/core/fulfillment_centers.rb +1 -1
  62. data/spec/factories/comee/core/master_prices.rb +1 -0
  63. data/spec/factories/comee/core/sales_order_items.rb +1 -0
  64. data/spec/factories/comee/core/suppliers.rb +1 -0
  65. metadata +35 -12
  66. data/app/models/comee/core/warehouse_shipment.rb +0 -70
  67. data/app/models/comee/core/warehouse_shipment_item.rb +0 -37
  68. data/db/migrate/20231003080017_create_comee_core_warehouse_shipments.rb +0 -17
  69. data/db/migrate/20231004105455_create_comee_core_warehouse_shipment_items.rb +0 -17
  70. data/spec/factories/comee/core/warehouse_shipment_items.rb +0 -7
  71. data/spec/factories/comee/core/warehouse_shipments.rb +0 -9
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.96
4
+ version: 0.1.98
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-17 00:00:00.000000000 Z
11
+ date: 2024-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -128,6 +128,20 @@ dependencies:
128
128
  - - ">="
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0'
131
+ - !ruby/object:Gem::Dependency
132
+ name: database_cleaner-active_record
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
131
145
  - !ruby/object:Gem::Dependency
132
146
  name: factory_bot_rails
133
147
  requirement: !ruby/object:Gem::Requirement
@@ -185,7 +199,7 @@ dependencies:
185
199
  - !ruby/object:Gem::Version
186
200
  version: '0'
187
201
  - !ruby/object:Gem::Dependency
188
- name: rubocop-rspec
202
+ name: rspec-retry
189
203
  requirement: !ruby/object:Gem::Requirement
190
204
  requirements:
191
205
  - - ">="
@@ -199,7 +213,7 @@ dependencies:
199
213
  - !ruby/object:Gem::Version
200
214
  version: '0'
201
215
  - !ruby/object:Gem::Dependency
202
- name: shoulda-matchers
216
+ name: rubocop-rspec
203
217
  requirement: !ruby/object:Gem::Requirement
204
218
  requirements:
205
219
  - - ">="
@@ -213,7 +227,7 @@ dependencies:
213
227
  - !ruby/object:Gem::Version
214
228
  version: '0'
215
229
  - !ruby/object:Gem::Dependency
216
- name: simplecov
230
+ name: shoulda-matchers
217
231
  requirement: !ruby/object:Gem::Requirement
218
232
  requirements:
219
233
  - - ">="
@@ -227,7 +241,7 @@ dependencies:
227
241
  - !ruby/object:Gem::Version
228
242
  version: '0'
229
243
  - !ruby/object:Gem::Dependency
230
- name: solargraph
244
+ name: simplecov
231
245
  requirement: !ruby/object:Gem::Requirement
232
246
  requirements:
233
247
  - - ">="
@@ -251,10 +265,13 @@ files:
251
265
  - README.md
252
266
  - Rakefile
253
267
  - app/controllers/comee/core/access_controller.rb
268
+ - app/controllers/comee/core/agents_controller.rb
254
269
  - app/controllers/comee/core/application_controller.rb
255
270
  - app/controllers/comee/core/back_orders_controller.rb
256
271
  - app/controllers/comee/core/client_prices_controller.rb
272
+ - app/controllers/comee/core/client_warehouses_controller.rb
257
273
  - app/controllers/comee/core/clients_controller.rb
274
+ - app/controllers/comee/core/contacts_controller.rb
258
275
  - app/controllers/comee/core/currencies_controller.rb
259
276
  - app/controllers/comee/core/customer_order_items_controller.rb
260
277
  - app/controllers/comee/core/customer_orders_controller.rb
@@ -282,12 +299,15 @@ files:
282
299
  - app/jobs/comee_core/application_job.rb
283
300
  - app/mailers/comee/core/application_mailer.rb
284
301
  - app/mailers/comee/core/supplier_mailer.rb
302
+ - app/models/comee/core/agent.rb
285
303
  - app/models/comee/core/application_record.rb
286
304
  - app/models/comee/core/back_order.rb
287
305
  - app/models/comee/core/back_order_item.rb
288
306
  - app/models/comee/core/client.rb
289
307
  - app/models/comee/core/client_order.rb
290
308
  - app/models/comee/core/client_price.rb
309
+ - app/models/comee/core/client_warehouse.rb
310
+ - app/models/comee/core/contact.rb
291
311
  - app/models/comee/core/currency.rb
292
312
  - app/models/comee/core/customer_order.rb
293
313
  - app/models/comee/core/customer_order_item.rb
@@ -323,11 +343,12 @@ files:
323
343
  - app/models/comee/core/unit.rb
324
344
  - app/models/comee/core/unit_conversion.rb
325
345
  - app/models/comee/core/user.rb
326
- - app/models/comee/core/warehouse_shipment.rb
327
- - app/models/comee/core/warehouse_shipment_item.rb
328
346
  - app/notifications/comee/core/back_order_notification.rb
347
+ - app/serializers/comee/core/agent_serializer.rb
329
348
  - app/serializers/comee/core/client_price_serializer.rb
330
349
  - app/serializers/comee/core/client_serializer.rb
350
+ - app/serializers/comee/core/client_warehouse_serializer.rb
351
+ - app/serializers/comee/core/contact_serializer.rb
331
352
  - app/serializers/comee/core/currency_serializer.rb
332
353
  - app/serializers/comee/core/customer_order_item_serializer.rb
333
354
  - app/serializers/comee/core/customer_order_serializer.rb
@@ -372,6 +393,8 @@ files:
372
393
  - db/migrate/20230728014330_create_comee_core_users.rb
373
394
  - db/migrate/20230728122618_create_comee_core_suppliers.rb
374
395
  - db/migrate/20230728123039_create_comee_core_clients.rb
396
+ - db/migrate/20230728123458_create_comee_core_agents.rb
397
+ - db/migrate/20230728123559_create_comee_core_contacts.rb
375
398
  - db/migrate/20230728123928_create_comee_core_back_orders.rb
376
399
  - db/migrate/20230728125723_create_comee_core_back_order_items.rb
377
400
  - db/migrate/20230730061225_create_comee_core_notifications.rb
@@ -387,8 +410,6 @@ files:
387
410
  - db/migrate/20230929115336_create_comee_core_order_sources.rb
388
411
  - db/migrate/20230929130910_create_comee_core_client_orders.rb
389
412
  - db/migrate/20231003073316_create_comee_core_inventories.rb
390
- - db/migrate/20231003080017_create_comee_core_warehouse_shipments.rb
391
- - db/migrate/20231004105455_create_comee_core_warehouse_shipment_items.rb
392
413
  - db/migrate/20231101113358_create_comee_core_edi_orders.rb
393
414
  - db/migrate/20231121094339_create_comee_core_quotation_requests.rb
394
415
  - db/migrate/20231121132709_create_comee_core_quotation_request_items.rb
@@ -407,16 +428,20 @@ files:
407
428
  - db/migrate/20240109185749_create_comee_core_transport_availability.rb
408
429
  - db/migrate/20240109185931_create_comee_core_time_slots.rb
409
430
  - db/migrate/20240111112140_create_comee_core_pickup_schedules.rb
431
+ - db/migrate/20240119100125_create_comee_core_client_warehouses.rb
410
432
  - lib/comee/core.rb
411
433
  - lib/comee/core/engine.rb
412
434
  - lib/comee/core/version.rb
413
435
  - lib/comee_core.rb
414
436
  - lib/tasks/comee_core_tasks.rake
437
+ - spec/factories/comee/core/agents.rb
415
438
  - spec/factories/comee/core/back_order_items.rb
416
439
  - spec/factories/comee/core/back_orders.rb
417
440
  - spec/factories/comee/core/client_orders.rb
418
441
  - spec/factories/comee/core/client_prices.rb
442
+ - spec/factories/comee/core/client_warehouses.rb
419
443
  - spec/factories/comee/core/clients.rb
444
+ - spec/factories/comee/core/contacts.rb
420
445
  - spec/factories/comee/core/currencies.rb
421
446
  - spec/factories/comee/core/customer_order_items.rb
422
447
  - spec/factories/comee/core/customer_orders.rb
@@ -451,8 +476,6 @@ files:
451
476
  - spec/factories/comee/core/unit_conversions.rb
452
477
  - spec/factories/comee/core/units.rb
453
478
  - spec/factories/comee/core/users.rb
454
- - spec/factories/comee/core/warehouse_shipment_items.rb
455
- - spec/factories/comee/core/warehouse_shipments.rb
456
479
  homepage: https://www.mks.com
457
480
  licenses:
458
481
  - MIT
@@ -1,70 +0,0 @@
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
-
12
- def self.ransackable_attributes(_auth_object = nil)
13
- %w[id client_id delivery_date destination id reference_number status]
14
- end
15
-
16
- def self.ransackable_associations(_auth_object = nil)
17
- []
18
- end
19
-
20
- def submit
21
- self.status = WarehouseShipment.statuses[:submitted]
22
- save!
23
- self
24
- end
25
-
26
- def acknowledge
27
- error = "Warehouse shipment should have a `submitted` status before acknowledgement."
28
- raise(StandardError, error) unless WarehouseShipment.statuses[status] == WarehouseShipment.statuses[:submitted]
29
-
30
- self.status = WarehouseShipment.statuses[:acknowledged]
31
- save!
32
- items = warehouse_shipment_items.includes(:sales_order_item)
33
- return self unless items.count.positive?
34
-
35
- updates = items.map do |item|
36
- order_item = item.sales_order_item
37
- {
38
- id: order_item.id,
39
- sales_order_id: order_item.sales_order_id,
40
- unit_id: order_item.unit_id,
41
- customer_order_item_id: order_item.customer_order_item_id,
42
- quantity: order_item.quantity,
43
- quantity_delivered: order_item.quantity_delivered,
44
- price: order_item.price,
45
- delivery_date: order_item.delivery_date,
46
- eb_number: order_item.eb_number
47
- }
48
- end
49
- SalesOrderItem.upsert_all(updates)
50
- self
51
- end
52
-
53
- def deliver
54
- error = "Warehouse shipment should have an `acknowledged` status before delivery."
55
- raise(StandardError, error) unless WarehouseShipment.statuses[status] == WarehouseShipment.statuses[:acknowledged]
56
-
57
- self.status = WarehouseShipment.statuses[:delivered]
58
- save!
59
- order_items = warehouse_shipment_items.includes(:sales_order_item).map(&:sales_order_item)
60
- return self unless order_items.count.positive?
61
-
62
- order_items.each do |sales_order_item|
63
- sales_order_item.update(quantity_delivered: sales_order_item.quantity)
64
- end
65
- # SalesOrderItem.where(id: order_items.map(&:id)).update_all(quantity_delivered: sales_order_item.quantity)
66
- self
67
- end
68
- end
69
- end
70
- end
@@ -1,37 +0,0 @@
1
- module Comee
2
- module Core
3
- class WarehouseShipmentItem < ApplicationRecord
4
- before_save :update_inventory
5
-
6
- belongs_to :warehouse_shipment
7
- belongs_to :sales_order_item
8
-
9
- validates :quantity, presence: true
10
- validate :validate_inventory_quantity
11
-
12
- def validate_inventory_quantity
13
- return unless quantity && sales_order_item
14
-
15
- inventory = Inventory.find_by(product_id: sales_order_item.customer_order_item.product_id)
16
- unless inventory
17
- errors.add(:base, "Inventory entry not found for product `#{sales_order_item.customer_order_item.product.name}`.")
18
- return
19
- end
20
-
21
- old_quantity = quantity_was || 0
22
- diff = inventory.quantity - (quantity - old_quantity)
23
- errors.add(:quantity, "exceeds available quantity in inventory by #{diff.abs}.") if diff.negative?
24
- end
25
-
26
- def update_inventory
27
- inventory = Inventory.find_by(product_id: sales_order_item.customer_order_item.product_id)
28
- return unless quantity_changed?
29
-
30
- old_quantity = quantity_was || 0
31
- diff = quantity - old_quantity
32
- inventory.quantity -= diff
33
- inventory.save!
34
- end
35
- end
36
- end
37
- end
@@ -1,17 +0,0 @@
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
@@ -1,17 +0,0 @@
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
@@ -1,7 +0,0 @@
1
- FactoryBot.define do
2
- factory :warehouse_shipment_item, class: "Comee::Core::WarehouseShipmentItem" do
3
- sales_order_item
4
- warehouse_shipment
5
- quantity { 10 }
6
- end
7
- end
@@ -1,9 +0,0 @@
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