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.
- checksums.yaml +4 -4
- data/app/controllers/comee/core/agents_controller.rb +13 -0
- data/app/controllers/comee/core/application_controller.rb +15 -2
- data/app/controllers/comee/core/back_orders_controller.rb +2 -2
- data/app/controllers/comee/core/client_prices_controller.rb +3 -10
- data/app/controllers/comee/core/client_warehouses_controller.rb +13 -0
- data/app/controllers/comee/core/clients_controller.rb +42 -9
- data/app/controllers/comee/core/contacts_controller.rb +13 -0
- data/app/controllers/comee/core/customer_order_items_controller.rb +3 -2
- data/app/controllers/comee/core/customer_orders_controller.rb +3 -3
- data/app/controllers/comee/core/item_statuses_controller.rb +2 -2
- data/app/controllers/comee/core/notifications_controller.rb +4 -4
- data/app/controllers/comee/core/product_lookups_controller.rb +2 -2
- data/app/controllers/comee/core/products_controller.rb +7 -9
- data/app/controllers/comee/core/purchase_order_items_controller.rb +2 -2
- data/app/controllers/comee/core/purchase_orders_controller.rb +2 -2
- data/app/controllers/comee/core/quotation_request_items_controller.rb +2 -2
- data/app/controllers/comee/core/quotation_requests_controller.rb +8 -9
- data/app/controllers/comee/core/sales_order_items_controller.rb +1 -1
- data/app/controllers/comee/core/sales_orders_controller.rb +13 -7
- data/app/controllers/comee/core/shipment_items_controller.rb +13 -12
- data/app/controllers/comee/core/suppliers_controller.rb +4 -6
- data/app/controllers/comee/core/unit_conversions_controller.rb +1 -1
- data/app/controllers/comee/core/units_controller.rb +1 -1
- data/app/controllers/concerns/comee/core/common.rb +33 -7
- data/app/models/comee/core/agent.rb +7 -0
- data/app/models/comee/core/client.rb +4 -1
- data/app/models/comee/core/client_warehouse.rb +8 -0
- data/app/models/comee/core/contact.rb +7 -0
- data/app/models/comee/core/customer_order_item.rb +6 -0
- data/app/models/comee/core/master_price.rb +2 -1
- data/app/models/comee/core/sales_order.rb +1 -2
- data/app/models/comee/core/sales_order_item.rb +6 -1
- data/app/models/comee/core/supplier.rb +2 -0
- data/app/serializers/comee/core/agent_serializer.rb +7 -0
- data/app/serializers/comee/core/client_serializer.rb +4 -1
- data/app/serializers/comee/core/client_warehouse_serializer.rb +8 -0
- data/app/serializers/comee/core/contact_serializer.rb +7 -0
- data/app/serializers/comee/core/product_serializer.rb +2 -2
- data/app/serializers/comee/core/sales_order_item_serializer.rb +1 -1
- data/app/serializers/comee/core/supplier_serializer.rb +1 -0
- data/app/services/comee/core/customer_order_service.rb +7 -2
- data/config/routes.rb +7 -1
- data/db/migrate/20230728122618_create_comee_core_suppliers.rb +4 -0
- data/db/migrate/20230728123039_create_comee_core_clients.rb +4 -0
- data/db/migrate/20230728123458_create_comee_core_agents.rb +23 -0
- data/db/migrate/20230728123559_create_comee_core_contacts.rb +34 -0
- data/db/migrate/20230811102708_create_comee_core_customer_order_items.rb +1 -0
- data/db/migrate/20230812212844_create_comee_core_sales_order_items.rb +1 -0
- data/db/migrate/20230813235946_create_comee_core_master_prices.rb +1 -0
- data/db/migrate/20240119100125_create_comee_core_client_warehouses.rb +15 -0
- data/lib/comee/core/version.rb +1 -1
- data/spec/factories/comee/core/agents.rb +8 -0
- data/spec/factories/comee/core/client_warehouses.rb +8 -0
- data/spec/factories/comee/core/clients.rb +2 -1
- data/spec/factories/comee/core/contacts.rb +8 -0
- data/spec/factories/comee/core/customer_order_items.rb +1 -0
- data/spec/factories/comee/core/fulfillment_centers.rb +1 -1
- data/spec/factories/comee/core/master_prices.rb +1 -0
- data/spec/factories/comee/core/sales_order_items.rb +1 -0
- data/spec/factories/comee/core/suppliers.rb +1 -0
- metadata +35 -12
- data/app/models/comee/core/warehouse_shipment.rb +0 -70
- data/app/models/comee/core/warehouse_shipment_item.rb +0 -37
- data/db/migrate/20231003080017_create_comee_core_warehouse_shipments.rb +0 -17
- data/db/migrate/20231004105455_create_comee_core_warehouse_shipment_items.rb +0 -17
- data/spec/factories/comee/core/warehouse_shipment_items.rb +0 -7
- 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,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
|