subj_models 0.3.8 → 0.4

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/lib/subj_models/access_group.rb +22 -0
  4. data/lib/subj_models/action.rb +31 -0
  5. data/lib/subj_models/attribute_value.rb +32 -0
  6. data/lib/subj_models/brand.rb +5 -5
  7. data/lib/subj_models/brand_line.rb +2 -2
  8. data/lib/subj_models/category.rb +36 -0
  9. data/lib/subj_models/city.rb +31 -0
  10. data/lib/subj_models/content_block.rb +25 -0
  11. data/lib/subj_models/event_schedule.rb +4 -4
  12. data/lib/subj_models/event_type.rb +27 -0
  13. data/lib/subj_models/faq.rb +55 -0
  14. data/lib/subj_models/global_notification.rb +16 -0
  15. data/lib/subj_models/measure_unit.rb +2 -2
  16. data/lib/subj_models/nomenclature2.rb +157 -0
  17. data/lib/subj_models/nomenclature_access_group.rb +19 -0
  18. data/lib/subj_models/nomenclature_attribute.rb +27 -0
  19. data/lib/subj_models/nomenclature_price.rb +38 -0
  20. data/lib/subj_models/nomenclature_review.rb +38 -0
  21. data/lib/subj_models/nomenclature_variety.rb +29 -0
  22. data/lib/subj_models/office.rb +33 -0
  23. data/lib/subj_models/office_contact.rb +45 -0
  24. data/lib/subj_models/order.rb +77 -0
  25. data/lib/subj_models/order_delivery_courier.rb +31 -0
  26. data/lib/subj_models/order_delivery_nova_poshta_warhouse.rb +17 -0
  27. data/lib/subj_models/order_delivery_pickup.rb +28 -0
  28. data/lib/subj_models/order_delivery_privatbank.rb +30 -0
  29. data/lib/subj_models/order_delivery_subj_courier.rb +24 -0
  30. data/lib/subj_models/order_item.rb +55 -0
  31. data/lib/subj_models/quality.rb +21 -0
  32. data/lib/subj_models/specialist_activity.rb +33 -0
  33. data/lib/subj_models/specialist_activity_document_type.rb +29 -0
  34. data/lib/subj_models/template.rb +2 -0
  35. data/lib/subj_models/user.rb +10 -9
  36. data/lib/subj_models/user_card.rb +29 -0
  37. data/lib/subj_models/user_delivery_address.rb +34 -0
  38. data/lib/subj_models/user_specialization.rb +24 -0
  39. data/lib/subj_models/user_work_place.rb +29 -0
  40. data/lib/subj_models/version.rb +1 -1
  41. data/lib/subj_models.rb +31 -0
  42. metadata +33 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca667519b6e1eaea60b0cff2aee33abbedbc0915
4
- data.tar.gz: 90b6ce6ff87f9f0b82554a115a76fd2b9fcf3189
3
+ metadata.gz: 83d942dd044b470133b3d351ae6958dd3ad273b1
4
+ data.tar.gz: f0d30f8ba4c5356efd3b3f85a7c82fc42cfd7eac
5
5
  SHA512:
