subj_sub_models 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.idea/modules.xml +1 -1
  4. data/.idea/workspace.xml +5 -5
  5. data/Gemfile +1 -1
  6. data/README.md +3 -3
  7. data/bin/console +1 -1
  8. data/lib/subj_models/access_group.rb +22 -0
  9. data/lib/subj_models/action_banner.rb +37 -0
  10. data/lib/subj_models/attribute_value.rb +32 -0
  11. data/lib/subj_models/brand.rb +74 -0
  12. data/lib/subj_models/brand_line.rb +51 -0
  13. data/lib/subj_models/category.rb +36 -0
  14. data/lib/subj_models/city.rb +31 -0
  15. data/lib/subj_models/concerns/comprising_external_id.rb +37 -0
  16. data/lib/subj_models/concerns/shared_scopes.rb +15 -0
  17. data/lib/subj_models/content_block.rb +28 -0
  18. data/lib/subj_models/document_file.rb +38 -0
  19. data/lib/subj_models/event.rb +79 -0
  20. data/lib/subj_models/event_booking.rb +39 -0
  21. data/lib/subj_models/event_schedule.rb +37 -0
  22. data/lib/subj_models/event_type.rb +27 -0
  23. data/lib/subj_models/faq.rb +46 -0
  24. data/lib/subj_models/global_notification.rb +16 -0
  25. data/lib/subj_models/manager.rb +31 -0
  26. data/lib/subj_models/measure_unit.rb +28 -0
  27. data/lib/subj_models/nomenclature.rb +166 -0
  28. data/lib/subj_models/nomenclature_access_group.rb +19 -0
  29. data/lib/subj_models/nomenclature_attribute.rb +27 -0
  30. data/lib/subj_models/nomenclature_file.rb +44 -0
  31. data/lib/subj_models/nomenclature_photo.rb +36 -0
  32. data/lib/subj_models/nomenclature_price.rb +39 -0
  33. data/lib/subj_models/nomenclature_review.rb +38 -0
  34. data/lib/subj_models/nomenclature_variety.rb +29 -0
  35. data/lib/subj_models/office.rb +40 -0
  36. data/lib/subj_models/office_contact.rb +41 -0
  37. data/lib/subj_models/order.rb +91 -0
  38. data/lib/subj_models/order_delivery_courier.rb +31 -0
  39. data/lib/subj_models/order_delivery_nova_poshta_warhouse.rb +20 -0
  40. data/lib/subj_models/order_delivery_pickup.rb +28 -0
  41. data/lib/subj_models/order_delivery_privatbank.rb +29 -0
  42. data/lib/subj_models/order_delivery_subj_courier.rb +25 -0
  43. data/lib/subj_models/order_item.rb +60 -0
  44. data/lib/subj_models/quality.rb +25 -0
  45. data/lib/subj_models/services/types_support.rb +122 -0
  46. data/lib/subj_models/services/values_checker.rb +11 -0
  47. data/lib/subj_models/specialist_activity.rb +33 -0
  48. data/lib/subj_models/specialist_activity_document_type.rb +29 -0
  49. data/lib/subj_models/template.rb +18 -0
  50. data/lib/subj_models/user.rb +131 -0
  51. data/lib/subj_models/user_card.rb +29 -0
  52. data/lib/subj_models/user_card_delivery.rb +29 -0
  53. data/lib/subj_models/user_delivery_address.rb +34 -0
  54. data/lib/subj_models/user_specialization.rb +38 -0
  55. data/lib/subj_models/user_specialization_approval.rb +33 -0
  56. data/lib/subj_models/user_work_place.rb +29 -0
  57. data/lib/subj_models/version.rb +3 -0
  58. data/lib/subj_models/video.rb +29 -0
  59. data/lib/subj_models.rb +49 -0
  60. data/subj_models.gemspec +33 -0
  61. data/subj_models.iml +9 -0
  62. metadata +56 -2
