comee_core 0.2.11 → 0.2.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/comee/core/customer_order_items_controller.rb +1 -0
  3. data/app/controllers/comee/core/customer_orders_controller.rb +11 -2
  4. data/app/controllers/comee/core/product_lookups_controller.rb +1 -1
  5. data/app/controllers/comee/core/quotation_request_items_controller.rb +1 -0
  6. data/app/controllers/comee/core/sales_order_items_controller.rb +8 -2
  7. data/app/controllers/comee/core/sales_orders_controller.rb +5 -3
  8. data/app/models/comee/core/customer_order_item.rb +5 -3
  9. data/app/models/comee/core/sales_order.rb +5 -7
  10. data/app/models/comee/core/sales_order_item.rb +2 -1
  11. data/app/serializers/comee/core/customer_order_item_serializer.rb +2 -2
  12. data/app/serializers/comee/core/quotation_request_item_serializer.rb +2 -1
  13. data/app/serializers/comee/core/sales_order_item_serializer.rb +2 -2
  14. data/app/serializers/comee/core/sales_order_serializer.rb +5 -2
  15. data/app/services/comee/core/customer_order_service.rb +11 -1
  16. data/app/services/comee/core/quotation_request_service.rb +1 -0
  17. data/config/routes.rb +1 -0
  18. data/db/migrate/20230811102708_create_comee_core_customer_order_items.rb +1 -0
  19. data/db/migrate/20230812190652_create_comee_core_sales_orders.rb +12 -4
  20. data/db/migrate/20230812212844_create_comee_core_sales_order_items.rb +1 -0
  21. data/db/migrate/20231121132709_create_comee_core_quotation_request_items.rb +1 -0
  22. data/lib/comee/core/version.rb +1 -1
  23. data/spec/factories/comee/core/customer_order_items.rb +1 -0
  24. data/spec/factories/comee/core/quotation_request_items.rb +1 -0
  25. data/spec/factories/comee/core/sales_order_items.rb +2 -0
  26. data/spec/factories/comee/core/sales_orders.rb +12 -3
  27. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9ecb44f38bb1bbc8fe8accb8d1df84c10de099038728c077948c25584770250
4
- data.tar.gz: 46c2e7d55a8ad2dd8abbc414f595a1128566c48d6c9e053bcdd849f9a32d4242
3
+ metadata.gz: 5a4ecd52efb335b2688fb0fd381163d594b81de592ed48dcd5701ee28c00d10f
4
+ data.tar.gz: 53ef139383420c858b4ce5afcb52974af1051cdb2086a83bcd28256311724a76
5
5
  SHA512:
6
- metadata.gz: 86f577f8514711c9d0c32e81ce657016fc36b0d95b13f4e4e2953f9ff696688f6ffd5bd7cf9ed20df3b51349668f552df34bd7dc03fffb476ced35523e61b1c0
7
- data.tar.gz: 9a65691ef5ba903d3ef4f501ba7f698608db2e01b5510693a238f944745e295374ac4b47288f3a337116ac6f14b14c4d13174bfe62c3b7cfcd7cb6b20343a006
6
+ metadata.gz: aea590ef7c2567f4f8014bd7d18f4e77e81b735afb9fb64444d680b419d0548d20edbf62308d7f3bd5904fa4a225cabaf5b47649955934976183e6ffcb9a63e2
7
+ data.tar.gz: 1a44e91626c5e3c1b3d5d37574bea1ab19fbf10c2993a31436bede678660d96862f6029735b70988eebbb39107039fb843b0a1c58f29045b983a733eee4c4386
@@ -39,6 +39,7 @@ module Comee
39
39
  params.require(:payload)
