subj_models 0.4.2 → 0.4.3

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: e793645f8990aed3b68c7f6975dc240ac7f26a26
4
- data.tar.gz: 13a3a0aeb8d2152232ab075b5c5b6413a23319b9
3
+ metadata.gz: 84241f6129048ebc4734a5b85a99d1ca8dbf02d0
4
+ data.tar.gz: f626cdcd3b1d2b5b06f617733b6c4ff97c884d5a
5
5
  SHA512:
6
- metadata.gz: faf041f77a447d3024200925fdc8fa077fb4f56e3f1616ff50a800108fa0c14405b991f6eda8f794c85272b4767ad1ed4f6ce67e780dc224416d68354d410248
7
- data.tar.gz: ec9d2f8a8a6b83e4b9e6035ccd2ce68a39bc830fd2db7dc8e210e3d614c88ce2c2a4ba47b518e7fb298d04b8bb7a01c2af859457960a1de68f6ffbe9195e399d
6
+ metadata.gz: 1e182bdd11fee25f45f63acb62500d154679df971a5de1d7da2ef6c317e21c09fb910a584babaaf6c434aef149b972830e39ee8c93ea9f7c25e46f72942b71e6
7
+ data.tar.gz: 6455c3d590b45ee561f73114569c59fd620b24491b2e2555ef76b8498c53dcb9d60a1fd40461df7898f15c73b0930a741a0ec6be25501f49ff3f0c3524e9b4c6
@@ -15,6 +15,7 @@ module SubjModels
15
15
  has_many :brand_lines, dependent: :destroy
16
16
  has_many :nomenclatures
17
17
  has_many :videos
18
+ has_and_belongs_to_many :users
18
19
 
19
20
  belongs_to :content_block1, class_name: "ContentBlock"
20
21
  belongs_to :content_block2, class_name: "ContentBlock"
@@ -25,6 +26,9 @@ module SubjModels
25
26
 
26
27
  validates :name, presence: true
27
28
 
29
+ scope :in_index_list, -> condition { where(show_on_index: condition) }
30
+ scope :in_recommended_list, -> condition { where(is_recommended: condition) }
31
+
28
32
  scope :category_id, -> (category_id) do
29
33
  return all if category_id.blank?
30
34
  joins(brand_lines: [{ nomenclatures: :category}]).where('categories.id' => category_id)
@@ -17,7 +17,9 @@ module SubjModels
17
17
  end
18
18
 
19
19
  def to_s
20
- id.to_s
20
+ brands = Brand.where('content_block1_id=? OR (content_block2_id=? OR content_block3_id=?)', id, id, id)
21
+
22
+ "#{title} - #{brands.any? ? 'С брендом' : 'Без бренда'}"
21
23
  end
22
24
 
23
25
  end
@@ -22,7 +22,7 @@ module SubjModels
22
22
  has_many :nomenclature_files, dependent: :destroy
23
23
  has_many :events
24
24
  has_many :attribute_values, dependent: :destroy
25
- has_many :nomenclature_prices
25
+ has_many :nomenclature_prices, dependent: :destroy
26
26
 
27
27
  belongs_to :analog_related_nomenclature, class_name: "Nomenclature"
28
28
  has_many :analogs, foreign_key: "analog_related_nomenclature_id", class_name: "Nomenclature"
@@ -38,6 +38,7 @@ module SubjModels
38
38
  scope :brand_line_ids, -> (brand_line_id) { where(brand_line_id: brand_line_id) }
39
39
  scope :with_action, -> { joins(:actions).distinct }
40
40
  scope :is_recommended, -> condition { where(is_recommended: condition) }
41
+ scope :in_index_list, -> condition { where(show_on_index: condition) }
41
42
  scope :is_stock, -> (condition) do
42
43
  nomenclature_prices_join.joins("LEFT OUTER JOIN qualities ON qualities.id = nomenclature_prices.quality_id").where("qualities.is_stock" => condition)
43
44
  end
@@ -124,7 +125,12 @@ module SubjModels
124
125
 
125
126
  scope :brand_ids, -> (brand) do
126
127
  return all unless brand.present?
127
- joins(:brand_line).where(brand_lines: { brand_id: brand }) #TODO join brands in two ways
128
+ where(brand: brand)
129
+ end
130
+
131
+ scope :with_brand, -> (brand) do
132
+ return none unless brand.present?
133
+ where(brand: brand)
128
134
  end
129
135
 
130
136
  scope :brand_line_ids, -> (ids) do
@@ -143,7 +149,7 @@ module SubjModels
143
149
  end
144
150
 
145
151
  def to_s
146
- id.to_s # TODO
152
+ name.to_s # TODO
147
153
  end
148
154
 
149
155
  def self.name_field_update(field)
@@ -8,8 +8,9 @@ module SubjModels
8
8
  ADMIN = 1
9
9
  LEGAL_PERSON = 2
10
10
  NATURAL_PERSON = 3
11
+ DISTRIBUTOR = 4
11
12
 
12
- USER_TYPES = { 'админ' => ADMIN, 'юридическое лицо' => LEGAL_PERSON, 'физическое лицо' => NATURAL_PERSON }
13
+ USER_TYPES = { 'админ' => ADMIN, 'юридическое лицо' => LEGAL_PERSON, 'физическое лицо' => NATURAL_PERSON, 'поставщик' => DISTRIBUTOR }
13
14
  end
14
15
 
15
16
  module EventTypes
@@ -29,6 +29,7 @@ module SubjModels
29
29
  enum user_type: USER_TYPES
30
30
  enum card_receive_type: CARD_RECEIVE_TYPES
31
31
 
32
+
32
33
  has_many :orders
33
34
  has_many :user_specialization_approvals, dependent: :destroy
34
35
  has_many :user_cards, dependent: :destroy
@@ -36,6 +37,7 @@ module SubjModels
36
37
  has_many :user_delivery_addresses, dependent: :destroy
37
38
 
38
39
  has_and_belongs_to_many :user_specializations
40
+ has_and_belongs_to_many :brands
39
41
 
40
42
  belongs_to :document_file
41
43
  belongs_to :city
@@ -96,10 +98,6 @@ module SubjModels
96
98
  email
97
99
  end
98
100
 
99
- def admin?
100
- self.user_type == 'админ'
101
- end
102
-
103
101
  def available_nomenclature_ids
104
102
  Nomenclature.joins(access_groups: [user_specializations: :users]).where("users.id" => self.id).uniq.pluck(:id)
105
103
  end
@@ -1,3 +1,3 @@
1
1
  module SubjModels
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -21,7 +21,7 @@ module SubjModels
21
21
  end
22
22
 
23
23
  def to_s
24
- id.to_s
24
+ "#{title1} #{title2}#{' - ПРОМО' if is_promo}"
25
25
  end
26
26
 
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subj_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denys Dvoriashyn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-29 00:00:00.000000000 Z
11
+ date: 2016-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  requirements: []
130
130
  rubyforge_project:
131
- rubygems_version: 2.6.6
131
+ rubygems_version: 2.5.1
132
132
  signing_key:
133
133
  specification_version: 4
134
134
  summary: Move models from some project to gem.