@@ -0,0 +1,20 @@
1
+ module SubjModels
2
+
3
+ module OrderDeliveryNovaPoshtaWarhouseModule
4
+
5
+ def self.included(including_class)
6
+
7
+ including_class.class_eval do
8
+ include SubjModels::ComprisingExternalId
9
+
10
+ belongs_to :order
11
+
12
+ scope :order_id, -> (order_id) { parent_id_scope("order", order_id) }
13
+
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,28 @@
1
+ require 'subj_models/concerns/comprising_external_id'
2
+
3
+ module SubjModels
4
+
5
+ module OrderDeliveryPickupModule
6
+
7
+ def self.included(including_class)
8
+
9
+ including_class.class_eval do
10
+
11
+ include SubjModels::ComprisingExternalId
12
+
13
+ belongs_to :order
14
+ belongs_to :office
15
+
16
+ scope :order_id, -> (order_id) { parent_id_scope("order", order_id) }
17
+
18
+ end
19
+
20
+ end
21
+
22
+ def to_s
23
+ id.to_s # TODO
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,29 @@
1
+ require 'subj_models/concerns/comprising_external_id'
2
+
3
+ module SubjModels
4
+
5
+ module OrderDeliveryPrivatbankModule
6
+
7
+ def self.included(including_class)
8
+
9
+ including_class.class_eval do
10
+
11
+ include SubjModels::ComprisingExternalId
12
+
13
+ belongs_to :order
14
+
15
+ validates :privat_bank_address, presence: true
16
+
17
+ scope :order_id, -> (order_id) { parent_id_scope("order", order_id) }
18
+
19
+ end
20
+
21
+ end
22
+
23
+ def to_s
24
+ id.to_s # TODO
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,25 @@
1
+ module SubjModels
2
+
3
+ module OrderDeliverySubjCourierModule
4
+
5
+ def self.included(including_class)
6
+
7
+ including_class.class_eval do
8
+ include SubjModels::ComprisingExternalId
9
+
10
+ belongs_to :order
11
+ belongs_to :city
12
+
13
+ scope :order_id, -> (order_id) { parent_id_scope("order", order_id) }
14
+
15
+ end
16
+
17
+ end
18
+
19
+ def to_s
20
+ id.to_s # TODO
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,60 @@
1
+ require 'subj_models/concerns/comprising_external_id'
2
+ require 'subj_models/services/values_checker'
3
+
4
+ module SubjModels
5
+
6
+ module OrderItemModule
7
+
8
+ include SubjModels::TypesSupport::ItemTypes
9
+ include SubjModels::ValuesChecker
10
+
11
+ def self.included(including_class)
12
+
13
+ including_class.class_eval do
14
+
15
+ include SubjModels::ComprisingExternalId
16
+
17
+ # before_destroy :decrease_nomenclature_popularity
18
+ # after_create :increase_nomenclature_popularity
19
+
20
+ enum item_type: ITEM_TYPES
21
+
22
+ belongs_to :order
23
+ belongs_to :event
24
+ belongs_to :nomenclature_variety
25
+ belongs_to :nomenclature
26
+ belongs_to :quality
27
+
28
+ validates :item_type, presence: true, inclusion: { in: item_types.keys }
29
+ validates :item_price, :item_count, presence: true
30
+
31
+ scope :order_id, -> (order_id) { parent_id_scope("order", order_id) }
32
+ scope :without_autoadded, -> { where(autoaddedposition: [nil, false]) }
33
+
34
+ end
35
+
36
+ end
37
+
38
+ def to_s
39
+ id.to_s # TODO
40
+ end
41
+
42
+ private
43
+
44
+ # def increase_nomenclature_popularity
45
+ # if nomenclature
46
+ # current_popularity = (nomenclature.popularity && nomenclature.popularity > 0) ? nomenclature.popularity : 0
47
+ # nomenclature.update(popularity: current_popularity + item_count)
48
+ # end
49
+ # end
50
+
51
+ # def decrease_nomenclature_popularity
52
+ # if nomenclature
53
+ # current_popularity = (nomenclature.popularity && nomenclature.popularity > item_count) ? nomenclature.popularity : item_count
54
+ # nomenclature.update(popularity: current_popularity - item_count)
55
+ # end
56
+ # end
57
+
58
+ end
59
+
60
+ end
@@ -0,0 +1,25 @@
1
+ require 'subj_models/concerns/comprising_external_id'
2
+
3
+ module SubjModels
4
+
5
+ module QualityModule
6
+
7
+ def self.included(including_class)
8
+
9
+ including_class.class_eval do
10
+
11
+ include SubjModels::ComprisingExternalId
12
+
13
+ has_many :nomenclature_prices
14
+
15
+ end
16
+
17
+ end
18
+
19
+ def to_s
20
+ name
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,122 @@
1
+ module SubjModels
2
+
3
+ module TypesSupport
4
+
5
+ BASE64_FORMAT = /\A(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?\z/
6
+
7
+ module UserTypes
8
+ ADMIN = 1
9
+ LEGAL_PERSON = 2
10
+ NATURAL_PERSON = 3
11
+ DISTRIBUTOR = 4
12
+
13
+ USER_TYPES = {
14
+ 'админ' => ADMIN,
15
+ 'юридическое лицо' => LEGAL_PERSON,
16
+ 'физическое лицо' => NATURAL_PERSON,
17
+ 'поставщик' => DISTRIBUTOR
18
+ }
19
+ end
20
+
21
+ module EventTypes
22
+ WEBINAR = 1
23
+ OFFLINE = 2
24
+
25
+ EVENT_TYPES = { 'вебинар' => WEBINAR, 'оффлайн' => OFFLINE }
26
+ end
27
+
28
+ module FileTypes
29
+ PICTURE = 1
30
+ PDF = 2
31
+ VIDEO = 3
32
+
33
+ FILE_TYPES = { 'изображение' => PICTURE, 'PDF' => PDF, 'видео' => VIDEO }
34
+ end
35
+
36
+ module CardReceiveTypes
37
+ PICKUP = 1
38
+ WITH_ORDER = 2
39
+ POST_DELIVERY = 3
40
+
41
+ CARD_RECEIVE_TYPES = { 'Самовывоз' => PICKUP, 'С первым заказом' => WITH_ORDER, 'Со склада новой почты' => POST_DELIVERY }
42
+ end
43
+
44
+ module ContactTypes
45
+ ADDRESS = 1
46
+ PHONE = 2
47
+ EMAIL = 3
48
+ SKYPE = 4
49
+
50
+ CONTACT_TYPES = {
51
+ 'адрес' => ADDRESS,
52
+ 'телефон' => PHONE,
53
+ 'email' => EMAIL,
54
+ 'skype' => SKYPE
55
+ }
56
+ end
57
+
58
+ module OrderStatuses
59
+ RECEIVED = 1
60
+ PROCESSED = 2
61
+ EN_ROUTE_EXTERNAL_COURIER = 3
62
+ EN_ROUTE_INTERNAL_COURIER = 4
63
+ DELIVERED = 5
64
+
65
+ ORDER_STATUSES = {
66
+ 'принят' => RECEIVED,
67
+ 'в обработке' => PROCESSED,
68
+ 'в пути(внешний курьер)' => EN_ROUTE_EXTERNAL_COURIER,
69
+ 'внутренний курьер' => EN_ROUTE_INTERNAL_COURIER,
70
+ 'получен' => DELIVERED
71
+ }
72
+ end
73
+
74
+ module DeliveryTypes
75
+ PRIVAT_BANK_PICK_POINT = 1
76
+ PICKUP = 2
77
+ NOVAYA_POCHTA_BY_COURIER = 3
78
+ NOVAYA_POCHTA_FROM_STORAGE = 4
79
+ SUBJ_COURIER = 5
80
+
81
+ DELIVERY_TYPES = {
82
+ 'приват банк(почтомат)' => PRIVAT_BANK_PICK_POINT,
83
+ 'самовывоз из центра' => PICKUP,
84
+ 'курьер новой почты' => NOVAYA_POCHTA_BY_COURIER,
85
+ 'склад новой почты' => NOVAYA_POCHTA_FROM_STORAGE,
86
+ 'курьер SUBJ' => SUBJ_COURIER
87
+ }
88
+ end
89
+
90
+ module PaymentTypes
91
+ CARD = 1
92
+ CASH_ON_COURIER_DELIVERY = 2
93
+ BANK_TRANSFER = 3
94
+ CASH_IN_SUBJ_CENTER = 4
95
+
96
+ PAYMENT_TYPES = {
97
+ 'картой' => CARD,
98
+ 'курьеру' => CASH_ON_COURIER_DELIVERY,
99
+ 'банковским переводом' => BANK_TRANSFER,
100
+ 'наличными в центре Subj' => CASH_IN_SUBJ_CENTER
101
+ }
102
+ end
103
+
104
+ module ItemTypes
105
+ PRODUCT = 1
106
+ EVENT = 2
107
+
108
+ ITEM_TYPES = { 'товар' => PRODUCT, 'мероприятие' => EVENT }
109
+ end
110
+
111
+ module FaqTypes
112
+ FAQ = 1
113
+ FAQ_DELIVERY = 2
114
+ FAQ_PAYMENT = 3
115
+
116
+ FAQ_TYPES = { 'помощь' => FAQ, 'доставка' => FAQ_DELIVERY, 'оплата' => FAQ_PAYMENT }
117
+ end
118
+
119
+ end
120
+
121
+ end
122
+
@@ -0,0 +1,11 @@
1
+ module SubjModels
2
+
3
+ module ValuesChecker
4
+
5
+ def check_string_for_int(value)
6
+ value.to_i == 0 ? value : value.to_i
7
+ end
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,33 @@
1
+ require 'subj_models/concerns/comprising_external_id'
2
+
3
+ module SubjModels
4
+
5
+ module SpecialistActivityModule
6
+
7
+ def self.included(including_class)
8
+
9
+ including_class.class_eval do
10
+
11
+ include SubjModels::ComprisingExternalId
12
+
13
+ has_many :specialist_activity_document_types, dependent: :destroy
14
+ has_many :user_specialization_approvals, dependent: :destroy
15
+ has_many :nomenclatures
16
+
17
+ belongs_to :document_file
18
+
19
+ validates :name, presence: true
20
+
21
+ scope :unavailable_for_current_user, -> ids { where.not(id: ids) }
22
+
23
+ end
24
+
25
+ end
26
+
27
+ def to_s
28
+ name
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,29 @@
1
+ require 'subj_models/concerns/comprising_external_id'
2
+
3
+ module SubjModels
4
+
5
+ module SpecialistActivityDocumentTypeModule
6
+
7
+ def self.included(including_class)
8
+
9
+ including_class.class_eval do
10
+
11
+ include SubjModels::ComprisingExternalId
12
+
13
+ belongs_to :user_specialization
14
+
15
+ validates :name, presence: true
16
+
17
+ scope :user_specialization_id, -> (user_specialization_id) { parent_id_scope("user_specialization", user_specialization_id) }
18
+
19
+ end
20
+
21
+ end
22
+
23
+ def to_s
24
+ name
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,18 @@
1
+ require 'subj_models/concerns/comprising_external_id'
2
+
3
+ module SubjModels
4
+
5
+ module
6
+
7
+ def self.included(including_class)
8
+
9
+ including_class.class_eval do
10
+
11
+
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,131 @@
1
+ require 'digest/sha1'
2
+ require 'subj_models/services/values_checker'
3
+ require 'subj_models/services/types_support'
4
+ require 'subj_models/concerns/shared_scopes'
5
+ require 'subj_models/concerns/comprising_external_id'
6
+
7
+ module SubjModels
8
+
9
+ module UserModule
10
+
11
+ include SubjModels::TypesSupport::UserTypes
12
+ include SubjModels::TypesSupport::CardReceiveTypes
13
+ include SubjModels::ValuesChecker
14
+
15
+ module ClassMethods
16
+ def get_by_email(email)
17
+ self.where(:email => email).first
18
+ end
19
+ end
20
+
21
+ def self.included(including_class)
22
+ including_class.extend ClassMethods
23
+ including_class.class_eval do
24
+
25
+ include RademadeAdmin::UserModule
26
+ include SubjModels::ComprisingExternalId
27
+ include SubjModels::SharedScopes
28
+
29
+ enum user_type: USER_TYPES
30
+ enum card_receive_type: CARD_RECEIVE_TYPES
31
+
32
+
33
+ has_many :orders
34
+ has_many :user_specialization_approvals, dependent: :destroy
35
+ has_many :user_cards, dependent: :destroy
36
+ has_one :user_work_place, dependent: :destroy
37
+ has_one :user_card_delivery
38
+ has_many :user_delivery_addresses, dependent: :destroy
39
+ has_many :event_bookings, dependent: :destroy
40
+
41
+ has_and_belongs_to_many :user_specializations
42
+ has_and_belongs_to_many :brands
43
+
44
+ belongs_to :document_file
45
+ belongs_to :city
46
+ belongs_to :avatar, class_name: "DocumentFile"
47
+
48
+ validates :first_name, :last_name, presence: true,
49
+ on: :update,
50
+ unless: lambda { |user| user.legal_person? || user.skip_validations }
51
+ # Валидация отключена на время тестирования. После её надо разкоментировать сдесь и в контроллере.
52
+ # validates :email, uniqueness: { case_sensitive: false }, presence: true,
53
+ # on: :update,
54
+ # unless: :skip_validations
55
+ # validates :phone, uniqueness: { case_sensitive: false }, presence: true,
56
+ # on: :update,
57
+ # unless: :skip_validations
58
+ validates :user_type, inclusion: { in: user_types.keys },
59
+ on: :update,
60
+ unless: :skip_validations
61
+
62
+ attr_accessor :skip_validations
63
+
64
+ scope :external_id, -> external_id do
65
+ external_id ? where(external_id: external_id) : User.none
66
+ end
67
+
68
+ scope :internal_users, -> (condition) do
69
+ joins(:user_card_delivery).where.not(user_card_deliveries: {id: nil} ).where(external_id: nil).uniq
70
+ end
71
+
72
+ scope :updated_at_last_day, -> (date) do
73
+ where.not(external_id: nil)
74
+ .joins(:user_specialization_approvals)
75
+ .where("user_specialization_approvals.updated_at > ? OR users.updated_at > ?", date.to_datetime, date.to_datetime)
76
+ .uniq
77
+ end
78
+
79
+ end
80
+
81
+ end
82
+
83
+ def natural_person?
84
+ user_type == USER_TYPES.key(NATURAL_PERSON)
85
+ end
86
+
87
+ def legal_person?
88
+ user_type == USER_TYPES.key(LEGAL_PERSON)
89
+ end
90
+
91
+ def user_type_value
92
+ self[:user_type]
93
+ end
94
+
95
+ def self.get_by_email(email)
96
+ self.where(:email => email).first
97
+ end
98
+
99
+ def password=(password)
100
+ self.encrypted_password = encrypt_password(password) unless password.blank?
101
+ end
102
+
103
+ def password
104
+ self.encrypted_password
105
+ end
106
+
107
+ def valid_password?(password)
108
+ self.encrypted_password == encrypt_password(password)
109
+ end
110
+
111
+ def to_s
112
+ email
113
+ end
114
+
115
+ def available_nomenclature_ids
116
+ Nomenclature.joins(access_groups: [user_specializations: :users]).where("users.id" => self.id).uniq.pluck(:id)
117
+ end
118
+
119
+ def available_categories_ids
120
+ Category.joins(:nomenclatures).where("nomenclatures.id IN (?) OR nomenclatures.is_professional=FALSE", available_nomenclature_ids).uniq.pluck(:id)
121
+ end
122
+
123
+ private
124
+
125
+ def encrypt_password(password)
126
+ Digest::SHA1.hexdigest(password)
127
+ end
128
+
129
+ end
130
+
131
+ end