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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8507c4dd25c1bcfa029f438953fe12ec069c715c4bec5783f0653e4a87b77332
4
- data.tar.gz: 474a2d3f78b9f0961130e2ace5dc66074b39d430c4c610b6b5a4ef0e2574c86b
3
+ metadata.gz: 738e68a65b4d7a96b3f0ea50a6e25da73e42d09f0ef888c49060a45ebc2fb39e
4
+ data.tar.gz: e42799a2bd3b0cfde406636e972ec258462df1df24dae8f4a051002eecc69294
5
5
  SHA512:
6
- metadata.gz: e65a2a474b37e891703e2f55b6c763b3ba8510c243d6cf8266fa987b7949b487c8086a29c8b5d49fda223d406ed5b6ae552a30c82e8e07a38e80bcaa4e02884c
7
- data.tar.gz: 6573cf6978274afeafb4467e74e9fe34340244bd08dca739115fd07fabca16974b083f100029ebb77534cabb686775bb586725aaee37e6ca9085b23bdd4001f3
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).permit(:quantity, :price, :delivery_date, :canceled, :product_id, :customer_order_id, :unit_id)
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
@@ -29,6 +29,7 @@ module Comee
29
29
  def model_params
30
30
  params.require(:payload)
31
31
  .permit(
32
+ :customer_item_no,
32
33
  :price,
33
34
  :quantity,
34
35
  :discount,
@@ -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).permit(:reference_no, :status, :client_id)
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, :order_terms, :delivery_address, :invoice_address, :status, presence: true
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
@@ -0,0 +1,9 @@
1
+ module Comee
2
+ module Core
3
+ class MasterPriceSerializer < ActiveModel::Serializer
4
+ attributes :id, :purchase_price, :selling_price, :valid_from, :valid_to, :primary, :margin
5
+ belongs_to :product
6
+ belongs_to :supplier
7
+ end
8
+ end
9
+ end
@@ -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
@@ -1,7 +1,7 @@
1
1
  module Comee
2
2
  module Core
3
3
  class QuotationRequestSerializer < ActiveModel::Serializer
4
- attributes :id, :reference_no, :status
4
+ attributes :id, :reference_no, :order_number, :status
5
5
  belongs_to :client
6
6
  end
7
7
  end
@@ -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]).select(:code)
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
- raise(StandardError, "Customer order does not have any items.") if order.customer_order_items.count.zero?
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!(client_id: params[:client_id], status: QuotationRequest.statuses[:draft])
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
- rfq.status = QuotationRequest.statuses[:confirmed]
64
- rfq.save!
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, null: false
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
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.1.51".freeze
3
+ VERSION = "0.1.53".freeze
4
4
  end
5
5
  end
@@ -3,6 +3,7 @@ FactoryBot.define do
3
3
  customer_order
4
4
  product
5
5
  unit
6
+ customer_item_no { Faker::Alphanumeric.alpha(number: 10) }
6
7
  quantity { 1 }
7
8
  price { 1.5 }
8
9
  delivery_date { Date.current }
@@ -3,6 +3,7 @@ FactoryBot.define do
3
3
  product
4
4
  quotation_request
5
5
  unit
6
+ customer_item_no { Faker::Alphanumeric.alpha(number: 10) }
6
7
  quantity { 10 }
7
8
  price { 0 }
8
9
  discount { 0 }
@@ -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.51
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-14 00:00:00.000000000 Z
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