comee_core 0.1.65 → 0.1.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/comee/core/client_prices_controller.rb +1 -1
  3. data/app/controllers/comee/core/product_lookups_controller.rb +24 -0
  4. data/app/controllers/comee/core/quotation_request_items_controller.rb +2 -1
  5. data/app/models/comee/core/client.rb +0 -1
  6. data/app/models/comee/core/client_price.rb +3 -2
  7. data/app/models/comee/core/product_lookup.rb +5 -1
  8. data/app/models/comee/core/quotation_request_item.rb +5 -2
  9. data/app/serializers/comee/core/client_price_serializer.rb +1 -1
  10. data/app/serializers/comee/core/product_lookup_serializer.rb +8 -0
  11. data/app/serializers/comee/core/quotation_request_item_serializer.rb +1 -1
  12. data/app/services/comee/core/product_lookup_service.rb +2 -3
  13. data/app/services/comee/core/quotation_request_service.rb +4 -2
  14. data/config/routes.rb +6 -0
  15. data/db/migrate/20230728123039_create_comee_core_clients.rb +0 -1
  16. data/db/migrate/20230813235946_create_comee_core_master_prices.rb +1 -1
  17. data/db/migrate/20230814151601_create_comee_core_client_prices.rb +2 -1
  18. data/db/migrate/{20230914041307_create_comee_core_external_products.rb → 20230914041307_create_comee_core_product_lookups.rb} +2 -1
  19. data/db/migrate/20231121132709_create_comee_core_quotation_request_items.rb +2 -1
  20. data/lib/comee/core/version.rb +1 -1
  21. data/spec/factories/comee/core/client_prices.rb +2 -1
  22. data/spec/factories/comee/core/clients.rb +0 -1
  23. data/spec/factories/comee/core/product_lookups.rb +1 -0
  24. data/spec/factories/comee/core/quotation_request_items.rb +2 -1
  25. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 52af84253c893c7cd0227d8f90bf1cfc08122dddd244dc08b43a35cb37d1e023
4
- data.tar.gz: '088941a03a3d82ce6139ee9dbbe37184efc8b5f14dfc28bbedc8c7cc01713359'
3
+ metadata.gz: 47cf5679d2c9d6fbc6d6f0c4f7eb3a6a25c402ec3e4aabf667de41c01b3e2f82
4
+ data.tar.gz: 3fc087959c16abb7bc68c36a0e8f126c21922545a6118d19203f8cb3d95e6e2d
5
5
  SHA512:
6
- metadata.gz: 594acab1ee9e374d297fd00251ec3abffa8a3b3f7fe10aef418fd6209d310a4f55376d1dfac93a3948375afcbf196ff4d0bb4e748b6d83e5acb3087208d5c00f
7
- data.tar.gz: 39b42c4dea22968643c0a782850fe981599936983494b3621beeeb055d31a7f4f104f040bb5b81d6b658dc9242e21e2b11c326ae6362003914060e7de4cbddc3
6
+ metadata.gz: f42d06b36fa70926e8cd3e0003522aecdad89a5c6a291fe39158beb29b9a769b03d35aa096e40db2bfdb7ff0d79e25538ee8b835e528bcf1b703f33af93fbff5
7
+ data.tar.gz: 33719ed3f0a29dd2f68e3c3192158c03a9f361ee62bc640264d385e7233642c4b376347656d71aa838b9aca1535fc1bf18d1f66280878f5efc0195b24e8c28ae
@@ -19,7 +19,7 @@ module Comee
19
19
  private
20
20
 
21
21
  def model_params
