comee_core 0.1.95 → 0.1.97

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) 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 -12
  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 +2 -1
  32. data/app/models/comee/core/sales_order.rb +1 -2
  33. data/app/models/comee/core/sales_order_item.rb +6 -1
  34. data/app/models/comee/core/supplier.rb +2 -0
  35. data/app/serializers/comee/core/agent_serializer.rb +7 -0
  36. data/app/serializers/comee/core/client_serializer.rb +4 -1
  37. data/app/serializers/comee/core/client_warehouse_serializer.rb +8 -0
  38. data/app/serializers/comee/core/contact_serializer.rb +7 -0
  39. data/app/serializers/comee/core/product_serializer.rb +2 -2
  40. data/app/serializers/comee/core/sales_order_item_serializer.rb +1 -1
  41. data/app/serializers/comee/core/supplier_serializer.rb +1 -0
  42. data/app/services/comee/core/customer_order_service.rb +7 -2
  43. data/config/routes.rb +7 -1
  44. data/db/migrate/20230728122618_create_comee_core_suppliers.rb +4 -0
  45. data/db/migrate/20230728123039_create_comee_core_clients.rb +4 -0
  46. data/db/migrate/20230728123458_create_comee_core_agents.rb +23 -0
  47. data/db/migrate/20230728123559_create_comee_core_contacts.rb +34 -0
  48. data/db/migrate/20230811102708_create_comee_core_customer_order_items.rb +1 -0
  49. data/db/migrate/20230812212844_create_comee_core_sales_order_items.rb +1 -0
  50. data/db/migrate/20230813235946_create_comee_core_master_prices.rb +1 -0
  51. data/db/migrate/20240119100125_create_comee_core_client_warehouses.rb +15 -0
  52. data/lib/comee/core/version.rb +1 -1
  53. data/spec/factories/comee/core/agents.rb +8 -0
  54. data/spec/factories/comee/core/client_warehouses.rb +8 -0
  55. data/spec/factories/comee/core/clients.rb +2 -1
  56. data/spec/factories/comee/core/contacts.rb +8 -0
  57. data/spec/factories/comee/core/customer_order_items.rb +1 -0
  58. data/spec/factories/comee/core/fulfillment_centers.rb +1 -1
  59. data/spec/factories/comee/core/master_prices.rb +1 -0
  60. data/spec/factories/comee/core/sales_order_items.rb +1 -0
  61. data/spec/factories/comee/core/suppliers.rb +1 -0
  62. metadata +35 -12
  63. data/app/models/comee/core/warehouse_shipment.rb +0 -70
  64. data/app/models/comee/core/warehouse_shipment_item.rb +0 -37
  65. data/db/migrate/20231003080017_create_comee_core_warehouse_shipments.rb +0 -17
  66. data/db/migrate/20231004105455_create_comee_core_warehouse_shipment_items.rb +0 -17
  67. data/spec/factories/comee/core/warehouse_shipment_items.rb +0 -7
  68. data/spec/factories/comee/core/warehouse_shipments.rb +0 -9
@@ -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