6
- metadata.gz: deb1126cf678f09f5bd050d0af69995af86d31d1da27b17f9be4909b00b79834866d0f83ea42cfe8d738d8de4c988a474b926de62bc3c5f96fc4e4fc041c441a
7
- data.tar.gz: e43eab6093da681c663802fa8228aea16424273182cb916baff779d8f3c6e3efe55fd99ea018106208dd3aaef96cdaca5715d45255c561d4c2acef4d127969fe
6
+ metadata.gz: a4a1e8d61751a6ddc5fd8a9374936e099e3b6d86c7d82151f20fdc423613e3dd19c263daa0d2eec7fc32255ba864e857fbf2f14d6b9866e7555e65f88383fc4f
7
+ data.tar.gz: f838d0cb6b4b771b273891259633249780ad518f79ef00d1fcef7368926ef6d35747d1adf04d92b04fdc81c4374cafde8c827de946cc95a1eed9a029bab5c4e7
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /lib/subj_models/.DS_Store
11
+ lib/.DS_Store
@@ -0,0 +1,22 @@
1
+ require 'subj_models/concerns/comprising_external_id'
2
+
3
+ module SubjModels
4
+
5
+ module AccessGroup
6
+
7
+ def self.included(including_class)
8
+
9
+ including_class.class_eval do
10
+
11
+ include SubjModels::ComprisingExternalId
12
+
13
+ has_and_belongs_to_many :user_specializations
14
+ has_and_belongs_to_many :nomenclatures, through: :nomenclature_access_groups
15
+
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,31 @@
1
+ require 'subj_models/concerns/comprising_external_id'
2
+
3
+ module SubjModels
4
+
5
+ module Action
6
+
7
+ def self.included(including_class)
8
+
9
+ including_class.class_eval do
10
+
11
+ include SubjModels::ComprisingExternalId
12
+
13
+ has_and_belongs_to_many :cities
14
+ has_and_belongs_to_many :nomenclatures
15
+ belongs_to :image, class_name: "DocumentFile"
16
+
17
+ validates :name, :discount_percent, presence: true
18
+
19
+ scope :to_show, -> condition { where(to_show: condition) }
20
+
21
+ end
22
+
23
+ end
24
+
25
+ def to_s
26
+ name
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,32 @@
1
+ require 'subj_models/concerns/comprising_external_id'
2
+
3
+ module SubjModels
4
+
5
+ module AttributeValue
6
+
7
+ def self.included(including_class)
8
+
9
+ including_class.class_eval do
10
+
11
+ include SubjModels::ComprisingExternalId
12
+
13
+ has_and_belongs_to_many :nomenclature_varieties
14
+
15
+ belongs_to :nomenclature
16
+ belongs_to :nomenclature_attribute
17
+
18
+ validates :nomenclature_value, :nomenclature_attribute, presence: true
19
+
20
+ scope :nomenclature_id, -> (nomenclature_id) { parent_id_scope("nomenclature", nomenclature_id) }
21
+
22
+ end
23
+
24
+ end
25
+
26
+ def to_s
27
+ nomenclature_value
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -13,12 +13,12 @@ module SubjModels
13
13
  include SubjModels::ComprisingExternalId
14
14
 
15
15
  has_many :brand_lines, dependent: :destroy
16
- #has_many :nomenclatures
17
- #has_many :videos
16
+ has_many :nomenclatures
17
+ has_many :videos
18
18
 
19
- #belongs_to :content_block1, class_name: "ContentBlock"
20
- #belongs_to :content_block2, class_name: "ContentBlock"
21
- #belongs_to :content_block3, class_name: "ContentBlock"
19
+ belongs_to :content_block1, class_name: "ContentBlock"
20
+ belongs_to :content_block2, class_name: "ContentBlock"
21
+ belongs_to :content_block3, class_name: "ContentBlock"
22
22
  belongs_to :document_file
23
23
 
24
24
  before_validation :set_first_letter, if: :name_changed?
@@ -12,10 +12,10 @@ module SubjModels
12
12
  include SubjModels::SharedScopes
13
13
  include SubjModels::ComprisingExternalId
14
14
 
15
- #belongs_to :brand
15
+ belongs_to :brand
16
16
  belongs_to :document_file
17
17
 
18
- #has_many :nomenclatures
18
+ has_many :nomenclatures
19
19
 
20
20
  validates :name, presence: true
21
21
 
@@ -0,0 +1,36 @@
1
+ require 'subj_models/concerns/comprising_external_id'
2
+
3
+ module SubjModels
4
+
5
+ module Category
6
+
7
+ def self.included(including_class)
8
+
9
+ including_class.class_eval do
10
+
11
+ include SubjModels::ComprisingExternalId
12
+
13
+ has_many :nomenclatures
14
+
15
+ belongs_to :image, class_name: "DocumentFile"
16
+ belongs_to :image_big, class_name: "DocumentFile"
17
+
18
+ validates :name, presence: true
19
+ #validates :slug_url, length: { minimum: 4, maximum: 50 }, uniqueness: true, presence: true
20
+
21
+ scope :by_slug_url, -> slug_url { where(slug_url: slug_url) }
22
+ scope :is_public, -> condition { where(is_public: condition) }
23
+ scope :by_id, -> ids { where(id: ids) }
24
+ scope :exclude_by_id, -> ids { where.not(id: ids) }
25
+
26
+ end
27
+
28
+ end
29
+
30
+ def to_s
31
+ name
32
+ end
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,31 @@
1
+ require 'subj_models/concerns/comprising_external_id'
2
+
3
+ module SubjModels
4
+
5
+ module City
6
+
7
+ def self.included(including_class)
8
+
9
+ including_class.class_eval do
10
+
11
+ include SubjModels::ComprisingExternalId
12
+
13
+ has_and_belongs_to_many :actions
14
+ has_many :offices
15
+ has_many :users
16
+
17
+ validates :name, presence: true, uniqueness: true
18
+
19
+ scope :with_office, -> { joins(:offices).where("offices.id IS NOT NULL").group(:id) }
20
+
21
+ end
22
+
23
+ end
24
+
25
+ def to_s
26
+ name
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,25 @@
1
+ require 'subj_models/concerns/comprising_external_id'
2
+
3
+ module SubjModels
4
+
5
+ module ContentBlock
6
+
7
+ def self.included(including_class)
8
+
9
+ including_class.class_eval do
10
+
11
+ include SubjModels::ComprisingExternalId
12
+
13
+ belongs_to :document_file
14
+
15
+ end
16
+
17
+ end
18
+
19
+ def to_s
20
+ id.to_s
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -17,11 +17,11 @@ module SubjModels
17
17
 