40
40
  .permit(
41
41
  :customer_item_no,
42
+ :customer_item_description,
42
43
  :quantity,
43
44
  :price,
44
45
  :total_price,
@@ -8,7 +8,16 @@ module Comee
8
8
  def index
9
9
  super do
10
10
  [
11
- CustomerOrder.includes(:client, :customer_order_items).all,
11
+ CustomerOrder.includes(:client, customer_order_items: :unit).order(:created_at),
12
+ fields: ["client", "customer_order_items.unit"]
13
+ ]
14
+ end
15
+ end
16
+
17
+ def show
18
+ super do
19
+ [
20
+ CustomerOrder.includes(:client, customer_order_items: :unit).find(params[:id]),
12
21
  fields: ["client", "customer_order_items.unit"]
13
22
  ]
14
23
  end
@@ -68,7 +77,7 @@ module Comee
68
77
  .permit(
69
78
  :order_number, :order_date, :order_terms, :consignee, :shipment_address, :final_destination,
70
79
  :final_delivery_date, :handover_date, :shipping_date, :delivery_address, :invoice_address, :status, :client_id,
71
- items: %i[customer_item_no product_id quantity price total_price unit_id delivery_date]
80
+ items: %i[customer_item_no customer_item_description product_id quantity price total_price unit_id delivery_date]
72
81
  )
73
82
  end
74
83
 
@@ -20,7 +20,7 @@ module Comee
20
20
  end
21
21
 
22
22
  def filter
23
- data = ProductLookup.ransack(params[:q]).result
23
+ data = ProductLookup.includes(:product).ransack(params[:q]).result
24
24
  render_content(data)
25
25
  end
26
26
 
@@ -30,6 +30,7 @@ module Comee
30
30
  params.require(:payload)
31
31
  .permit(
32
32
  :customer_item_no,
33
+ :customer_item_description,
33
34
  :price,
34
35
  :quantity,
35
36
  :margin,
@@ -20,6 +20,12 @@ module Comee
20
20
  render json: {success: true, data: result}
21
21
  end
22
22
 
23
+ def cancel
24
+ item = set_object
25
+ item.update(canceled: true)
26
+ render_content(item)
27
+ end
28
+
23
29
  def destroy
24
30
  Comee::Core::SalesOrderItem.destroy(params[:id])
25
31
  render json: {success: true}
@@ -29,8 +35,8 @@ module Comee
29
35
 
30
36
  def model_params
31
37
  params.require(:payload).permit(:sales_order_id, :customer_order_item_id, :product_id, :unit_id, :quantity, :quantity_delivered,
32
- :customer_item_no, :price, :handover_date, :delivery_date, :eb_number, :lead_time, :comment,
33
- :action_note, :po_reference, :pallet_no, :source_id)
38
+ :customer_item_no, :customer_item_description, :price, :handover_date, :delivery_date,
39
+ :eb_number, :lead_time, :comment, :action_note, :po_reference, :pallet_no, :source_id)
34
40
  end
35
41
  end
36
42
  end
@@ -58,9 +58,11 @@ module Comee
58
58
  private
59
59
 
60
60
  def model_params
61
- params.require(:payload).permit(:order_number, :customer_order_id, :payment_penalty, :payment_term, :delivery_term, :status,
62
- :fulfillment_center_id, :total_price, :amount_paid, :pallete_note, :handover_date, :remark,
63
- :consignee, :client_id, files: [])
61
+ params.require(:payload).permit(:order_number, :order_date, :customer_order_id, :fulfillment_center_id, :client_id,
62
+ :order_terms, :shipment_address, :delivery_address, :invoice_address, :destination,
63
+ :handover_date, :shipping_date, :delivery_date, :consignee, :payment_term, :delivery_term,
64
+ :payment_penalty, :status, :total_price, :amount_paid, :pallete_note, :remark,
65
+ files: [])
64
66
  end
65
67
 
66
68
  def back_order_params
@@ -1,20 +1,22 @@
1
1
  module Comee
2
2
  module Core
3
3
  class CustomerOrderItem < ApplicationRecord
4
- before_save :calculate_total_price, unless: proc { |item| item.total_price }
4
+ before_save :calculate_total_price
5
5
 
6
6
  belongs_to :customer_order
7
7
  belongs_to :product
8
8
  belongs_to :unit
9
9
 
10
- validates :customer_item_no, :quantity, :price, :delivery_date, presence: true
10
+ validates :customer_item_no, :customer_item_description, :quantity, :price, :delivery_date, presence: true
11
+ validates :quantity, :price, numericality: {greater_than_or_equal_to: 0}
12
+ validates :total_price, numericality: {greater_than_or_equal_to: 0}, allow_nil: true
11
13
 
12
14
  def calculate_total_price
13
15
  self.total_price = price * quantity
14
16
  end
15
17
 
16
18
  def self.ransackable_attributes(_auth_object = nil)
17
- %w[id customer_order_id product_id unit_id]
19
+ %w[id customer_order_id product_id unit_id customer_item_no customer_item_description delivery_date]
18
20
  end
19
21
 
20
22
  def self.ransackable_associations(_auth_object = nil)
@@ -14,15 +14,13 @@ module Comee
14
14
  enum :status, {draft: 0, submitted: 1, confirmed: 2, canceled: 3}
15
15
 
16
16
  validates :order_number, presence: true, uniqueness: true
17
- validates :status, presence: true
18
- validates :payment_penalty,
19
- presence: true,
20
- numericality: {greater_than_or_equal_to: 0, less_than_or_equal_to: 100}
17
+ validates :order_date, :status, presence: true
18
+ validates :payment_penalty, numericality: {greater_than_or_equal_to: 0, less_than_or_equal_to: 100}, allow_nil: true
21
19
 
22
- validates :total_price,
23
- :amount_paid,
20
+ validates :amount_paid,
24
21
  presence: true,
25
- numericality: {greater_than_or_equal_to: 0}
22
+ numericality: {greater_than_or_equal_to: 0},
23
+ allow_nil: true
26
24
 
27
25
  def total_price
28
26
  sales_order_items = SalesOrderItem.where(sales_order_id: id)
@@ -10,7 +10,7 @@ module Comee
10
10
  belongs_to :source, class_name: "Comee::Core::FulfillmentCenter", optional: true
11
11
  has_many :shipment_items
12
12
 
13
- validates :customer_item_no, :delivery_date, presence: true
13
+ validates :customer_item_no, :customer_item_description, :delivery_date, presence: true
14
14
  validates :quantity, :price, presence: true, numericality: {greater_than: 0}
15
15
  validates :quantity_delivered, numericality: {greater_than_or_equal_to: 0}
16
16
 
@@ -22,6 +22,7 @@ module Comee
22
22
  %w[
23
23
  id
24
24
  customer_item_no
25
+ customer_item_description
25
26
  customer_order_item_id
26
27
  delivery_date
27
28
  eb_number
@@ -1,8 +1,8 @@
1
1
  module Comee
2
2
  module Core
3
3
  class CustomerOrderItemSerializer < ActiveModel::Serializer
4
- attributes :id, :customer_item_no, :quantity, :price, :total_price, :delivery_date, :canceled, :customer_order_id,
5
- :product_id, :unit_id
4
+ attributes :id, :customer_item_no, :customer_item_description, :quantity, :price, :total_price, :delivery_date,
5
+ :canceled, :customer_order_id, :product_id, :unit_id
6
6
  belongs_to :product
7
7
  belongs_to :unit
8
8
  belongs_to :customer_order
@@ -1,7 +1,8 @@
1
1
  module Comee
2
2
  module Core
3
3
  class QuotationRequestItemSerializer < ActiveModel::Serializer
4
- attributes :id, :customer_item_no, :price, :margin, :margin_type, :valid_from, :valid_to, :quantity, :expected_delivery_date
4
+ attributes :id, :customer_item_no, :customer_item_description, :price, :margin, :margin_type, :valid_from, :valid_to,
5
+ :quantity, :expected_delivery_date
5
6
  belongs_to :product
6
7
  belongs_to :quotation_request
7
8
  belongs_to :unit
@@ -1,8 +1,8 @@
1
1
  module Comee
2
2
  module Core
3
3
  class SalesOrderItemSerializer < ActiveModel::Serializer
4
- attributes :id, :customer_item_no, :quantity, :quantity_delivered, :price, :handover_date, :delivery_date, :eb_number,
5
- :lead_time, :comment, :action_note, :po_reference, :total_price
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, :po_reference, :total_price, :canceled
6
6
 
7
7
  belongs_to :sales_order
8
8
  belongs_to :customer_order_item
@@ -1,12 +1,15 @@
1
1
  module Comee
2
2
  module Core
3
3
  class SalesOrderSerializer < ActiveModel::Serializer
4
- attributes :id, :order_number, :payment_penalty, :status, :total_price, :payment_term, :delivery_term, :amount_paid,
5
- :pallete_note, :handover_date, :remark, :parent_client_name, :created_by, :files_url, :customs_detail, :consignee
4
+ attributes :id, :order_number, :order_date, :order_terms, :shipment_address, :delivery_address, :invoice_address,
5
+ :destination, :handover_date, :shipping_date, :delivery_date, :consignee, :parent_client_name, :payment_term,
6
+ :delivery_term, :payment_penalty, :status, :total_price, :amount_paid, :pallete_note, :remark, :created_by,
7
+ :files_url
6
8
  belongs_to :customer_order
7
9
  belongs_to :client
8
10
  belongs_to :fulfillment_center
9
11
  has_many :sales_order_items
12
+ has_one :customs_detail
10
13
  end
11
14
  end
12
15
  end
@@ -138,9 +138,18 @@ module Comee
138
138
  CustomerOrder.transaction do
139
139
  sales_order = SalesOrder.create!(
140
140
  order_number: order.order_number,
141
+ order_date: order.order_date,
141
142
  customer_order: order,
142
143
  status: SalesOrder.statuses[:draft],
143
144
  client: order.client,
145
+ order_terms: order.order_terms,
146
+ shipment_address: order.shipment_address,
147
+ invoice_address: order.invoice_address,
148
+ delivery_address: order.delivery_address,
149
+ destination: order.final_destination,
150
+ handover_date: order.handover_date,
151
+ shipping_date: order.shipping_date,
152
+ delivery_date: order.final_delivery_date,
144
153
  consignee: order.consignee,
145
154
  created_by: accepted_by || ""
146
155
  )
@@ -173,7 +182,8 @@ module Comee
173
182
  customer_order_item_id: item.id,
174
183
  product_id: item.product_id,
175
184
  unit_id: unit_id,
176
- customer_item_no: item.product.code,
185
+ customer_item_no: item.customer_item_no,
186
+ customer_item_description: item.customer_item_description,
177
187
  quantity: quantity,
178
188
  price: price,
179
189
  total_price: quantity * price,
@@ -118,6 +118,7 @@ module Comee
118
118
  product_id: item.product_id,
119
119
  unit_id: item.unit_id,
120
120
  customer_item_no: item.customer_item_no,
121
+ customer_item_description: item.customer_item_description,
121
122
  quantity: item.quantity,
122
123
  price: item.price,
123
124
  delivery_date: item.expected_delivery_date,
data/config/routes.rb CHANGED
@@ -113,6 +113,7 @@ Comee::Core::Engine.routes.draw do
113
113
  resources :sales_order_items, except: [:index] do
114
114
  member do
115
115
  get "suggest", controller: :sales_order_items, action: :suggest_values
116
+ post "cancel"
116
117
  end
117
118
  end
118
119
  resources :shipment_items do
@@ -14,6 +14,7 @@ class CreateComeeCoreCustomerOrderItems < ActiveRecord::Migration[7.1]
14
14
  index: {name: "unit_on_cccuoi_indx"},
15
15
  foreign_key: {to_table: :comee_core_units}
16
16
  t.string :customer_item_no, null: false
17
+ t.string :customer_item_description, null: false
17
18
  t.float :quantity, null: false, default: 0
18
19
  t.float :price, null: false, default: 0
19
20
  t.float :total_price, null: false, default: 0
@@ -2,6 +2,7 @@ class CreateComeeCoreSalesOrders < ActiveRecord::Migration[7.0]
2
2
  def change
3
3
  create_table :comee_core_sales_orders do |t|
4
4
  t.string :order_number, null: false
5
+ t.date :order_date, null: false
5
6
  t.references :customer_order,
6
7
  null: false,
7
8
  index: {name: "co_on_ccso_indx"},
@@ -14,16 +15,23 @@ class CreateComeeCoreSalesOrders < ActiveRecord::Migration[7.0]
14
15
  null: false,
15
16
  index: {name: "client_on_ccso_indx"},
16
17
  foreign_key: {to_table: :comee_core_clients}
18
+ t.string :order_terms
19
+ t.string :shipment_address
20
+ t.string :delivery_address
21
+ t.string :invoice_address
22
+ t.string :destination
23
+ t.date :shipping_date
24
+ t.date :delivery_date
25
+ t.date :handover_date
17
26
  t.string :consignee
18
27
  t.string :parent_client_name
19
28
  t.string :payment_term
20
29
  t.string :delivery_term
21
- t.float :payment_penalty, null: false, default: 0.0
30
+ t.float :payment_penalty, default: 0
22
31
  t.integer :status, null: false, default: 0
23
- t.float :total_price, null: false, default: 0
24
- t.float :amount_paid, null: false, default: 0
32
+ t.float :total_price, default: 0.0
33
+ t.float :amount_paid, default: 0.0
25
34
  t.string :pallete_note
26
- t.date :handover_date
27
35
  t.string :remark
28
36
  t.string :created_by
29
37
 
@@ -22,6 +22,7 @@ class CreateComeeCoreSalesOrderItems < ActiveRecord::Migration[7.0]
22
22
  index: {name: "source_on_ccsoi_indx"},
23
23
  foreign_key: {to_table: :comee_core_fulfillment_centers}
24
24
  t.string :customer_item_no, null: false
25
+ t.string :customer_item_description, null: false
25
26
  t.float :quantity, null: false
26
27
  t.float :quantity_delivered, null: false, default: 0
27
28
  t.float :price, null: false
@@ -10,6 +10,7 @@ class CreateComeeCoreQuotationRequestItems < ActiveRecord::Migration[7.1]
10
10
  index: {name: "rfq_on_ccrfqi_indx"},
11
11
  foreign_key: {to_table: :comee_core_quotation_requests}
12
12
  t.string :customer_item_no
13
+ t.string :customer_item_description
13
14
  t.float :quantity, null: false
14
15
  t.float :price, null: false, default: 0
15
16
  t.float :margin, null: false, default: 0
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.2.11".freeze
3
+ VERSION = "0.2.13".freeze
4
4
  end
5
5
  end
@@ -4,6 +4,7 @@ FactoryBot.define do
4
4
  product
5
5
  unit
6
6
  customer_item_no { Faker::Alphanumeric.alpha(number: 10) }
7
+ customer_item_description { Faker::Lorem.sentence }
7
8
  quantity { 1 }
8
9
  price { 1.5 }
9
10
  total_price { quantity * price }
@@ -4,6 +4,7 @@ FactoryBot.define do
4
4
  quotation_request
5
5
  unit
6
6
  customer_item_no { Faker::Alphanumeric.alpha(number: 10) }
7
+ customer_item_description { Faker::Lorem.sentence }
7
8
  quantity { 10 }
8
9
  price { 0 }
9
10
  margin { 0 }
@@ -6,6 +6,7 @@ FactoryBot.define do
6
6
  product
7
7
  unit
8
8
  customer_item_no { Faker::Alphanumeric.alpha(number: 10) }
9
+ customer_item_description { Faker::Lorem.sentence }
9
10
  quantity { 100 }
10
11
  quantity_delivered { 0 }
11
12
  price { 50 }
@@ -17,5 +18,6 @@ FactoryBot.define do
17
18
  comment { Faker::Lorem.sentence }
18
19
  action_note { Faker::Lorem.sentence }
19
20
  po_reference { Faker::Alphanumeric.alpha(number: 10) }
21
+ canceled { false }
20
22
  end
21
23
  end
@@ -1,19 +1,28 @@
1
1
  FactoryBot.define do
2
2
  factory :sales_order, class: "Comee::Core::SalesOrder" do
3
3
  order_number { Faker::Alphanumeric.alpha(number: 10) }
4
+ order_date { Date.current }
4
5
  customer_order
5
6
  fulfillment_center
6
7
  client
8
+ order_terms { Faker::Lorem.sentence }
9
+ shipment_address { Faker::Address.full_address }
10
+ delivery_address { Faker::Address.full_address }
11
+ invoice_address { Faker::Address.full_address }
12
+ destination { Faker::Address.city }
13
+ handover_date { Date.current.advance(weeks: 1) }
14
+ shipping_date { Date.current.advance(days: 10) }
15
+ delivery_date { Date.current.advance(days: 15) }
16
+ consignee { Faker::Name.name }
17
+ parent_client_name { Faker::Name.name }
7
18
  payment_term { Faker::Lorem.sentence }
8
19
  delivery_term { Faker::Lorem.sentence }
9
20
  payment_penalty { 0 }
21
+ status { Comee::Core::SalesOrder.statuses[:draft] }
10
22
  total_price { 0 }
11
23
  amount_paid { 0 }
12
- status { Comee::Core::SalesOrder.statuses[:draft] }
13
24
  pallete_note { Faker::Lorem.sentence }
14
- consignee { Faker::Name.name }
15
25
  remark { Faker::Lorem.sentence }
16
- parent_client_name { Faker::Name.name }
17
26
  created_by { Faker::Name.name }
18
27
  end
19
28
  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.11
4
+ version: 0.2.13
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-02-05 00:00:00.000000000 Z
11
+ date: 2024-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers