comee_core 0.1.51 → 0.1.53
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/customer_order_items_controller.rb +11 -1
- data/app/controllers/comee/core/products_controller.rb +14 -0
- data/app/controllers/comee/core/quotation_request_items_controller.rb +1 -0
- data/app/controllers/comee/core/quotation_requests_controller.rb +10 -1
- data/app/models/comee/core/customer_order.rb +1 -1
- data/app/models/comee/core/customer_order_item.rb +1 -1
- data/app/models/comee/core/quotation_request.rb +1 -1
- data/app/serializers/comee/core/customer_order_item_serializer.rb +1 -1
- data/app/serializers/comee/core/master_price_serializer.rb +9 -0
- data/app/serializers/comee/core/quotation_request_item_serializer.rb +1 -1
- data/app/serializers/comee/core/quotation_request_serializer.rb +1 -1
- data/app/services/comee/core/customer_order_service.rb +5 -2
- data/app/services/comee/core/quotation_request_service.rb +69 -3
- data/config/routes.rb +7 -1
- data/db/migrate/20230811083239_create_comee_core_customer_orders.rb +1 -1
- data/db/migrate/20230811102708_create_comee_core_customer_order_items.rb +1 -0
- data/db/migrate/20231121094339_create_comee_core_quotation_requests.rb +4 -0
- data/db/migrate/20231121132709_create_comee_core_quotation_request_items.rb +1 -0
- data/lib/comee/core/version.rb +1 -1
- data/spec/factories/comee/core/customer_order_items.rb +1 -0
- data/spec/factories/comee/core/quotation_request_items.rb +1 -0
- data/spec/factories/comee/core/quotation_requests.rb +4 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 738e68a65b4d7a96b3f0ea50a6e25da73e42d09f0ef888c49060a45ebc2fb39e
|
4
|
+
data.tar.gz: e42799a2bd3b0cfde406636e972ec258462df1df24dae8f4a051002eecc69294
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e680be5bdcf25fce5cd6fe5ee833c856fcf7eff59600b6cd8741a65d3713d36fd868bb6cac0bc25c2fe420c610ebce61617559b9da112ebdf214c818e5de407a
|
7
|
+
data.tar.gz: 343a4eff4586c0ea69d51960250a73766b710284c0f68724bbcb975f3b060080a288ca04e965dee8d7736d0e802af7fb3196f8f1ff841f494e9d5ec3cbd5fb40
|
@@ -27,7 +27,17 @@ module Comee
|
|
27
27
|
private
|
28
28
|
|
29
29
|
def model_params
|
30
|
-
params.require(:payload)
|
30
|
+
params.require(:payload)
|
31
|
+
.permit(
|
32
|
+
:customer_item_no,
|
33
|
+
:quantity,
|
34
|
+
:price,
|
35
|
+
:delivery_date,
|
36
|
+
:canceled,
|
37
|
+
:product_id,
|
38
|
+
:customer_order_id,
|
39
|
+
:unit_id
|
40
|
+
)
|
31
41
|
end
|
32
42
|
end
|
33
43
|
end
|
@@ -17,11 +17,25 @@ module Comee
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
def master_prices
|
21
|
+
data = MasterPrice.where(product_id: price_params[:product_ids])
|
22
|
+
render json: {success: true, data: serialize(data)}
|
23
|
+
end
|
24
|
+
|
25
|
+
def client_prices
|
26
|
+
data = ClientPrice.where(product_id: price_params[:product_ids])
|
27
|
+
render json: {success: true, data: serialize(data)}
|
28
|
+
end
|
29
|
+
|
20
30
|
private
|
21
31
|
|
22
32
|
def model_params
|
23
33
|
params.required(:payload).permit(:code, :name, :description, :parent_id, :thumbnail_image, :preferred_units, images: [])
|
24
34
|
end
|
35
|
+
|
36
|
+
def price_params
|
37
|
+
params.require(:payload).permit(product_ids: [])
|
38
|
+
end
|
25
39
|
end
|
26
40
|
end
|
27
41
|
end
|
@@ -52,10 +52,19 @@ module Comee
|
|
52
52
|
render json: {success: false, error: e.message}
|
53
53
|
end
|
54
54
|
|
55
|
+
def convert
|
56
|
+
service = QuotationRequestService.new
|
57
|
+
order = service.convert_to_order(params[:id])
|
58
|
+
render json: {success: true, data: serialize(order)}
|
59
|
+
rescue StandardError => e
|
60
|
+
render json: {success: false, error: e.message}
|
61
|
+
end
|
62
|
+
|
55
63
|
private
|
56
64
|
|
57
65
|
def model_params
|
58
|
-
params.require(:payload)
|
66
|
+
params.require(:payload)
|
67
|
+
.permit(:reference_no, :order_number, :order_date, :delivery_address, :invoice_address, :status, :client_id)
|
59
68
|
end
|
60
69
|
|
61
70
|
def rfq_params
|
@@ -7,7 +7,7 @@ module Comee
|
|
7
7
|
|
8
8
|
enum :status, {draft: 0, submitted: 1, awaiting_confirmation: 2, accepted: 3, canceled: 4}
|
9
9
|
|
10
|
-
validates :order_number, :order_date, :
|
10
|
+
validates :order_number, :order_date, :delivery_address, :invoice_address, :status, presence: true
|
11
11
|
|
12
12
|
def self.ransackable_attributes(_auth_object = nil)
|
13
13
|
%w[client_id delivery_address invoice_address order_number status]
|
@@ -5,7 +5,7 @@ module Comee
|
|
5
5
|
belongs_to :product
|
6
6
|
belongs_to :unit
|
7
7
|
|
8
|
-
validates :quantity, :price, :delivery_date, presence: true
|
8
|
+
validates :customer_item_no, :quantity, :price, :delivery_date, presence: true
|
9
9
|
|
10
10
|
def self.ransackable_attributes(_auth_object = nil)
|
11
11
|
%w[customer_order_id product_id unit_id]
|
@@ -6,7 +6,7 @@ module Comee
|
|
6
6
|
belongs_to :client
|
7
7
|
has_many :quotation_request_items
|
8
8
|
|
9
|
-
enum :status, {draft: 0, submitted: 1, awaiting_confirmation: 2, confirmed: 3}
|
9
|
+
enum :status, {draft: 0, submitted: 1, awaiting_confirmation: 2, confirmed: 3, converted: 4}
|
10
10
|
|
11
11
|
validates :status, presence: true
|
12
12
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Comee
|
2
2
|
module Core
|
3
3
|
class CustomerOrderItemSerializer < ActiveModel::Serializer
|
4
|
-
attributes :id, :quantity, :price, :delivery_date, :canceled
|
4
|
+
attributes :id, :customer_item_no, :quantity, :price, :delivery_date, :canceled
|
5
5
|
belongs_to :product
|
6
6
|
belongs_to :customer_order
|
7
7
|
belongs_to :unit
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Comee
|
2
2
|
module Core
|
3
3
|
class QuotationRequestItemSerializer < ActiveModel::Serializer
|
4
|
-
attributes :id, :price, :discount, :valid_from, :valid_to
|
4
|
+
attributes :id, :customer_item_no, :price, :discount, :valid_from, :valid_to
|
5
5
|
belongs_to :product
|
6
6
|
belongs_to :quotation_request
|
7
7
|
belongs_to :unit
|
@@ -44,7 +44,7 @@ module Comee
|
|
44
44
|
.or(UnitConversion.where("from_id = ? AND to_id = ?", new_unit_id, unit_id))
|
45
45
|
|
46
46
|
unless conversions.count.positive?
|
47
|
-
units = Unit.where(id: [unit_id, new_unit_id])
|
47
|
+
units = Unit.where(id: [unit_id, new_unit_id])
|
48
48
|
raise(StandardError, "There is no conversion factor between #{units[0].code} and #{units[1].code}.")
|
49
49
|
end
|
50
50
|
|
@@ -112,7 +112,10 @@ module Comee
|
|
112
112
|
raise(StandardError, "Customer order should be in submitted or awaiting confirmation state.")
|
113
113
|
end
|
114
114
|
|
115
|
-
|
115
|
+
if order.customer_order_items.count.zero? ||
|
116
|
+
order.customer_order_items.all?(&:canceled?)
|
117
|
+
raise(StandardError, "Customer order does not have any items.")
|
118
|
+
end
|
116
119
|
|
117
120
|
sales_order = nil
|
118
121
|
CustomerOrder.transaction do
|
@@ -4,7 +4,14 @@ module Comee
|
|
4
4
|
def create_request_with_items(params)
|
5
5
|
request = nil
|
6
6
|
QuotationRequest.transaction do
|
7
|
-
request = QuotationRequest.create!(
|
7
|
+
request = QuotationRequest.create!(
|
8
|
+
client_id: params[:client_id],
|
9
|
+
status: QuotationRequest.statuses[:draft],
|
10
|
+
order_number: params[:order_number],
|
11
|
+
order_date: params[:order_date],
|
12
|
+
delivery_address: params[:delivery_address],
|
13
|
+
invoice_address: params[:invoice_address]
|
14
|
+
)
|
8
15
|
items = params[:items]
|
9
16
|
items.each do |item|
|
10
17
|
item[:price] = 0
|
@@ -60,10 +67,69 @@ module Comee
|
|
60
67
|
raise(StandardError, "RFQ should be in awaiting_confirmation state.")
|
61
68
|
end
|
62
69
|
|
63
|
-
|
64
|
-
|
70
|
+
data = rfq.quotation_request_items.each_with_object([]) do |item, res|
|
71
|
+
res << {
|
72
|
+
client_id: rfq.client_id,
|
73
|
+
product_id: item.product_id,
|
74
|
+
unit_id: item.unit_id,
|
75
|
+
price: item.price,
|
76
|
+
discount: 0,
|
77
|
+
valid_from: item.valid_from,
|
78
|
+
valid_to: item.valid_to,
|
79
|
+
status: ClientPrice.statuses[:current]
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
ClientPrice.transaction do
|
84
|
+
ClientPrice.insert_all!(data)
|
85
|
+
rfq.status = QuotationRequest.statuses[:confirmed]
|
86
|
+
rfq.save!
|
87
|
+
end
|
65
88
|
rfq
|
66
89
|
end
|
90
|
+
|
91
|
+
def convert_to_order(id)
|
92
|
+
rfq = QuotationRequest.find(id)
|
93
|
+
if QuotationRequest.statuses[rfq.status] != QuotationRequest.statuses[:confirmed]
|
94
|
+
raise(StandardError, "RFQ should be in confirmed state for conversion to order.")
|
95
|
+
end
|
96
|
+
|
97
|
+
if rfq.quotation_request_items.any? { |item| item.customer_item_no.nil? }
|
98
|
+
raise(StandardError, "All RFQ items should have customer item number set.")
|
99
|
+
end
|
100
|
+
|
101
|
+
order = nil
|
102
|
+
CustomerOrder.transaction do
|
103
|
+
order = CustomerOrder.create!(
|
104
|
+
order_number: rfq.order_number,
|
105
|
+
order_date: Date.current,
|
106
|
+
client_id: rfq.client_id,
|
107
|
+
order_terms: "",
|
108
|
+
delivery_address: rfq.delivery_address,
|
109
|
+
invoice_address: rfq.invoice_address,
|
110
|
+
status: CustomerOrder.statuses[:draft]
|
111
|
+
)
|
112
|
+
|
113
|
+
items = rfq.quotation_request_items.each_with_object([]) do |item, res|
|
114
|
+
res << {
|
115
|
+
customer_order_id: order.id,
|
116
|
+
product_id: item.product_id,
|
117
|
+
unit_id: item.unit_id,
|
118
|
+
customer_item_no: item.customer_item_no,
|
119
|
+
quantity: item.quantity,
|
120
|
+
price: item.price,
|
121
|
+
delivery_date: item.expected_delivery_date,
|
122
|
+
canceled: false
|
123
|
+
}
|
124
|
+
end
|
125
|
+
|
126
|
+
CustomerOrderItem.insert_all!(items)
|
127
|
+
rfq.status = QuotationRequest.statuses[:converted]
|
128
|
+
rfq.save!
|
129
|
+
end
|
130
|
+
|
131
|
+
order
|
132
|
+
end
|
67
133
|
end
|
68
134
|
end
|
69
135
|
end
|
data/config/routes.rb
CHANGED
@@ -9,7 +9,12 @@ Comee::Core::Engine.routes.draw do
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
resources :suppliers
|
12
|
-
resources :products
|
12
|
+
resources :products do
|
13
|
+
collection do
|
14
|
+
post "master_prices"
|
15
|
+
post "client_prices"
|
16
|
+
end
|
17
|
+
end
|
13
18
|
resources :lookups
|
14
19
|
resources :quotation_requests do
|
15
20
|
collection do
|
@@ -20,6 +25,7 @@ Comee::Core::Engine.routes.draw do
|
|
20
25
|
post "submit"
|
21
26
|
post "submit_for_confirmation"
|
22
27
|
post "confirm"
|
28
|
+
post "convert"
|
23
29
|
end
|
24
30
|
end
|
25
31
|
resources :quotation_request_items do
|
@@ -7,7 +7,7 @@ class CreateComeeCoreCustomerOrders < ActiveRecord::Migration[7.1]
|
|
7
7
|
null: false,
|
8
8
|
index: {name: "client_on_cccuo_indx"},
|
9
9
|
foreign_key: {to_table: :comee_core_clients}
|
10
|
-
t.string :order_terms
|
10
|
+
t.string :order_terms
|
11
11
|
t.string :delivery_address, null: false
|
12
12
|
t.string :invoice_address, null: false
|
13
13
|
t.integer :status, null: false, default: 0
|
@@ -13,6 +13,7 @@ class CreateComeeCoreCustomerOrderItems < ActiveRecord::Migration[7.1]
|
|
13
13
|
null: false,
|
14
14
|
index: {name: "unit_on_cccuoi_indx"},
|
15
15
|
foreign_key: {to_table: :comee_core_units}
|
16
|
+
t.string :customer_item_no, null: false
|
16
17
|
t.float :quantity, null: false, default: 0
|
17
18
|
t.float :price, null: false, default: 0
|
18
19
|
t.date :delivery_date, null: false
|
@@ -2,6 +2,10 @@ class CreateComeeCoreQuotationRequests < ActiveRecord::Migration[7.1]
|
|
2
2
|
def change
|
3
3
|
create_table :comee_core_quotation_requests do |t|
|
4
4
|
t.string :reference_no, null: false
|
5
|
+
t.string :order_number, null: false
|
6
|
+
t.date :order_date, null: false
|
7
|
+
t.string :delivery_address, null: false
|
8
|
+
t.string :invoice_address, null: false
|
5
9
|
t.references :client,
|
6
10
|
null: false,
|
7
11
|
index: {name: "client_on_ccrfq_indx"},
|
@@ -9,6 +9,7 @@ class CreateComeeCoreQuotationRequestItems < ActiveRecord::Migration[7.1]
|
|
9
9
|
null: false,
|
10
10
|
index: {name: "rfq_on_ccrfqi_indx"},
|
11
11
|
foreign_key: {to_table: :comee_core_quotation_requests}
|
12
|
+
t.string :customer_item_no
|
12
13
|
t.float :quantity, null: false
|
13
14
|
t.float :price, null: false, default: 0
|
14
15
|
t.float :discount, null: false, default: 0
|
data/lib/comee/core/version.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :quotation_request, class: "Comee::Core::QuotationRequest" do
|
3
3
|
reference_no { "RFQ-#{client.code}-#{DateTime.now.to_i}" }
|
4
|
+
order_number { Faker::Alphanumeric.alpha(number: 10) }
|
5
|
+
order_date { Date.current }
|
6
|
+
delivery_address { Faker::Address.street_address }
|
7
|
+
invoice_address { Faker::Address.street_address }
|
4
8
|
client
|
5
9
|
status { 0 }
|
6
10
|
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.53
|
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-12-
|
11
|
+
date: 2023-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -353,6 +353,7 @@ files:
|
|
353
353
|
- app/serializers/comee/core/external_rfq_serializer.rb
|
354
354
|
- app/serializers/comee/core/item_status_serializer.rb
|
355
355
|
- app/serializers/comee/core/lookup_serializer.rb
|
356
|
+
- app/serializers/comee/core/master_price_serializer.rb
|
356
357
|
- app/serializers/comee/core/product_serializer.rb
|
357
358
|
- app/serializers/comee/core/product_type_serializer.rb
|
358
359
|
- app/serializers/comee/core/purchase_order_item_serializer.rb
|