18
18
  enum event_type: EVENT_TYPES
19
19
 
20
- #belongs_to :event
21
- #belongs_to :city
22
- #belongs_to :office
20
+ belongs_to :event
21
+ belongs_to :city
22
+ belongs_to :office
23
23
 
24
- #has_many :order_items
24
+ has_many :order_items
25
25
 
26
26
  validates :event_type, presence: true, inclusion: { in: event_types.keys }
27
27
  validates :event_date, :event_price, :title, presence: true
@@ -0,0 +1,27 @@
1
+ require 'subj_models/concerns/comprising_external_id'
2
+
3
+ module SubjModels
4
+
5
+ module EventType
6
+
7
+ def self.included(including_class)
8
+
9
+ including_class.class_eval do
10
+
11
+ include SubjModels::ComprisingExternalId
12
+
13
+ has_many :events
14
+
15
+ validates :name, presence: true
16
+
17
+ end
18
+
19
+ end
20
+
21
+ def to_s
22
+ name
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,55 @@
1
+ require 'subj_models/concerns/comprising_external_id'
2
+
3
+ module SubjModels
4
+
5
+ module Faq
6
+
7
+ include SubjModels::TypesSupport::FaqTypes
8
+ include SubjModels::ValuesChecker
9
+
10
+ def self.included(including_class)
11
+
12
+ including_class.class_eval do
13
+
14
+ include SubjModels::ComprisingExternalId
15
+
16
+ enum faq_type: FAQ_TYPES
17
+
18
+ after_create :notify_manager
19
+ after_save :notify_user
20
+
21
+ validates :question, presence: true, allow_blank: false,
22
+ uniqueness: { message: 'Простите, такой вопрос уже был задан' }
23
+ validates :faq_type, inclusion: { in: faq_types.keys },
24
+ on: :update
25
+
26
+ scope :with_answer, -> { where.not(answer: nil) }
27
+ scope :without_answer, -> { where(answer: nil) }
28
+ scope :on_site, -> { where(show_on_site: true) }
29
+ scope :type_is, -> (condition) { where(faq_type: condition) }
30
+
31
+ end
32
+
33
+ end
34
+
35
+ def to_s
36
+ question
37
+ end
38
+
39
+ def faq_type=(value)
40
+ super(check_string_for_int(value))
41
+ end
42
+
43
+ private
44
+
45
+ def notify_manager
46
+ FaqMailer.notify_manager(self).deliver
47
+ end
48
+
49
+ def notify_user
50
+ FaqMailer.notify_user(self).deliver if send_to_user
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,16 @@
1
+ module SubjModels
2
+
3
+ module GlobalNotification
4
+
5
+ def self.included(including_class)
6
+
7
+ including_class.class_eval do
8
+
9
+
10
+ end
11
+
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -10,9 +10,9 @@ module SubjModels
10
10
 
11
11
  include SubjModels::ComprisingExternalId
12
12
 
13
- #belongs_to :attribute_value
13
+ belongs_to :attribute_value
14
14
 
15
- #has_many :nomenclature_prices
15
+ has_many :nomenclature_prices
16
16
 
17
17
  validates :name, presence: true
18
18
 
