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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5af8bf8f2c1f9cf058e249237279cb6ae6019d0189c549c8bd5c6f421d4774a
4
- data.tar.gz: 711689393088d435d720d49497d9e52e5db34cf15e4889fd4a020deb180fa0ae
3
+ metadata.gz: 4614aa569251964bb6f680e1aaaf6cba4f2ce8a64f45d54751e18ad62378b871
4
+ data.tar.gz: 0f8f41bf2828f2292ee6e65906bb47c8888ebae8ed79e8e978bd7e6cdc432878
5
5
  SHA512:
6
- metadata.gz: ce2b456011d92074efffb23b2a1ba2df3f6818bd8d487b888fa5c4a9353ae4cea90af41a7b4fb0e4567070b1583c1f4a11eb308bce465a01fd8666d05eb574b4
7
- data.tar.gz: ba7e824700d03d946fa3a1e30d4d0189dd0ac0b96a792482d10c611c70823eb345dfd75d8114e3905ffe48435cb231ba140cccbc180f524f92498af8ac2b84f9
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, :price,
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 :set_object, only: %i[show update confirm cancel]
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, validated: 1, authorized: 2, approved: 3, cancelled: 4, confirmed: 5, finalized: 6}
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
@@ -3,6 +3,7 @@ module Comee
3
3
  class SalesOrderItem < ApplicationRecord
4
4
  belongs_to :sales_order
5
5
  belongs_to :customer_order_item
6
+ belongs_to :product
6
7
  belongs_to :unit
7
8
  has_many :warehouse_shipment_items
8
9
 
@@ -52,6 +52,7 @@ module Comee
52
52
  res << {
53
53
  sales_order_id: sales_order.id,
54
54
  customer_order_item_id: item.id,
55
+ product_id: item.product_id,
55
56
  unit_id: item.unit_id,
56
57
  quantity: item.quantity,
57
58
  price: item.price,
@@ -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
@@ -76,7 +76,7 @@ Comee::Core::Engine.routes.draw do
76
76
  end
77
77
  member do
78
78
  get "items", controller: :sales_order_items, action: :index
79
- get "/sales_order/filter/", controller: :sales_orders, action: :filter
79
+ post "submit"
80
80
  post "confirm"
81
81
  post "cancel"
82
82
  end
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.1.41".freeze
3
+ VERSION = "0.1.43".freeze
4
4
  end
5
5
  end
@@ -2,6 +2,7 @@ FactoryBot.define do
2
2
  factory :sales_order_item, class: "Comee::Core::SalesOrderItem" do
3
3
  sales_order
4
4
  association :customer_order_item, :with_inventory
5
+ product
5
6
  unit
6
7
  quantity { 100 }
7
8
  quantity_delivered { 0 }
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.41
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-29 00:00:00.000000000 Z
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