comee_core 0.1.79 → 0.1.81

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: d71a8200c433afbae99cbd4b1ca79c35eee1213e1192ebe7e0af4094f172bc41
4
- data.tar.gz: fa8fd302ec0376de853aa014d980f261c6cbabe517c1f7a5e1723a887271a98e
3
+ metadata.gz: a4318ef428c28e4dbcf4fe933ec2b485b451988f05b512743d27eee5279cd86f
4
+ data.tar.gz: d2ac11b22312a1ec6255c96f2bdcffed7339d4e5d53a8b547e5c478de715c509
5
5
  SHA512:
6
- metadata.gz: 62e97416902c0185884d83f89bd19ea26a0b02e9a7aae46c8e144a57c2adeb9207fe577899490617eb75a2aadbcf868e30ec5443d0e8ffb12c7beef5f81acaee
7
- data.tar.gz: 44d4a262ac39c7e97c7096cdc214ed842bf1f764d4b4233038decf27ef38fbcef8aba9d5e60622ba2ce9674ba7fc2775847c5775c615eaf0e7dda4972dc0df6e
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
@@ -17,8 +17,13 @@ module Comee
17
17
  code
18
18
  name
19
19
  locale
20
+ parent_id
20
21
  ]
21
22
  end
23
+
24
+ def self.ransackable_associations(_auth_object = nil)
25
+ ["parent"]
26
+ end
22
27
  end
23
28
  end
24
29
  end
@@ -5,11 +5,23 @@ module Comee
5
5
  belongs_to :client
6
6
  belongs_to :previous_price, class_name: "Comee::Core::ClientPrice", optional: true
7
7
  belongs_to :next_price, class_name: "Comee::Core::ClientPrice", optional: true
8
+ belongs_to :product_lookup, optional: true
8
9
 
9
10
  validates :price, :margin_type, presence: true
10
11
  validates :price, numericality: {greater_than: 0}
11
12
  validates :margin, presence: true, numericality: {greater_than_or_equal_to: 0, less_than_or_equal_to: 100}
12
13
  validates :product_id, uniqueness: {scope: %i[client_id previous_price_id next_price_id status]}
14
+ validate :validate_product_lookup
15
+
16
+ def validate_product_lookup
17
+ return unless product_lookup && product && client
18
+
19
+ if product_lookup.itemable_id != client_id ||
20
+ product_lookup.itemable_type != "Comee::Core::Client" ||
21
+ product_lookup.product_id != product_id
22
+ errors.add(:product_lookup, "contains wrong client or product.")
23
+ end
24
+ end
13
25
 
14
26
  def self.ransackable_attributes(_auth_object = nil)