@@ -0,0 +1,157 @@
1
+ require 'json'
2
+ require 'subj_models/concerns/comprising_external_id'
3
+
4
+ module SubjModels
5
+
6
+ module Nomenclature2
7
+
8
+ def self.included(including_class)
9
+
10
+ including_class.class_eval do
11
+
12
+ include SubjModels::ComprisingExternalId
13
+
14
+ belongs_to :brand_line
15
+ belongs_to :brand
16
+ belongs_to :specialist_activity
17
+ belongs_to :category
18
+
19
+ has_many :nomenclature_varieties, dependent: :destroy
20
+ has_many :nomenclature_photos, dependent: :destroy
21
+ has_many :nomenclature_reviews, dependent: :destroy
22
+ has_many :nomenclature_files, dependent: :destroy
23
+ has_many :events
24
+ has_many :attribute_values, dependent: :destroy
25
+ has_many :nomenclature_prices
26
+
27
+ belongs_to :analog_related_nomenclature, class_name: "Nomenclature"
28
+ has_many :analogs, foreign_key: "analog_related_nomenclature_id", class_name: "Nomenclature"
29
+ belongs_to :bought_together_related_nomenclature, class_name: "Nomenclature"
30
+ has_many :bought_together, foreign_key: "bought_together_related_nomenclature_id", class_name: "Nomenclature"
31
+
32
+ has_and_belongs_to_many :actions
33
+ has_and_belongs_to_many :access_groups, through: :nomenclature_access_groups
34
+
35
+ validates :name, presence: true
36
+
37
+ scope :with_category, -> { where.not(category_id: nil) }
38
+ scope :brand_line_ids, -> (brand_line_id) { where(brand_line_id: brand_line_id) }
39
+ scope :with_action, -> { joins(:actions).distinct }
40
+ scope :is_recommended, -> condition { where(is_recommended: condition) }
41
+ scope :is_stock, -> (condition) do
42
+ nomenclature_prices_join.joins("LEFT OUTER JOIN qualities ON qualities.id = nomenclature_prices.quality_id").where("qualities.is_stock" => condition)
43
+ end
44
+
45
+ scope :bought_together_external_id, -> (ids) do
46
+ order_ids = Order.joins(order_items: [nomenclature_variety: :nomenclature]).where("nomenclatures.external_id IN (?)", ids).uniq.pluck(:id)
47
+ Nomenclature.joins(nomenclature_varieties: [order_items: :order]).where("orders.id" => order_ids).order(:id).uniq
48
+ end
49
+
50
+ 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) : []
56
+ where(id: ids)
57
+ end
58
+
59
+ scope :only_promotional, -> do
60
+ joins(:actions).uniq
61
+ end
62
+
63
+ scope :is_professional, -> (condition) {where(is_professional: condition) }
64
+
65
+ scope :price, -> (prices) do
66
+ prices = prices.map { |p| p.split(',') }
67
+ nomenclature_prices_join.
68
+ where(
69
+ prices.map do |range|
70
+ if range[0] && range[1]
71
+ '(nomenclature_prices.current_price >= ? AND nomenclature_prices.current_price < ?)'
72
+ elsif range[0]
73
+ '(nomenclature_prices.current_price >= ?)'
74
+ elsif range[1]
75
+ '(nomenclature_prices.current_price < ?)'
76
+ end
77
+ end.join(' OR '),
78
+ *prices.map(&:compact).flatten
79
+ )
80
+ end
81
+
82
+ scope :order_by_name, -> (ordering) do
83
+ ordering = ordering.second.try(:to_sym)
84
+ order(name: ordering)
85
+ end
86
+
87
+ scope :order_by_popularity, -> (ordering) do
88
+ ordering = ordering.second.try(:to_sym)
89
+ order(popularity: ordering)
90
+ end
91
+
92
+ scope :attribute_value_ids, -> (attribute_value_name_strings) do
93
+ query_result = nil
94
+ nomenclature_ids = ids
95
+ attribute_value_name_strings.each do |str|
96
+ attr_names = str.split('/')
97
+ query_result = Nomenclature.joins(:attribute_values).where("attribute_values.nomenclature_value" => attr_names).where(id: nomenclature_ids).uniq
98
+ nomenclature_ids = query_result.pluck(:id)
99
+ end
100
+
101
+ query_result
102
+ end
103
+
104
+ scope :nomenclature_prices_join, -> do
105
+ joins(:nomenclature_prices)
106
+ #joins('LEFT OUTER JOIN nomenclature_varieties ON nomenclature_varieties.id = (SELECT innerNomVar.id FROM nomenclature_varieties as innerNomVar WHERE innerNomVar.nomenclature_id = nomenclatures.id LIMIT 1)')
107
+ #.joins('LEFT OUTER JOIN nomenclature_prices on nomenclature_prices.id = (SELECT innerNomPrice.id FROM nomenclature_prices AS innerNomPrice WHERE innerNomPrice.nomenclature_variety_id = nomenclature_varieties.id LIMIT 1)')
108
+ end
109
+
110
+ scope :order_by_price, -> (ordering) do
111
+ ordering = ordering.second.try(:to_sym)
112
+ if [:asc, :desc].include? ordering
113
+ nomenclature_prices_join.
114
+ order("nomenclature_prices.current_price #{ordering}")
115
+ end
116
+ end
117
+
118
+ scope :category_id, -> (category_id) do
119
+ return all unless category_id.present?
120
+ where(category_id: category_id)
121
+ end
122
+
123
+ scope :nomenclature_ids, -> (ids) { where(id: ids) }
124
+
125
+ scope :brand_ids, -> (brand) do
126
+ return all unless brand.present?
127
+ joins(:brand_line).where(brand_lines: { brand_id: brand }) #TODO join brands in two ways
128
+ end
129
+
130
+ scope :brand_line_ids, -> (ids) do
131
+ return all unless ids.present?
132
+ where(brand_line_id: ids)
133
+ end
134
+
135
+ end
136
+
137
+ end
138
+
139
+ def is_bought(user_id)
140
+ Order.joins(order_items: :nomenclature)
141
+ .where("nomenclatures.id IN (?)", self.id)
142
+ .where(user_id: user_id).any?
143
+ end
144
+
145
+ def to_s
146
+ id.to_s # TODO
147
+ end
148
+
149
+ def self.name_field_update(field)
150
+ if field.to_s == 'name' #TODO refactor this
151
+ field = 'name.raw'
152
+ end
153
+ end
154
+
155
+ end
156
+
157
+ end
@@ -0,0 +1,19 @@
1
+ require 'subj_models/concerns/comprising_external_id'
2
+
3
+ module SubjModels
4
+
5
+ module NomenclatureAccessGroup
6
+
7
+ def self.included(including_class)
8
+
9
+ including_class.class_eval do
10
+
11
+ include SubjModels::ComprisingExternalId
12
+
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,27 @@
1
+ require 'subj_models/concerns/comprising_external_id'
2
+
3
+ module SubjModels
4
+
5
+ module NomenclatureAttribute
6
+
7
+ def self.included(including_class)
8
+
9
+ including_class.class_eval do
10
+
11
+ include SubjModels::ComprisingExternalId
12
+
13
+ has_many :attribute_values, dependent: :destroy
14
+
15
+ validates :name, presence: true
16
+
17
+ end
18
+
19
+ end
20
+
21
+ def to_s
22
+ name
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,38 @@
1
+ require 'subj_models/concerns/comprising_external_id'
2
+
3
+ module SubjModels
4
+
5
+ module NomenclaturePrice
6
+
7
+ def self.included(including_class)
8
+
9
+ including_class.class_eval do
10
+
11
+ include SubjModels::ComprisingExternalId
12
+
13
+ belongs_to :nomenclature, touch: true
14
+ belongs_to :nomenclature_variety
15
+ belongs_to :quality
16
+ belongs_to :measure_unit
17
+
18
+ has_many :order_items
19
+
20
+ validates :current_price, presence: true
21
+
22
+ scope :nomenclature_id, -> (nomenclature_id) { parent_id_scope("nomenclature", nomenclature_id) }
23
+
24
+ scope :belongs_to_nomenclature, -> (nomenclature_id) do
25
+ where(nomenclature_id: nomenclature_id).union(joins(:nomenclature_variety).where("nomenclature_varieties.nomenclature_id" => nomenclature_id))
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+
32
+ def to_s
33
+ id.to_s # TODO
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,38 @@
1
+ require 'subj_models/concerns/comprising_external_id'
2
+
3
+ module SubjModels
4
+
5
+ module NomenclatureReview
6
+
7
+ def self.included(including_class)
8
+
9
+ including_class.class_eval do
10
+
11
+ include SubjModels::ComprisingExternalId
12
+
13
+ after_create :notify
14
+
15
+ belongs_to :nomenclature
16
+ belongs_to :user
17
+
18
+ validates :user, :nomenclature, :content, presence: true
19
+
20
+ scope :nomenclature_id, -> nomenclature { where(nomenclature_id: nomenclature) }
21
+
22
+ scope :approved, -> { where(review_approved: true) }
23
+
24
+ scope :without_approves, -> { where(review_approved: false) }
25
+
26
+ end
27
+
28
+ end
29
+
30
+ private
31
+
32
+ def notify
33
+ NomenclatureReviewMailer.notify(self).deliver
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,29 @@
1
+ require 'subj_models/concerns/comprising_external_id'
2
+
3
+ module SubjModels
4
+
5
+ module NomenclatureVariety
6
+
7
+ def self.included(including_class)
8
+
9
+ including_class.class_eval do
10
+
11
+ include SubjModels::ComprisingExternalId
12
+
13
+ belongs_to :nomenclature
14
+
15
+ has_many :nomenclature_prices
16
+ has_many :order_items
17
+
18
+ validates :name, presence: true
19
+
20
+ scope :external_id, -> id { where(external_id: id) }
21
+ scope :nomenclature_id, -> (nomenclature_id) { parent_id_scope("nomenclature", nomenclature_id) }
22
+
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+
29
+ end