22
- params.require(:payload).permit(:valid_from, :valid_to, :price, :product_id, :discount, :client_id, :previous_price,
22
+ params.require(:payload).permit(:valid_from, :valid_to, :price, :product_id, :margin, :margin_type, :client_id, :previous_price,
23
23
  :unit_id)
24
24
  end
25
25
  end
@@ -0,0 +1,24 @@
1
+ module Comee
2
+ module Core
3
+ class ProductLookupsController < ApplicationController
4
+ include Common
5
+
6
+ def index
7
+ super do
8
+ ProductLookup.includes(:product).all
9
+ end
10
+ end
11
+
12
+ def filter
13
+ lookups = ProductLookup.ransack(params[:q]).result
14
+ render json: {success: true, data: serialize(lookups)}
15
+ end
16
+
17
+ private
18
+
19
+ def model_params
20
+ params.required(:payload).permit(:code, :itemable_id, :itemable_type, :item_description, :product_id)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -32,7 +32,8 @@ module Comee
32
32
  :customer_item_no,
33
33
  :price,
34
34
  :quantity,
35
- :discount,
35
+ :margin,
36
+ :margin_type,
36
37
  :valid_from,
37
38
  :valid_to,
38
39
  :product_id,
@@ -15,7 +15,6 @@ module Comee
15
15
  address
16
16
  code
17
17
  name
18
- discount
19
18
  locale
20
19
  ]
21
20
  end
@@ -1,13 +1,14 @@
1
1
  module Comee
2
2
  module Core
3
3
  class ClientPrice < Price
4
+ enum :margin_type, {increase: 0, discount: 1}
4
5
  belongs_to :client
5
6
  belongs_to :previous_price, class_name: "Comee::Core::ClientPrice", optional: true
6
7
  belongs_to :next_price, class_name: "Comee::Core::ClientPrice", optional: true
7
8
 
8
- validates :price, presence: true
9
+ validates :price, :margin_type, presence: true
9
10
  validates :price, numericality: {greater_than: 0}
10
- validates :discount, presence: true, numericality: {greater_than_or_equal_to: 0, less_than_or_equal_to: 100}
11
+ validates :margin, presence: true, numericality: {greater_than_or_equal_to: 0, less_than_or_equal_to: 100}
11
12
  validates :product_id, uniqueness: {scope: %i[client_id previous_price_id next_price_id status]}
12
13
 
13
14
  def self.ransackable_attributes(_auth_object = nil)
@@ -4,7 +4,11 @@ module Comee
4
4
  belongs_to :product
5
5
  belongs_to :itemable, polymorphic: true
6
6
 
7
- validates :code, presence: true
7
+ validates :code, :item_description, presence: true
8
+
9
+ def self.ransackable_attributes(_auth_object = nil)
10
+ %w[code item_description itemable_id itemable_type product_id]
11
+ end
8
12
  end
9
13
  end
10
14
  end
@@ -1,14 +1,17 @@
1
1
  module Comee
2
2
  module Core
3
3
  class QuotationRequestItem < ApplicationRecord
4
+ enum :margin_type, {increase: 0, discount: 1}
4
5
  belongs_to :product
5
6
  belongs_to :quotation_request
6
7
  belongs_to :unit
7
8
 
8
- validates :quantity, :price, :discount, :expected_delivery_date, presence: true
9
+ validates :margin_type, :expected_delivery_date, presence: true
10
+ validates :quantity, :price, presence: true, numericality: {greater_than_or_equal_to: 0}
11
+ validates :margin, presence: true, numericality: {greater_than_or_equal_to: 0, less_than_or_equal_to: 100}
9
12
 
10
13
  def self.ransackable_attributes(_auth_object = nil)
11
- %w[quotation_request_id product_id unit_id quantity price discount expected_delivery_date]
14
+ %w[quotation_request_id product_id unit_id quantity price margin margin_type expected_delivery_date]
12
15
  end
13
16
  end
14
17
  end
@@ -1,7 +1,7 @@
1
1
  module Comee
2
2
  module Core
3
3
  class ClientPriceSerializer < ActiveModel::Serializer
4
- attributes :id, :valid_from, :valid_to, :price, :status, :previous_price
4
+ attributes :id, :valid_from, :valid_to, :price, :status, :previous_price, :margin, :margin_type
5
5
  belongs_to :product
6
6
  belongs_to :client
7
7
  belongs_to :unit
@@ -0,0 +1,8 @@
1
+ module Comee
2
+ module Core
3
+ class ProductLookupSerializer < ActiveModel::Serializer
4
+ attributes :id, :code, :itemable_id, :itemable_type, :item_description
5
+ belongs_to :product
6
+ end
7
+ end
8
+ end
@@ -1,7 +1,7 @@
1
1
  module Comee
