comee_core 0.1.80 → 0.1.81

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e66de25a6395ee13f7dd5bdf45a79d8fdda48df5037197f499c5000b2cd965e
4
- data.tar.gz: f19d317e6465ebadc10aa01674f7e39651e9fa11a8875c62adadd418a8cad0f8
3
+ metadata.gz: a4318ef428c28e4dbcf4fe933ec2b485b451988f05b512743d27eee5279cd86f
4
+ data.tar.gz: d2ac11b22312a1ec6255c96f2bdcffed7339d4e5d53a8b547e5c478de715c509
5
5
  SHA512:
6
- metadata.gz: f0c3b34e1015e9bd2b71d28d575514de6c346d5dc00e073160f28a6cfa15a78172b9b7215154c3f435d395ceeeb1e9062a2ba90a455073f5b752a62b037652b4
7
- data.tar.gz: c57d6182fe854968524ef8184c5f92163e0c15e8c7fcf2f81fe46ef2e1b1de1d71587a9edfa609bbfe22ac56b1201a22cf162137829a24b3e462a679c3cf330b
6
+ metadata.gz: c466754e9b38187b8e07699ba940397ca8186350b074abaf193a133da26a53692935cbd8ffff307ba0ef8923f7ffa79cac8508d16662d81b270792269fea2acf
7
+ data.tar.gz: 0e053593a318be96788240fa1ecbe6116759a3096414bdee15df9795e7e110c74f992b6df4cec3eb0493608b55910111ecdb369e8c7efa9bf18b2c1796e17023
@@ -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
+ .filter(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
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.1.80".freeze
3
+ VERSION = "0.1.81".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.81
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.