comee_core 0.1.80 → 0.1.82

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: 8e66de25a6395ee13f7dd5bdf45a79d8fdda48df5037197f499c5000b2cd965e
4
- data.tar.gz: f19d317e6465ebadc10aa01674f7e39651e9fa11a8875c62adadd418a8cad0f8
3
+ metadata.gz: aec2eead92d024daab37e1477e49f59cf15b03710c8f2846cca144a2991bb2a1
4
+ data.tar.gz: 11b7949daff48bb2b49466abbede7b76c39b1e862bb332a1b5f5999308b1fcc4
5
5
  SHA512:
6
- metadata.gz: f0c3b34e1015e9bd2b71d28d575514de6c346d5dc00e073160f28a6cfa15a78172b9b7215154c3f435d395ceeeb1e9062a2ba90a455073f5b752a62b037652b4
7
- data.tar.gz: c57d6182fe854968524ef8184c5f92163e0c15e8c7fcf2f81fe46ef2e1b1de1d71587a9edfa609bbfe22ac56b1201a22cf162137829a24b3e462a679c3cf330b
6
+ metadata.gz: 438cb2d9d91f97c3d7ab2aa099e949045dadcf67528b9eb146b356adaa9bb849776256fc5c258ef99b461252ba6765e80e2d864c31f35f631a5db70e7417c176
7
+ data.tar.gz: 986ce5f97c44033fc95ff38ace756d151dcaeef290be9b6d4fa0349898c6f4c851a918d74242bd71462eb04fde947def19ded389c56c570ae432aae59eb29431
@@ -10,57 +10,24 @@ module Comee
10
10
  end
11
11
  end
12
12
 
13
+ def fetch_for_client
14
+ client = Comee::Core::Client.find(params[:id])
15
+ client_id = client.parent_id || client.id
16
+ prices = Comee::Core::ClientPrice.includes(:client, :product, :unit, :product_lookup)
17
+ .where(client_id: client_id)
18
+ total = prices.count
19
+ prices = prices.then(&paginate)
20
+
21
+ render json: {success: true, data: serialize(prices), page: params[:page], total: total}
22
+ end
23
+
13
24
  def filter
14
- @client_prices = Comee::Core::ClientPrice.includes(:client, :product, :unit).ransack(params[:q]).result
15
- total = @client_prices.count
16
- @client_prices = @client_prices.then(&paginate)
17
- queries = @client_prices.map { |cp| {itemable_id: cp.client_id, product_id: cp.product_id, itemable_type: "Comee::Core::Client"} }
25
+ prices = Comee::Core::ClientPrice.includes(:client, :product, :unit, :product_lookup)
26
+ .ransack(params[:q]).result
27
+ total = prices.count
28
+ prices = prices.then(&paginate)
18
29
 
19
- lookups = queries.inject(Comee::Core::ProductLookup.none) do |conditions, condition|
20
- conditions.or(Comee::Core::ProductLookup.where(condition))
21
- end
22
- result = @client_prices.each_with_object([]) do |obj, res|
23
- item = {
24
- id: obj.id,
25
- valid_from: obj.valid_from,
26
- valid_to: obj.valid_to,
27
- price: obj.price,
28
- status: obj.status,
29
- margin: obj.margin,
30
- margin_type: obj.margin_type,
31
- client_id: obj.client.id,
32
- client_code: obj.client.code,
33
- client_name: obj.client.name,
34
- client_address: obj.client.address,
35
- product_id: obj.product.id,
36
- product_code: obj.product.code,
37
- product_name: obj.product.name,
38
- product_description: obj.product.description,
39
- product_preferred_units: obj.product.preferred_units,
40
- product_weight: obj.product.weight,
41
- product_weight_unit: obj.product.weight_unit,
42
- product_dimensions: obj.product.dimensions,
43
- product_hs_code: obj.product.hs_code,
44
- product_hs_description: obj.product.hs_description,
45
- product_image: obj.product.thumbnail_image_url,
46
- unit_id: obj.unit.id,
47
- unit_code: obj.unit.code,
48
- unit_name: obj.unit.name
49
- }
50
- lkp = lookups.select { |lookup| lookup.itemable_id == obj.client_id && lookup.product_id == obj.product_id }
51
- if lkp.count.positive?
52
- item[:client_product_code] = lkp[0].code
53
- item[:client_product_name] = lkp[0].item_description
54
- end
55
- res << item
56
- end
57
- result = {success: true, data: result}
58
- page = params[:page]
59
- if page
60
- result[:page] = page
61
- result[:total] = total
62
- end
63
- render json: result
30
+ render json: {success: true, data: serialize(prices), page: params[:page], total: total}
64
31
  end
65
32
 
66
33
  private
@@ -37,7 +37,7 @@ module Comee
37
37
  end
38
38
 
39
39
  def self.ransackable_associations(_auth_object = nil)
40
- %w[product client]
40
+ %w[product client product_lookup]
41
41
  end
42
42
  end
43
43
  end
@@ -56,7 +56,7 @@ module Comee
56
56
  end
57
57
 
58
58
  def self.ransackable_associations(_auth_object = nil)
59
- %w[product supplier]
59
+ %w[product supplier product_lookup]
60
60
  end
61
61
  end
62
62
  end
@@ -5,6 +5,7 @@ module Comee
5
5
  belongs_to :product
6
6
  belongs_to :client
7
7
  belongs_to :unit
8
+ belongs_to :product_lookup
8
9
  end
9
10
  end
10
11
  end
@@ -4,6 +4,7 @@ module Comee
4
4
  attributes :id, :purchase_price, :selling_price, :valid_from, :valid_to, :primary, :margin, :lead_time, :status
5
5
  belongs_to :product
6
6
  belongs_to :supplier
7
+ belongs_to :product_lookup
7
8
  end
8
9
  end
9
10
  end
data/config/routes.rb CHANGED
@@ -68,6 +68,7 @@ Comee::Core::Engine.routes.draw do
68
68
  resources :clients do
69
69
  member do
70
70
  get "rfq_products", controller: :quotation_requests, action: :rfq_products_for_client
71
+ get "prices", controller: :client_prices, action: :fetch_for_client
71
72
  end
72
73
  collection do
73
74
  post "filter"
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.1.80".freeze
3
+ VERSION = "0.1.82".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comee_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.80
4
+ version: 0.1.82
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.