comee_core 0.2.49 → 0.2.51
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/sales_order_items_controller.rb +21 -4
- data/app/controllers/comee/core/sales_orders_controller.rb +8 -1
- data/app/models/comee/core/purchase_order.rb +3 -1
- data/app/models/comee/core/purchase_order_item.rb +2 -0
- data/app/models/comee/core/sales_order.rb +1 -1
- data/app/models/comee/core/sales_order_item.rb +7 -1
- data/app/models/comee/core/supplier_invoice.rb +0 -1
- data/app/serializers/comee/core/sales_order_item_serializer.rb +3 -4
- data/app/services/comee/core/sales_order_service.rb +31 -7
- data/config/routes.rb +2 -0
- data/db/migrate/20230728123823_create_comee_core_purchase_orders.rb +1 -0
- data/db/migrate/20230812212844_create_comee_core_sales_order_items.rb +1 -0
- data/lib/comee/core/version.rb +1 -1
- data/spec/factories/comee/core/sales_order_items.rb +1 -0
- data/spec/factories/comee/core/sales_orders.rb +16 -0
- metadata +2 -6
- data/app/models/comee/core/supplier_invoice_item.rb +0 -20
- data/db/migrate/20240328033103_add_total_price_to_purchase_order.rb +0 -5
- data/db/migrate/20240328132625_create_comee_core_supplier_invoice_items.rb +0 -23
- data/spec/factories/comee/core/supplier_invoice_items.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cefcb81eb41e5db7078a2de7c478cf2cf477bd747272e684a6acb7590f4df22
|
4
|
+
data.tar.gz: 355d9461d9208c214a99819e78242923d37027ec909e70e59d47021ce30700b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfa1546039693c3138a202c59391fc169c579b465c9ede57808f9c61f7995324108cd25cbb79d7527bcfcd95e9b0205e2fa9c2687c5b34a6a07a3998fa4a26de
|
7
|
+
data.tar.gz: 5f9ea82e05e6467269bc8cf9fd5815c87dad8668df654ad8a5a0ce17bd94daa77e48415349c718f304de4212f82b94538c10f553dba4a96bed42a29a4134e93e
|
@@ -27,6 +27,18 @@ module Comee
|
|
27
27
|
render_content(item)
|
28
28
|
end
|
29
29
|
|
30
|
+
def cancel_quantity
|
31
|
+
item = set_object
|
32
|
+
to_cancel = cancel_quantity_params[:quantity]
|
33
|
+
raise(StandardError, "Quantity to cancel is greater than available quantity.") if to_cancel > item.quantity_remaining
|
34
|
+
|
35
|
+
item.quantity_canceled += to_cancel
|
36
|
+
item.save!
|
37
|
+
render_content(item)
|
38
|
+
rescue StandardError => e
|
39
|
+
render_error(e)
|
40
|
+
end
|
41
|
+
|
30
42
|
def activate
|
31
43
|
item = set_object
|
32
44
|
item.update(canceled: false)
|
@@ -45,10 +57,15 @@ module Comee
|
|
45
57
|
end
|
46
58
|
|
47
59
|
def model_params
|
48
|
-
params.require(:payload)
|
49
|
-
|
50
|
-
|
51
|
-
|
60
|
+
params.require(:payload)
|
61
|
+
.permit(:sales_order_id, :customer_order_item_id, :product_id, :unit_id, :quantity, :quantity_delivered,
|
62
|
+
:quantity_canceled, :customer_item_no, :customer_item_description, :price, :handover_date,
|
63
|
+
:delivery_date, :eb_number, :lead_time, :comment, :action_note, :purchase_order_item_id, :pallet_no,
|
64
|
+
:source_id, :processing_status)
|
65
|
+
end
|
66
|
+
|
67
|
+
def cancel_quantity_params
|
68
|
+
params.require(:payload).permit(:quantity)
|
52
69
|
end
|
53
70
|
end
|
54
71
|
end
|
@@ -2,7 +2,7 @@ module Comee
|
|
2
2
|
module Core
|
3
3
|
class SalesOrdersController < ApplicationController
|
4
4
|
include Common
|
5
|
-
before_action :set_service, only: %i[submit confirm cancel]
|
5
|
+
before_action :set_service, only: %i[submit confirm accept cancel]
|
6
6
|
|
7
7
|
def index
|
8
8
|
super do
|
@@ -75,6 +75,13 @@ module Comee
|
|
75
75
|
render json: {success: false, error: e.message}
|
76
76
|
end
|
77
77
|
|
78
|
+
def accept
|
79
|
+
order = @service.accept(params[:id])
|
80
|
+
render_content(order)
|
81
|
+
rescue StandardError => e
|
82
|
+
render json: {success: false, error: e.message}
|
83
|
+
end
|
84
|
+
|
78
85
|
def cancel
|
79
86
|
order = @service.cancel(params[:id])
|
80
87
|
render_content(order)
|
@@ -13,7 +13,8 @@ module Comee
|
|
13
13
|
submitted: 1,
|
14
14
|
approved: 2,
|
15
15
|
confirmed: 3,
|
16
|
-
|
16
|
+
accepted: 4,
|
17
|
+
canceled: 5
|
17
18
|
}
|
18
19
|
|
19
20
|
def total_price
|
@@ -24,6 +25,7 @@ module Comee
|
|
24
25
|
def self.ransackable_attributes(_auth_object = nil)
|
25
26
|
%w[
|
26
27
|
id
|
28
|
+
po_number
|
27
29
|
supplier_id
|
28
30
|
unit_id
|
29
31
|
order_date
|
@@ -15,6 +15,8 @@ module Comee
|
|
15
15
|
validates :price, presence: true, numericality: {greater_than_or_equal_to: 0}
|
16
16
|
validates :status, :delivery_date, presence: true
|
17
17
|
|
18
|
+
delegate(:po_number, to: :purchase_order, prefix: false)
|
19
|
+
|
18
20
|
def calculate_total_price
|
19
21
|
self.total_price = price * quantity
|
20
22
|
end
|
@@ -11,7 +11,7 @@ module Comee
|
|
11
11
|
has_many_attached :files
|
12
12
|
has_one :customs_detail
|
13
13
|
|
14
|
-
enum :status, {draft: 0, submitted: 1, confirmed: 2, canceled:
|
14
|
+
enum :status, {draft: 0, submitted: 1, confirmed: 2, accepted: 3, canceled: 4}
|
15
15
|
|
16
16
|
validates :order_number, presence: true, uniqueness: true
|
17
17
|
validates :order_date, :status, presence: true
|
@@ -15,12 +15,18 @@ module Comee
|
|
15
15
|
|
16
16
|
validates :customer_item_no, :customer_item_description, :delivery_date, :processing_status, presence: true
|
17
17
|
validates :quantity, :price, presence: true, numericality: {greater_than: 0}
|
18
|
-
validates :quantity_delivered, numericality: {greater_than_or_equal_to: 0}
|
18
|
+
validates :quantity_delivered, :quantity_canceled, numericality: {greater_than_or_equal_to: 0}
|
19
|
+
|
20
|
+
delegate(:po_number, to: :purchase_order_item, prefix: false, allow_nil: true)
|
19
21
|
|
20
22
|
def calculate_total_price
|
21
23
|
self.total_price = price * quantity
|
22
24
|
end
|
23
25
|
|
26
|
+
def quantity_remaining
|
27
|
+
quantity - (quantity_delivered + quantity_canceled)
|
28
|
+
end
|
29
|
+
|
24
30
|
def self.ransackable_attributes(_auth_object = nil)
|
25
31
|
%w[
|
26
32
|
id
|
@@ -1,10 +1,9 @@
|
|
1
1
|
module Comee
|
2
2
|
module Core
|
3
3
|
class SalesOrderItemSerializer < ActiveModel::Serializer
|
4
|
-
attributes :id, :customer_item_no, :customer_item_description, :quantity, :quantity_delivered, :
|
5
|
-
:delivery_date, :eb_number, :lead_time, :comment, :action_note, :purchase_order_item_id,
|
6
|
-
:processing_status
|
7
|
-
|
4
|
+
attributes :id, :customer_item_no, :customer_item_description, :quantity, :quantity_delivered, :quantity_canceled,
|
5
|
+
:price, :handover_date, :delivery_date, :eb_number, :lead_time, :comment, :action_note, :purchase_order_item_id,
|
6
|
+
:total_price, :canceled, :processing_status
|
8
7
|
belongs_to :sales_order
|
9
8
|
belongs_to :customer_order_item
|
10
9
|
belongs_to :source
|
@@ -141,9 +141,7 @@ module Comee
|
|
141
141
|
order = SalesOrder.find_by(id: id)
|
142
142
|
raise(StandardError, "Sales order with id `#{id}` not found.") unless order
|
143
143
|
|
144
|
-
|
145
|
-
raise(StandardError, "Sales order should be in draft state.")
|
146
|
-
end
|
144
|
+
raise(StandardError, "Sales order should be in draft state.") unless order.draft?
|
147
145
|
|
148
146
|
raise(StandardError, "Sales order should have at least one item.") unless order.sales_order_items.count.positive?
|
149
147
|
|
@@ -153,13 +151,25 @@ module Comee
|
|
153
151
|
order
|
154
152
|
end
|
155
153
|
|
154
|
+
# def approve(id)
|
155
|
+
# order = SalesOrder.find_by(id: id)
|
156
|
+
# raise(StandardError, "Sales order with id `#{id}` not found.") unless order
|
157
|
+
|
158
|
+
# raise(StandardError, "Sales order should be in submitted state.") unless order.submitted?
|
159
|
+
|
160
|
+
# raise(StandardError, "Sales order should have at least one item.") unless order.sales_order_items.count.positive?
|
161
|
+
|
162
|
+
# raise(StandardError, "All items are canceled for sales order.") if order.sales_order_items.all?(&:canceled?)
|
163
|
+
|
164
|
+
# order.update!(status: SalesOrder.statuses[:approved])
|
165
|
+
# order
|
166
|
+
# end
|
167
|
+
|
156
168
|
def confirm(id)
|
157
169
|
order = SalesOrder.find_by(id: id)
|
158
170
|
raise(StandardError, "Sales order with id `#{id}` not found.") unless order
|
159
171
|
|
160
|
-
|
161
|
-
raise(StandardError, "Sales order should be in submitted state.")
|
162
|
-
end
|
172
|
+
raise(StandardError, "Sales order should be in submitted state.") unless order.submitted?
|
163
173
|
|
164
174
|
raise(StandardError, "Sales order should have at least one item.") unless order.sales_order_items.count.positive?
|
165
175
|
|
@@ -169,11 +179,25 @@ module Comee
|
|
169
179
|
order
|
170
180
|
end
|
171
181
|
|
182
|
+
def accept(id)
|
183
|
+
order = SalesOrder.find_by(id: id)
|
184
|
+
raise(StandardError, "Sales order with id `#{id}` not found.") unless order
|
185
|
+
|
186
|
+
raise(StandardError, "Sales order should be in confirmed state.") unless order.confirmed?
|
187
|
+
|
188
|
+
raise(StandardError, "Sales order should have at least one item.") unless order.sales_order_items.count.positive?
|
189
|
+
|
190
|
+
raise(StandardError, "All items are canceled for sales order.") if order.sales_order_items.all?(&:canceled?)
|
191
|
+
|
192
|
+
order.update!(status: SalesOrder.statuses[:accepted])
|
193
|
+
order
|
194
|
+
end
|
195
|
+
|
172
196
|
def cancel(id)
|
173
197
|
order = SalesOrder.find_by(id: id)
|
174
198
|
raise(StandardError, "Sales order with id `#{id}` not found.") unless order
|
175
199
|
|
176
|
-
raise(StandardError, "Sales order is already canceled.") if
|
200
|
+
raise(StandardError, "Sales order is already canceled.") if order.canceled?
|
177
201
|
|
178
202
|
order.update!(status: SalesOrder.statuses[:canceled])
|
179
203
|
order
|
data/config/routes.rb
CHANGED
@@ -111,6 +111,7 @@ Comee::Core::Engine.routes.draw do
|
|
111
111
|
post "suggest", controller: :sales_order_items, action: :suggest_values
|
112
112
|
post "cancel"
|
113
113
|
post "activate"
|
114
|
+
post "cancel_quantity"
|
114
115
|
end
|
115
116
|
end
|
116
117
|
resources :shipment_items do
|
@@ -128,6 +129,7 @@ Comee::Core::Engine.routes.draw do
|
|
128
129
|
get "items", controller: :sales_order_items, action: :index
|
129
130
|
post "submit"
|
130
131
|
post "confirm"
|
132
|
+
post "accept"
|
131
133
|
post "cancel"
|
132
134
|
end
|
133
135
|
end
|
@@ -29,6 +29,7 @@ class CreateComeeCoreSalesOrderItems < ActiveRecord::Migration[7.0]
|
|
29
29
|
t.string :customer_item_description, null: false
|
30
30
|
t.float :quantity, null: false
|
31
31
|
t.float :quantity_delivered, null: false, default: 0
|
32
|
+
t.float :quantity_canceled, null: false, default: 0
|
32
33
|
t.float :price, null: false
|
33
34
|
t.float :total_price, null: false
|
34
35
|
t.date :delivery_date, null: false
|
data/lib/comee/core/version.rb
CHANGED
@@ -24,5 +24,21 @@ FactoryBot.define do
|
|
24
24
|
pallete_note { Faker::Lorem.sentence }
|
25
25
|
remark { Faker::Lorem.sentence }
|
26
26
|
created_by { Faker::Name.name }
|
27
|
+
|
28
|
+
trait :submitted do
|
29
|
+
status { Comee::Core::SalesOrder.statuses[:submitted] }
|
30
|
+
end
|
31
|
+
|
32
|
+
trait :confirmed do
|
33
|
+
status { Comee::Core::SalesOrder.statuses[:confirmed] }
|
34
|
+
end
|
35
|
+
|
36
|
+
trait :accepted do
|
37
|
+
status { Comee::Core::SalesOrder.statuses[:accepted] }
|
38
|
+
end
|
39
|
+
|
40
|
+
trait :canceled do
|
41
|
+
status { Comee::Core::SalesOrder.statuses[:canceled] }
|
42
|
+
end
|
27
43
|
end
|
28
44
|
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.2.
|
4
|
+
version: 0.2.51
|
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-
|
11
|
+
date: 2024-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -345,7 +345,6 @@ files:
|
|
345
345
|
- app/models/comee/core/shipment_item.rb
|
346
346
|
- app/models/comee/core/supplier.rb
|
347
347
|
- app/models/comee/core/supplier_invoice.rb
|
348
|
-
- app/models/comee/core/supplier_invoice_item.rb
|
349
348
|
- app/models/comee/core/supplier_payment.rb
|
350
349
|
- app/models/comee/core/time_slot.rb
|
351
350
|
- app/models/comee/core/transport_availability.rb
|
@@ -443,9 +442,7 @@ files:
|
|
443
442
|
- db/migrate/20240314111117_create_comee_core_purchase_requisitions.rb
|
444
443
|
- db/migrate/20240314111307_create_comee_core_purchase_requisition_items.rb
|
445
444
|
- db/migrate/20240325155406_create_comee_core_purchase_order_item_diffs.rb
|
446
|
-
- db/migrate/20240328033103_add_total_price_to_purchase_order.rb
|
447
445
|
- db/migrate/20240328132454_create_comee_core_supplier_invoices.rb
|
448
|
-
- db/migrate/20240328132625_create_comee_core_supplier_invoice_items.rb
|
449
446
|
- db/migrate/20240328132713_create_comee_core_payment_orders.rb
|
450
447
|
- db/migrate/20240328132921_create_comee_core_supplier_payments.rb
|
451
448
|
- lib/comee/core.rb
|
@@ -497,7 +494,6 @@ files:
|
|
497
494
|
- spec/factories/comee/core/shipment_instruction_items.rb
|
498
495
|
- spec/factories/comee/core/shipment_instructions.rb
|
499
496
|
- spec/factories/comee/core/shipment_items.rb
|
500
|
-
- spec/factories/comee/core/supplier_invoice_items.rb
|
501
497
|
- spec/factories/comee/core/supplier_invoices.rb
|
502
498
|
- spec/factories/comee/core/supplier_payments.rb
|
503
499
|
- spec/factories/comee/core/suppliers.rb
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module Comee
|
2
|
-
module Core
|
3
|
-
class SupplierInvoiceItem < ApplicationRecord
|
4
|
-
before_save { self.total_price = unit_price * quantity }
|
5
|
-
after_save :update_invoice_price
|
6
|
-
|
7
|
-
belongs_to :purchase_order_item
|
8
|
-
belongs_to :supplier_invoice
|
9
|
-
belongs_to :unit
|
10
|
-
|
11
|
-
validates :quantity, :unit_price, presence: true, numericality: {greater_than: 0}
|
12
|
-
validates :total_price, numericality: {greater_than_or_equal_to: 0, allow_nil: true}
|
13
|
-
|
14
|
-
def update_invoice_price
|
15
|
-
supplier_invoice.total_price = supplier_invoice.supplier_invoice_items.sum(:total_price)
|
16
|
-
supplier_invoice.save!
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
class CreateComeeCoreSupplierInvoiceItems < ActiveRecord::Migration[7.1]
|
2
|
-
def change
|
3
|
-
create_table :comee_core_supplier_invoice_items do |t|
|
4
|
-
t.references :purchase_order_item,
|
5
|
-
null: false,
|
6
|
-
index: {name: "poi_on_ccsii_indx"},
|
7
|
-
foreign_key: {to_table: :comee_core_purchase_order_items}
|
8
|
-
t.references :supplier_invoice,
|
9
|
-
null: false,
|
10
|
-
index: {name: "si_on_ccsii2_indx"},
|
11
|
-
foreign_key: {to_table: :comee_core_supplier_invoices}
|
12
|
-
t.float :quantity, null: false
|
13
|
-
t.references :unit,
|
14
|
-
null: false,
|
15
|
-
index: {name: "unit_on_ccsii2_indx"},
|
16
|
-
foreign_key: {to_table: :comee_core_units}
|
17
|
-
t.float :unit_price, null: false
|
18
|
-
t.float :total_price
|
19
|
-
|
20
|
-
t.timestamps
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|