15
27
  %w[
@@ -25,7 +37,7 @@ module Comee
25
37
  end
26
38
 
27
39
  def self.ransackable_associations(_auth_object = nil)
28
- %w[product client]
40
+ %w[product client product_lookup]
29
41
  end
30
42
  end
31
43
  end
@@ -4,11 +4,12 @@ module Comee
4
4
  belongs_to :supplier
5
5
  belongs_to :previous_price, class_name: "Comee::Core::MasterPrice", optional: true
6
6
  belongs_to :next_price, class_name: "Comee::Core::MasterPrice", optional: true
7
+ belongs_to :product_lookup, optional: true
7
8
 
8
9
  validates :purchase_price, :selling_price, presence: true
9
10
  validates :margin, presence: true, numericality: {greater_than_or_equal_to: 0, less_than_or_equal_to: 100}
10
11
  validates :product_id, uniqueness: {scope: %i[supplier_id previous_price_id next_price_id status]}
11
- validate :validate_primary_price
12
+ validate :validate_primary_price, :validate_product_lookup
12
13
 
13
14
  scope :current_primary, -> { where(primary: true).current }
14
15
  scope :unapplied, -> { where(propagated_to_client: false).current_primary }
@@ -30,6 +31,16 @@ module Comee
30
31
  errors.add(:base, "There is already a primary price entry for item '#{product.code}'")
31
32
  end
32
33
 
34
+ def validate_product_lookup
35
+ return unless product_lookup && product && supplier
36
+
37
+ if product_lookup.itemable_id != supplier_id ||
38
+ product_lookup.itemable_type != "Comee::Core::Supplier" ||
39
+ product_lookup.product_id != product_id
40
+ errors.add(:product_lookup, "contains wrong supplier or product.")
41
+ end
42
+ end
43
+
33
44
  def self.ransackable_attributes(_auth_object = nil)
34
45
  %w[
35
46
  valid_from
@@ -45,7 +56,7 @@ module Comee
45
56
  end
46
57
 
47
58
  def self.ransackable_associations(_auth_object = nil)
48
- %w[product supplier]
59
+ %w[product supplier product_lookup]
49
60
  end
50
61
  end
51
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
@@ -29,6 +29,10 @@ class CreateComeeCoreMasterPrices < ActiveRecord::Migration[7.0]
29
29
  null: true,
30
30
  index: {name: "next_price_on_ccsp_indx"},
31
31
  foreign_key: {to_table: :comee_core_master_prices}
32
+ t.references :product_lookup,
33
+ null: true,
34
+ index: {name: "pl_on_ccmp_indx"},
35
+ foreign_key: {to_table: :comee_core_product_lookups}
32
36
  t.boolean :propagated_to_client, null: false, default: false
33
37
 
34
38
  t.timestamps
@@ -27,6 +27,10 @@ class CreateComeeCoreClientPrices < ActiveRecord::Migration[7.0]
27
27
  null: true,
28
28
  index: {name: "next_price_on_cccp_indx"},
29
29
  foreign_key: {to_table: :comee_core_client_prices}
30
+ t.references :product_lookup,
31
+ null: true,
32
+ index: {name: "pl_on_cccp_indx"},
33
+ foreign_key: {to_table: :comee_core_product_lookups}
30
34
 
31
35
  t.timestamps
32
36
  end
@@ -1,5 +1,5 @@
1
1
  module Comee
2
2
  module Core
3
- VERSION = "0.1.79".freeze
3
+ VERSION = "0.1.81".freeze
4
4
  end
5
5
  end
@@ -11,6 +11,7 @@ FactoryBot.define do
11
11
  margin_type { Comee::Core::ClientPrice.margin_types[:increase] }
12
12
  previous_price { nil }
13
13
  next_price { nil }
14
+ product_lookup { nil }
14
15
 
15
16
  trait :past do
16
17
  valid_from { Date.current.advance(months: -2) }
@@ -12,6 +12,7 @@ FactoryBot.define do
12
12
  unit
13
13
  previous_price { nil }
14
14
  next_price { nil }
15
+ product_lookup { nil }
15
16
  propagated_to_client { false }
16
17
 
17
18
  trait :past do
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.79
4
+ version: 0.1.81
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-01-05 00:00:00.000000000 Z
11
+ date: 2024-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -401,9 +401,9 @@ files:
401
401
  - db/migrate/20230811102708_create_comee_core_customer_order_items.rb
402
402
  - db/migrate/20230812190652_create_comee_core_sales_orders.rb
403
403
  - db/migrate/20230812212844_create_comee_core_sales_order_items.rb
404
+ - db/migrate/20230813041307_create_comee_core_product_lookups.rb
404
405
  - db/migrate/20230813235946_create_comee_core_master_prices.rb
405
406
  - db/migrate/20230814151601_create_comee_core_client_prices.rb
406
- - db/migrate/20230914041307_create_comee_core_product_lookups.rb
407
407
  - db/migrate/20230915205522_create_comee_core_invoices.rb
408
408
  - db/migrate/20230915205648_create_comee_core_invoice_items.rb
409
409
  - db/migrate/20230929115336_create_comee_core_order_sources.rb