2
2
  module Core
3
3
  class QuotationRequestItemSerializer < ActiveModel::Serializer
4
- attributes :id, :customer_item_no, :price, :discount, :valid_from, :valid_to, :quantity, :expected_delivery_date
4
+ attributes :id, :customer_item_no, :price, :margin, :margin_type, :valid_from, :valid_to, :quantity, :expected_delivery_date
5
5
  belongs_to :product
6
6
  belongs_to :quotation_request
7
7
  belongs_to :unit
@@ -21,7 +21,7 @@ module Comee
21
21
 
22
22
  if from == ORGANIZATION
23
23
  query = ProductLookup.joins(:product).find_by(product: {code: code}, **to)
24
- return query.code
24
+ return query
25
25
  end
26
26
 
27
27
  if to == ORGANIZATION
@@ -30,8 +30,7 @@ module Comee
30
30
  end
31
31
 
32
32
  product = ProductLookup.find_by(code: code, **from).product
33
- query = ProductLookup.find_by(product: product, **to)
34
- query.code
33
+ ProductLookup.find_by(product: product, **to)
35
34
  end
36
35
  end
37
36
  end
@@ -16,7 +16,8 @@ module Comee
16
16
  items.each do |item|
17
17
  item[:price] = 0
18
18
  item[:quotation_request_id] = request.id
19
- item[:discount] = 0
19
+ item[:margin] = 0
20
+ item[:margin_type] = QuotationRequestItem.margin_types[:increase]
20
21
  end
21
22
  QuotationRequestItem.insert_all!(items)
22
23
  end
@@ -73,7 +74,8 @@ module Comee
73
74
  product_id: item.product_id,
74
75
  unit_id: item.unit_id,
75
76
  price: item.price,
76
- discount: 0,
77
+ margin: 0,
78
+ margin_type: QuotationRequestItem.margin_types[:increase],
77
79
  valid_from: item.valid_from,
78
80
  valid_to: item.valid_to,
79
81
  status: ClientPrice.statuses[:current]
data/config/routes.rb CHANGED
@@ -15,6 +15,12 @@ Comee::Core::Engine.routes.draw do
15
15
  post "client_prices"
16
16
  end
17
17
  end
18
+ resources :product_lookups do
19
+ collection do
20
+ post "filter"
21
+ end
22
+ end
23
+
18
24
  resources :lookups
19
25
  resources :quotation_requests do
20
26
  collection do
@@ -9,7 +9,6 @@ class CreateComeeCoreClients < ActiveRecord::Migration[7.0]
9
9
  t.string :name, null: false
10
10
  t.string :address, null: false
11
11
  t.string :locale, null: false, default: "en"
12
- t.string :discount, null: false, default: 0
13
12
 
14
13
  t.timestamps
15
14
  end
@@ -7,7 +7,7 @@ class CreateComeeCoreMasterPrices < ActiveRecord::Migration[7.0]
7
7
  t.date :valid_to, null: false
8
8
  t.float :status, null: false, default: 0
9
9
  t.boolean :primary, null: false, default: false
10
- t.integer :margin, null: false
10
+ t.float :margin, null: false, default: 0
11
11
  t.integer :lead_time
12
12
  t.references :product,
13
13
  null: false,
@@ -5,7 +5,8 @@ class CreateComeeCoreClientPrices < ActiveRecord::Migration[7.0]
5
5
  t.date :valid_to, null: false
6
6
  t.float :price, null: false
7
7
  t.float :status, null: false, default: 0
8
- t.integer :discount, null: false
8
+ t.float :margin, null: false, default: 0
9
+ t.integer :margin_type, null: false, default: 0
9
10
  t.references :product,
10
11
  null: false,
11
12
  index: {name: "product_on_cccp_indx"},
@@ -1,8 +1,9 @@
1
- class CreateComeeCoreExternalProducts < ActiveRecord::Migration[7.0]
1
+ class CreateComeeCoreProductLookups < ActiveRecord::Migration[7.0]
2
2
  def change
3
3
  create_table :comee_core_product_lookups do |t|
4
4
  t.string :code, null: false
5
5
  t.references :itemable, polymorphic: true, null: false
