subj_sub_models 0.0.3.25 → 0.0.3.26

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
  SHA1:
3
- metadata.gz: 52816493b98dd3e9d4521321b876515ee553b7c6
4
- data.tar.gz: bea5b8ed8c0f9f3f9df4657829aa7fb2929fc0b2
3
+ metadata.gz: fce6ce8300b955f3b964930c019699991c4588a0
4
+ data.tar.gz: aae15f23a478110ab92354cde71d289635fae7eb
5
5
  SHA512:
6
- metadata.gz: da355780261d61bfb6cf5675a44505028bc0233d19645afa683abe5687cc4de8fe6170c02e221a338e4e20d1d468cd752b7d7a8bca4347801da8803849a5b9d6
7
- data.tar.gz: c1a2b7f9c03d35219fe1aca9827fb19992e12165829432ed066618f6a7f0ac452f18123d2b721c084a94cef7a06e9312db63d4864046d2814337cd44da43bb6f
6
+ metadata.gz: 0416e17adecd52ced25e337312ab5d38b25e805784009906bda82d4ef82b2cb5364c4e10010a95e0c42a2d9d35252605da3c6b05a51e13fbdc43fd2d6aab0a8c
7
+ data.tar.gz: 21a2419b12c711fb29ae1d7810e45e45cdcb35df81eed1143e654504adabbab74e97565531737951b5803147f871a4dc3f2bec60ef2bfb8ddb4977a1d0812090
@@ -0,0 +1,15 @@
1
+ module SubjModels
2
+ module RecordsUnion
3
+
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def union(relations, opts={})
8
+ query = 'SELECT '+ (opts[:distinct] ? 'DISTINCT ' : '' ) + (!opts[:fields].blank? ? opts[:fields].map(&:to_s).join(' ') : '*') + ' FROM ((' + relations.map { |r| r.ast.to_sql }.join(') UNION (') + ')) AS t'
9
+ query << " ORDER BY #{opts[:order]}" if opts[:order]
10
+ query << " LIMIT #{opts[:limit]}" if opts[:limit]
11
+ find_by_sql(query)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,6 @@
1
1
  require 'json'
2
2
  require 'subj_models/concerns/comprising_external_id'
3
+ require 'subj_models/concerns/records_union'
3
4
 
4
5
  module SubjModels
5
6
 
@@ -10,6 +11,7 @@ module SubjModels
10
11
  including_class.class_eval do
11
12
 
12
13
  include SubjModels::ComprisingExternalId
14
+ include SubjModels::RecordsUnion
13
15
 
14
16
  belongs_to :brand_line
15
17
  belongs_to :brand
@@ -48,11 +50,8 @@ module SubjModels
48
50
  end
49
51
 
50
52
  scope :is_available, -> (params) do
51
- is_available = params.first
52
- return all unless is_available == 'true'
53
- user = User.find_by(id: params.second.to_i)
54
- not_professional_ids = Nomenclature.is_professional(false).pluck(:id)
55
- ids = user ? user.available_nomenclature_ids.concat(not_professional_ids) : []
53
+ return all unless params.first == 'true'
54
+ ids = (user = User.find_by(id: params.second.to_i)) ? user.available_nomenclature_ids : []
56
55
  where(id: ids)
57
56
  end
58
57
 
@@ -125,7 +125,9 @@ module SubjModels
125
125
  end
126
126
 
127
127
  def available_nomenclature_ids
128
- Nomenclature.joins(access_groups: [user_specializations: :users]).where("users.id" => self.id).uniq.pluck(:id)
128
+ nomenclatures_available_for_user = Nomenclature.joins(access_groups: [user_specializations: :users]).where("users.id" => self.id)
129
+ nomenclatures_with_b2c_prices = Nomenclature.joins(:nomenclature_prices).where('nomenclature_prices.price_type = ?', NomenclaturePrice.price_types['b2c'] )
130
+ Nomenclature.union([nomenclatures_available_for_user, nomenclatures_with_b2c_prices], distinct: true).map(&:id)
129
131
  end
130
132
 
131
133
  def available_categories_ids
@@ -1,3 +1,3 @@
1
1
  module SubjModels
2
- VERSION = '0.0.3.25'
2
+ VERSION = '0.0.3.26'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subj_sub_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.25
4
+ version: 0.0.3.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - A.Nasa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-15 00:00:00.000000000 Z
11
+ date: 2017-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -65,6 +65,7 @@ files:
65
65
  - lib/subj_models/category.rb
66
66
  - lib/subj_models/city.rb
67
67
  - lib/subj_models/concerns/comprising_external_id.rb
68
+ - lib/subj_models/concerns/records_union.rb
68
69
  - lib/subj_models/concerns/shared_scopes.rb
69
70
  - lib/subj_models/content_block.rb
70
71
  - lib/subj_models/document_file.rb