comee_core 0.1.26 → 0.1.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/comee/core/warehouse_shipment.rb +45 -0
- data/app/models/comee/core/warehouse_shipment_item.rb +20 -9
- data/lib/comee/core/version.rb +1 -1
- data/spec/factories/comee/core/inventories.rb +1 -1
- data/spec/factories/comee/core/sales_order_items.rb +7 -1
- data/spec/factories/comee/core/warehouse_shipment_items.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4584d0f6f728f6ab957e59500e8a8af4564e0922558df83cb7562e9d9b094603
|
4
|
+
data.tar.gz: 5404312320bbcf4d482e5261a6c960dc1418d1e9051c1cfa810419cd872fef7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86745d97fac73d6fc66de542291014f4c1b6b57fb61bac5c8c31f523b7be03728b3109fad94750100ad40c6cbdca0305e448baaa5d399c52208ddb14ff2921a0
|
7
|
+
data.tar.gz: d4013f260e88c21628dc3eb1434718e949f3132e77b77d1daa58554fe6f33339da882772c43e6f6efc45d5d07230b0255b08b4fffa96cf7a91a179b0f6f6ab9c
|
@@ -16,6 +16,51 @@ module Comee
|
|
16
16
|
def self.ransackable_associations(_auth_object = nil)
|
17
17
|
[]
|
18
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
|
+
product_id: order_item.product_id,
|
41
|
+
quantity: order_item.quantity,
|
42
|
+
quantity_en_route: order_item.quantity_en_route + item.quantity,
|
43
|
+
quantity_remaining: order_item.quantity_remaining - item.quantity,
|
44
|
+
price: order_item.price,
|
45
|
+
delivery_date: order_item.delivery_date
|
46
|
+
}
|
47
|
+
end
|
48
|
+
SalesOrderItem.upsert_all(updates)
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def deliver
|
53
|
+
error = "Warehouse shipment should have an `acknowledged` status before delivery."
|
54
|
+
raise(StandardError, error) unless WarehouseShipment.statuses[status] == WarehouseShipment.statuses[:acknowledged]
|
55
|
+
|
56
|
+
self.status = WarehouseShipment.statuses[:delivered]
|
57
|
+
save!
|
58
|
+
order_items = warehouse_shipment_items.includes(:sales_order_item).map(&:sales_order_item)
|
59
|
+
return self unless order_items.count.positive?
|
60
|
+
|
61
|
+
SalesOrderItem.where(id: order_items.map(&:id)).update_all(quantity_en_route: 0)
|
62
|
+
self
|
63
|
+
end
|
19
64
|
end
|
20
65
|
end
|
21
66
|
end
|
@@ -1,25 +1,36 @@
|
|
1
1
|
module Comee
|
2
2
|
module Core
|
3
3
|
class WarehouseShipmentItem < ApplicationRecord
|
4
|
-
|
4
|
+
before_save :update_inventory
|
5
5
|
|
6
6
|
belongs_to :warehouse_shipment
|
7
7
|
belongs_to :sales_order_item
|
8
8
|
|
9
9
|
validates :quantity, presence: true
|
10
|
+
validate :validate_inventory_quantity
|
10
11
|
|
11
|
-
def
|
12
|
-
|
12
|
+
def validate_inventory_quantity
|
13
|
+
return unless quantity && sales_order_item
|
13
14
|
|
14
|
-
sales_order_item.
|
15
|
+
inventory = Inventory.find_by(product_id: sales_order_item.product_id)
|
16
|
+
unless inventory
|
17
|
+
errors.add(:base, "Inventory entry not found for product `#{sales_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?
|
15
24
|
end
|
16
25
|
|
17
|
-
def update_inventory
|
18
|
-
inventory = Inventory.find_by(product_id: product_id)
|
19
|
-
return unless
|
26
|
+
def update_inventory
|
27
|
+
inventory = Inventory.find_by(product_id: sales_order_item.product_id)
|
28
|
+
return unless quantity_changed?
|
20
29
|
|
21
|
-
|
22
|
-
|
30
|
+
old_quantity = quantity_was || 0
|
31
|
+
diff = quantity - old_quantity
|
32
|
+
inventory.quantity -= diff
|
33
|
+
inventory.save!
|
23
34
|
end
|
24
35
|
end
|
25
36
|
end
|
data/lib/comee/core/version.rb
CHANGED
@@ -4,8 +4,14 @@ FactoryBot.define do
|
|
4
4
|
product
|
5
5
|
quantity { 100 }
|
6
6
|
quantity_en_route { 0 }
|
7
|
-
quantity_remaining {
|
7
|
+
quantity_remaining { quantity }
|
8
8
|
price { 50 }
|
9
9
|
delivery_date { Date.current.advance(months: 1) }
|
10
|
+
|
11
|
+
trait :with_inventory do
|
12
|
+
after(:create) do |item|
|
13
|
+
create(:inventory, product: item.product, quantity: item.quantity + 100)
|
14
|
+
end
|
15
|
+
end
|
10
16
|
end
|
11
17
|
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.28
|
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-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 7.0
|
75
|
+
version: 7.1.0
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 7.0
|
82
|
+
version: 7.1.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: ransack
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|