6
+ t.string :item_description, null: false
6
7
  t.references :product,
7
8
  null: false,
8
9
  index: {name: "product_on_ccep_indx"},
@@ -12,7 +12,8 @@ class CreateComeeCoreQuotationRequestItems < ActiveRecord::Migration[7.1]
12
12
  t.string :customer_item_no
13
13
  t.float :quantity, null: false
14
14
  t.float :price, null: false, default: 0
15
- t.float :discount, null: false, default: 0
15
+ t.float :margin, null: false, default: 0
16
+ t.integer :margin_type, null: false, default: 0
16
17
  t.date :expected_delivery_date, null: false
17
18
  t.boolean :canceled, null: false, default: false
18
19
  t.references :unit,
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.1.65".freeze
3
+ VERSION = "0.1.66".freeze
4
4
  end
5
5
  end
@@ -7,7 +7,8 @@ FactoryBot.define do
7
7
  product
8
8
  client
9
9
  unit
10
- discount { 0 }
10
+ margin { 0.0 }
11
+ margin_type { Comee::Core::ClientPrice.margin_types[:increase] }
11
12
  previous_price { nil }
12
13
  next_price { nil }
13
14
 
@@ -5,6 +5,5 @@ FactoryBot.define do
5
5
  name { Faker::Name.name }
6
6
  address { Faker::Address.full_address }
7
7
  locale { "en" }
8
- discount { 0 }
9
8
  end
10
9
  end
@@ -3,5 +3,6 @@ FactoryBot.define do
3
3
  code { Faker::Alphanumeric.alpha(number: 8) }
4
4
  product
5
5
  itemable factory: :supplier
6
+ item_description { Faker::Lorem.sentence }
6
7
  end
7
8
  end
@@ -6,7 +6,8 @@ FactoryBot.define do
6
6
  customer_item_no { Faker::Alphanumeric.alpha(number: 10) }
7
7
  quantity { 10 }
8
8
  price { 0 }
9
- discount { 0 }
9
+ margin { 0 }
10
+ margin_type { Comee::Core::QuotationRequestItem.margin_types[:increase] }
10
11
  expected_delivery_date { Date.current.advance(days: 15) }
11
12
  canceled { false }
12
13
  valid_from { nil }
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.65
4
+ version: 0.1.66
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-22 00:00:00.000000000 Z
11
+ date: 2023-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -291,6 +291,7 @@ files:
291
291
  - app/controllers/comee/core/item_statuses_controller.rb
292
292
  - app/controllers/comee/core/lookups_controller.rb
293
293
  - app/controllers/comee/core/notifications_controller.rb
294
+ - app/controllers/comee/core/product_lookups_controller.rb
294
295
  - app/controllers/comee/core/products_controller.rb
295
296
  - app/controllers/comee/core/purchase_order_items_controller.rb
296
297
  - app/controllers/comee/core/purchase_orders_controller.rb
@@ -354,6 +355,7 @@ files:
354
355
  - app/serializers/comee/core/item_status_serializer.rb
355
356
  - app/serializers/comee/core/lookup_serializer.rb
356
357
  - app/serializers/comee/core/master_price_serializer.rb
358
+ - app/serializers/comee/core/product_lookup_serializer.rb
357
359
  - app/serializers/comee/core/product_serializer.rb
358
360
  - app/serializers/comee/core/product_type_serializer.rb
359
361
  - app/serializers/comee/core/purchase_order_item_serializer.rb
@@ -396,7 +398,7 @@ files:
396
398
  - db/migrate/20230812212844_create_comee_core_sales_order_items.rb
397
399
  - db/migrate/20230813235946_create_comee_core_master_prices.rb
398
400
  - db/migrate/20230814151601_create_comee_core_client_prices.rb
399
- - db/migrate/20230914041307_create_comee_core_external_products.rb
401
+ - db/migrate/20230914041307_create_comee_core_product_lookups.rb
400
402
  - db/migrate/20230915205522_create_comee_core_invoices.rb
401
403
  - db/migrate/20230915205648_create_comee_core_invoice_items.rb
402
404
  - db/migrate/20230929115336_create_comee_core_order_sources.rb