comee_core 0.1.41 → 0.1.43
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 +2 -2
- data/app/controllers/comee/core/sales_orders_controller.rb +26 -15
- data/app/models/comee/core/sales_order.rb +1 -15
- data/app/models/comee/core/sales_order_item.rb +1 -0
- data/app/services/comee/core/customer_order_service.rb +1 -0
- data/app/services/comee/core/sales_order_service.rb +42 -0
- data/config/routes.rb +1 -1
- data/db/migrate/20230812212844_create_comee_core_sales_order_items.rb +5 -0
- data/lib/comee/core/version.rb +1 -1
- data/spec/factories/comee/core/sales_order_items.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4614aa569251964bb6f680e1aaaf6cba4f2ce8a64f45d54751e18ad62378b871
|
4
|
+
data.tar.gz: 0f8f41bf2828f2292ee6e65906bb47c8888ebae8ed79e8e978bd7e6cdc432878
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 743afdd1aac35780b96ace42f00eb9cf14fd29cfb4cff61412121288846f8574ce1f7c61b955038b0cb6a31a900267e90bb29d11cf880403d107bca0d45e06ba
|
7
|
+
data.tar.gz: 1d3d427ef671fa0cf13bdb50424c6f4bd93edbc2822090dcc0dcb428e710a84547a14e5231815f892b05b2aa2886446053dd455ff5a36a11d3842488b41e8f6e
|
@@ -17,8 +17,8 @@ module Comee
|
|
17
17
|
private
|
18
18
|
|
19
19
|
def model_params
|
20
|
-
params.require(:payload).permit(:sales_order_id, :customer_order_item_id, :unit_id, :quantity, :quantity_delivered,
|
21
|
-
:delivery_date, :eb_number)
|
20
|
+
params.require(:payload).permit(:sales_order_id, :customer_order_item_id, :product_id, :unit_id, :quantity, :quantity_delivered,
|
21
|
+
:price, :delivery_date, :eb_number)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -2,21 +2,7 @@ module Comee
|
|
2
2
|
module Core
|
3
3
|
class SalesOrdersController < ApplicationController
|
4
4
|
include Common
|
5
|
-
before_action :
|
6
|
-
|
7
|
-
def confirm
|
8
|
-
@obj.confirm
|
9
|
-
render json: {success: true, data: serialize(@obj.reload)}
|
10
|
-
rescue StandardError => e
|
11
|
-
render json: {success: false, error: e.message}
|
12
|
-
end
|
13
|
-
|
14
|
-
def cancel
|
15
|
-
@obj.cancel
|
16
|
-
render json: {success: true, data: serialize(@obj.reload)}
|
17
|
-
rescue StandardError => e
|
18
|
-
render json: {success: false, error: e.message}
|
19
|
-
end
|
5
|
+
before_action :set_service, only: %i[submit confirm cancel]
|
20
6
|
|
21
7
|
def index
|
22
8
|
super do
|
@@ -29,6 +15,27 @@ module Comee
|
|
29
15
|
render json: {success: true, data: serialize(@sales_order)}
|
30
16
|
end
|
31
17
|
|
18
|
+
def submit
|
19
|
+
order = @service.submit(params[:id])
|
20
|
+
render json: {success: true, data: serialize(order)}
|
21
|
+
rescue StandardError => e
|
22
|
+
render json: {success: false, error: e.message}
|
23
|
+
end
|
24
|
+
|
25
|
+
def confirm
|
26
|
+
order = @service.confirm(params[:id])
|
27
|
+
render json: {success: true, data: serialize(order)}
|
28
|
+
rescue StandardError => e
|
29
|
+
render json: {success: false, error: e.message}
|
30
|
+
end
|
31
|
+
|
32
|
+
def cancel
|
33
|
+
order = @service.cancel(params[:id])
|
34
|
+
render json: {success: true, data: serialize(order)}
|
35
|
+
rescue StandardError => e
|
36
|
+
render json: {success: false, error: e.message}
|
37
|
+
end
|
38
|
+
|
32
39
|
private
|
33
40
|
|
34
41
|
def model_params
|
@@ -40,6 +47,10 @@ module Comee
|
|
40
47
|
params.permit(payload: [:supplier_id, :order_number, :order_date, :delivery_date, :delivery_address, :invoice_address,
|
41
48
|
back_order_items: %i[product_id requested_quantity requested_price supplier_quantity delivery_date]])
|
42
49
|
end
|
50
|
+
|
51
|
+
def set_service
|
52
|
+
@service = SalesOrderService.new
|
53
|
+
end
|
43
54
|
end
|
44
55
|
end
|
45
56
|
end
|
@@ -6,7 +6,7 @@ module Comee
|
|
6
6
|
belongs_to :customer_order
|
7
7
|
has_many :sales_order_items
|
8
8
|
|
9
|
-
enum :status, {draft: 0,
|
9
|
+
enum :status, {draft: 0, submitted: 1, confirmed: 2, canceled: 3}
|
10
10
|
|
11
11
|
validates :order_number, presence: true, uniqueness: true
|
12
12
|
validates :status, presence: true
|
@@ -25,20 +25,6 @@ module Comee
|
|
25
25
|
self.total_price = total_price
|
26
26
|
end
|
27
27
|
|
28
|
-
def confirm
|
29
|
-
raise(StandardError, "Sales order is already confirmed.") if SalesOrder.statuses[status] == SalesOrder.statuses[:confirmed]
|
30
|
-
|
31
|
-
self.status = SalesOrder.statuses[:confirmed]
|
32
|
-
save
|
33
|
-
end
|
34
|
-
|
35
|
-
def cancel
|
36
|
-
raise(StandardError, "Sales order is already cancelled.") if SalesOrder.statuses[status] == SalesOrder.statuses[:cancelled]
|
37
|
-
|
38
|
-
self.status = SalesOrder.statuses[:cancelled]
|
39
|
-
save
|
40
|
-
end
|
41
|
-
|
42
28
|
def self.ransackable_attributes(_auth_object = nil)
|
43
29
|
%w[
|
44
30
|
order_number
|
@@ -136,6 +136,48 @@ module Comee
|
|
136
136
|
rescue StandardError => e
|
137
137
|
{success: false, error: e.message}
|
138
138
|
end
|
139
|
+
|
140
|
+
def submit(id)
|
141
|
+
order = SalesOrder.find_by(id: id)
|
142
|
+
raise(StandardError, "Sales order with id `#{id}` not found.") unless order
|
143
|
+
|
144
|
+
unless SalesOrder.statuses[order.status] == SalesOrder.statuses[:draft]
|
145
|
+
raise(StandardError, "Sales order should be in draft state.")
|
146
|
+
end
|
147
|
+
|
148
|
+
raise(StandardError, "Sales order should have at least one item.") unless order.sales_order_items.count.positive?
|
149
|
+
|
150
|
+
raise(StandardError, "All items are canceled for sales order.") if order.sales_order_items.all?(&:canceled?)
|
151
|
+
|
152
|
+
order.update!(status: SalesOrder.statuses[:submitted])
|
153
|
+
order
|
154
|
+
end
|
155
|
+
|
156
|
+
def confirm(id)
|
157
|
+
order = SalesOrder.find_by(id: id)
|
158
|
+
raise(StandardError, "Sales order with id `#{id}` not found.") unless order
|
159
|
+
|
160
|
+
unless SalesOrder.statuses[order.status] == SalesOrder.statuses[:submitted]
|
161
|
+
raise(StandardError, "Sales order should be in submitted state.")
|
162
|
+
end
|
163
|
+
|
164
|
+
raise(StandardError, "Sales order should have at least one item.") unless order.sales_order_items.count.positive?
|
165
|
+
|
166
|
+
raise(StandardError, "All items are canceled for sales order.") if order.sales_order_items.all?(&:canceled?)
|
167
|
+
|
168
|
+
order.update!(status: SalesOrder.statuses[:confirmed])
|
169
|
+
order
|
170
|
+
end
|
171
|
+
|
172
|
+
def cancel(id)
|
173
|
+
order = SalesOrder.find_by(id: id)
|
174
|
+
raise(StandardError, "Sales order with id `#{id}` not found.") unless order
|
175
|
+
|
176
|
+
raise(StandardError, "Sales order is already canceled.") if SalesOrder.statuses[order.status] == SalesOrder.statuses[:canceled]
|
177
|
+
|
178
|
+
order.update!(status: SalesOrder.statuses[:canceled])
|
179
|
+
order
|
180
|
+
end
|
139
181
|
end
|
140
182
|
end
|
141
183
|
end
|
data/config/routes.rb
CHANGED
@@ -5,6 +5,10 @@ class CreateComeeCoreSalesOrderItems < ActiveRecord::Migration[7.0]
|
|
5
5
|
null: false,
|
6
6
|
index: {name: "so_on_ccsoi_indx"},
|
7
7
|
foreign_key: {to_table: :comee_core_sales_orders}
|
8
|
+
t.references :product,
|
9
|
+
null: false,
|
10
|
+
index: {name: "product_on_ccsoi_indx"},
|
11
|
+
foreign_key: {to_table: :comee_core_products}
|
8
12
|
t.references :unit,
|
9
13
|
null: false,
|
10
14
|
index: {name: "unit_on_ccsoi_indx"},
|
@@ -17,6 +21,7 @@ class CreateComeeCoreSalesOrderItems < ActiveRecord::Migration[7.0]
|
|
17
21
|
t.float :quantity_delivered, null: false, default: 0
|
18
22
|
t.float :price, null: false
|
19
23
|
t.date :delivery_date, null: false
|
24
|
+
t.boolean :canceled, default: false
|
20
25
|
t.date :handover_date
|
21
26
|
t.string :eb_number
|
22
27
|
|
data/lib/comee/core/version.rb
CHANGED
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.43
|
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-11-
|
11
|
+
date: 2023-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|