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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 067fb1956bf9f0c318d443ac1bc3e57c92b98a7db3afcdaf0a4d0869a5df7989
4
- data.tar.gz: c70a6b57d486b4029dc66f4e07e3d8dce94ab3695b0623a582e8e5573e9b1120
3
+ metadata.gz: 3cefcb81eb41e5db7078a2de7c478cf2cf477bd747272e684a6acb7590f4df22
4
+ data.tar.gz: 355d9461d9208c214a99819e78242923d37027ec909e70e59d47021ce30700b1
5
5
  SHA512:
6
- metadata.gz: d3ac1e81c9d58317182cd37e470e4f92516201bddf1d77fc2c5e5412b045dfc340d8c55b6dea389f07059fc6c683bc825d1b25a23102dbbd319f83317e80d26e
7
- data.tar.gz: 943ec3ba980dbdfe273afa930fa30f7ad6200ff5085ee6552aec2af978012e8a933e23a0dacc94b2389792c262de0f1bf4dc9d09622864bf10111cbbaa8723df
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).permit(:sales_order_id, :customer_order_item_id, :product_id, :unit_id, :quantity, :quantity_delivered,
49
- :customer_item_no, :customer_item_description, :price, :handover_date, :delivery_date,
50
- :eb_number, :lead_time, :comment, :action_note, :purchase_order_item_id, :pallet_no, :source_id,
51
- :processing_status)
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
- canceled: 4
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: 3}
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
@@ -2,7 +2,6 @@ module Comee
2
2
  module Core
3
3
  class SupplierInvoice < ApplicationRecord
4
4
  belongs_to :purchase_order
5
- has_many :supplier_invoice_items
6
5
  has_many :supplier_payments
7
6
 
8
7
  enum :status, {draft: 0, approved: 1}
@@ -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, :price, :handover_date,
5
- :delivery_date, :eb_number, :lead_time, :comment, :action_note, :purchase_order_item_id, :total_price, :canceled,
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
- unless SalesOrder.statuses[order.status] == SalesOrder.statuses[:draft]
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
- unless SalesOrder.statuses[order.status] == SalesOrder.statuses[:submitted]
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 SalesOrder.statuses[order.status] == SalesOrder.statuses[:canceled]
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
@@ -10,6 +10,7 @@ class CreateComeeCorePurchaseOrders < ActiveRecord::Migration[7.1]
10
10
  t.integer :status, default: 0
11
11
  t.string :delivery_address, null: false
12
12
  t.date :delivery_date, null: false
13
+ t.float :total_price, default: 0
13
14
  t.string :terms
14
15
 
15
16
  t.timestamps
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.2.49".freeze
3
+ VERSION = "0.2.51".freeze
4
4
  end
5
5
  end
@@ -10,6 +10,7 @@ FactoryBot.define do
10
10
  customer_item_description { Faker::Lorem.sentence }
11
11
  quantity { 100 }
12
12
  quantity_delivered { 0 }
13
+ quantity_canceled { 0 }
13
14
  price { 50 }
14
15
  total_price { quantity * price }
15
16
  delivery_date { Date.current.advance(months: 1) }
@@ -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.49
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-03-29 00:00:00.000000000 Z
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,5 +0,0 @@
1
- class AddTotalPriceToPurchaseOrder < ActiveRecord::Migration[7.1]
2
- def change
3
- add_column :comee_core_purchase_orders, :total_price, :float, default: 0
4
- end
5
- 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
@@ -1,10 +0,0 @@
1
- FactoryBot.define do
2
- factory :supplier_invoice_item, class: "Comee::Core::SupplierInvoiceItem" do
3
- purchase_order_item
4
- supplier_invoice
5
- quantity { 10 }
6
- unit
7
- unit_price { 5 }
8
- total_price { quantity * unit_price }
9
- end
10
- end