mobilart_models 1.2.14

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 (98) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +37 -0
  5. data/app/models/bundle.rb +39 -0
  6. data/app/models/chosen_deck.rb +76 -0
  7. data/app/models/chosen_furniture.rb +114 -0
  8. data/app/models/chosen_item.rb +187 -0
  9. data/app/models/chosen_room.rb +114 -0
  10. data/app/models/commission.rb +58 -0
  11. data/app/models/deck.rb +25 -0
  12. data/app/models/furniture.rb +45 -0
  13. data/app/models/furniture_item.rb +20 -0
  14. data/app/models/item.rb +25 -0
  15. data/app/models/room.rb +22 -0
  16. data/app/models/timetable.rb +171 -0
  17. data/app/models/workflow.rb +173 -0
  18. data/config/initializers/mobilart_models_after_initialize.rb +7 -0
  19. data/config/locales/en.activerecord.yml +36 -0
  20. data/config/locales/en.yml +38 -0
  21. data/config/locales/it.activerecord.yml +157 -0
  22. data/config/locales/it.yml +33 -0
  23. data/config/routes.rb +2 -0
  24. data/db/migrate/20150825174853_create_items.rb +13 -0
  25. data/db/migrate/20150825175219_create_commissions.rb +14 -0
  26. data/db/migrate/20150825175836_create_decks.rb +13 -0
  27. data/db/migrate/20150825175853_create_rooms.rb +13 -0
  28. data/db/migrate/20150825175952_create_furnitures.rb +13 -0
  29. data/db/migrate/20150825180027_create_furniture_items.rb +10 -0
  30. data/db/migrate/20150825180510_create_bundles.rb +14 -0
  31. data/db/migrate/20150827084511_create_chosen_decks.rb +12 -0
  32. data/db/migrate/20150827084626_create_chosen_rooms.rb +12 -0
  33. data/db/migrate/20150827084745_create_chosen_furnitures.rb +12 -0
  34. data/db/migrate/20150827184845_create_chosen_items.rb +12 -0
  35. data/db/migrate/20150828180910_create_workflows.rb +13 -0
  36. data/db/migrate/20150903152839_create_timetables.rb +17 -0
  37. data/db/migrate/20151201145832_add_external_to_user.rb +5 -0
  38. data/db/migrate/20151202155259_add_external_to_workflow.rb +6 -0
  39. data/db/migrate/20151218145139_add_closed_to_commission.rb +5 -0
  40. data/db/migrate/20151221083612_add_checked_to_chosen_item.rb +5 -0
  41. data/db/migrate/20151221100829_add_bundle_to_chosen_item.rb +5 -0
  42. data/db/migrate/20151221100914_add_checked_in_bundle_to_chosen_item.rb +5 -0
  43. data/db/migrate/20160212155936_remove_chosen_furniture_from_timetable.rb +5 -0
  44. data/db/migrate/20160212160511_add_chosen_item_to_timetable.rb +5 -0
  45. data/db/migrate/20160331101901_add_code_to_user.rb +6 -0
  46. data/db/migrate/20160519144818_save_items_to_make_name_code_the_same.rb +7 -0
  47. data/db/migrate/20160622132452_add_barcode_to_chosen_item.rb +154 -0
  48. data/db/migrate/20160629135548_edit_index_for_furniture.rb +6 -0
  49. data/db/migrate/20170723195528_remove_barcode_from_chosen_items.rb +5 -0
  50. data/lib/mobilart_models.rb +14 -0
  51. data/lib/mobilart_models/engine.rb +12 -0
  52. data/lib/mobilart_models/version.rb +3 -0
  53. data/lib/mobilart_models_abilities.rb +53 -0
  54. data/lib/mobilart_roles.rb +6 -0
  55. data/lib/rails_admin_print_jobs_concern.rb +13 -0
  56. data/lib/rails_admin_printers_concern.rb +13 -0
  57. data/lib/rails_admin_user_main_concern.rb +11 -0
  58. data/lib/tasks/mobilart_models_tasks.rake +4 -0
  59. data/lib/user_model_concerns.rb +13 -0
  60. data/test/dummy/README.rdoc +28 -0
  61. data/test/dummy/Rakefile +6 -0
  62. data/test/dummy/app/assets/javascripts/application.js +13 -0
  63. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  64. data/test/dummy/app/controllers/application_controller.rb +5 -0
  65. data/test/dummy/app/helpers/application_helper.rb +2 -0
  66. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  67. data/test/dummy/bin/bundle +3 -0
  68. data/test/dummy/bin/rails +4 -0
  69. data/test/dummy/bin/rake +4 -0
  70. data/test/dummy/bin/setup +29 -0
  71. data/test/dummy/config.ru +4 -0
  72. data/test/dummy/config/application.rb +25 -0
  73. data/test/dummy/config/boot.rb +5 -0
  74. data/test/dummy/config/database.yml +25 -0
  75. data/test/dummy/config/environment.rb +5 -0
  76. data/test/dummy/config/environments/development.rb +41 -0
  77. data/test/dummy/config/environments/production.rb +79 -0
  78. data/test/dummy/config/environments/test.rb +42 -0
  79. data/test/dummy/config/initializers/assets.rb +11 -0
  80. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  81. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  82. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  83. data/test/dummy/config/initializers/inflections.rb +16 -0
  84. data/test/dummy/config/initializers/mime_types.rb +4 -0
  85. data/test/dummy/config/initializers/session_store.rb +3 -0
  86. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  87. data/test/dummy/config/locales/en.yml +23 -0
  88. data/test/dummy/config/routes.rb +56 -0
  89. data/test/dummy/config/secrets.yml +22 -0
  90. data/test/dummy/log/development.log +1 -0
  91. data/test/dummy/public/404.html +67 -0
  92. data/test/dummy/public/422.html +67 -0
  93. data/test/dummy/public/500.html +66 -0
  94. data/test/dummy/public/favicon.ico +0 -0
  95. data/test/integration/navigation_test.rb +8 -0
  96. data/test/mobilart_models_test.rb +7 -0
  97. data/test/test_helper.rb +20 -0
  98. metadata +206 -0
@@ -0,0 +1,114 @@
1
+ class ChosenRoom < ApplicationRecord
2
+ belongs_to :chosen_deck, inverse_of: :chosen_rooms
3
+ belongs_to :room, inverse_of: :chosen_rooms
4
+
5
+ has_many :chosen_furnitures, inverse_of: :chosen_room, dependent: :destroy
6
+ has_many :furnitures, through: :chosen_furnitures, inverse_of: :chosen_rooms
7
+ accepts_nested_attributes_for :chosen_furnitures, allow_destroy: true
8
+
9
+ validates :room, presence: true
10
+ validates :chosen_deck, presence: true
11
+
12
+ before_create :increment_code
13
+ # Items: I need a method to obtain all the items in the
14
+ # current selected Commission
15
+ def records_for_print id
16
+ # TODO: move away from this pseudo code as soon as Bancolini tells me
17
+ # what Mobilart wants
18
+ # chosen_item.name
19
+ # chosen_item.barcode
20
+ # chosen_item.timetables.last.status
21
+ # chosen_item.timetables.last.job_type
22
+ ChosenItem.joins(chosen_furniture: :chosen_room).where(chosen_rooms: {id: id}).distinct
23
+ end
24
+
25
+ def list_associated_items
26
+ true
27
+ end
28
+
29
+ def commission
30
+ chosen_deck.commission.code rescue "-"
31
+ end
32
+ def deck
33
+ chosen_deck.deck.name rescue "-"
34
+ end
35
+
36
+ def display_name
37
+ "#{room.name} nel ponte #{deck} della commessa #{commission} contenente #{chosen_furnitures.count} mobili"
38
+ end
39
+
40
+ default_scope {joins({chosen_deck: [:deck, :commission]})}
41
+
42
+ rails_admin do
43
+ navigation_label I18n.t(:operative_section)
44
+ navigation_icon 'fa fa-home'
45
+ parent Commission
46
+ weight 6
47
+
48
+ field :commission do
49
+ searchable "commissions.code"
50
+ sortable "commissions.code"
51
+ filterable true
52
+ read_only true
53
+ visible do
54
+ bindings[:controller].params["model_name"] == "chosen_room"
55
+ end
56
+ end
57
+ field :deck do
58
+ searchable "decks.name"
59
+ sortable "decks.name"
60
+ filterable true
61
+ read_only true
62
+ visible do
63
+ bindings[:controller].params["model_name"] == "chosen_room"
64
+ end
65
+ end
66
+ field :room
67
+ list do
68
+ field :furnitures
69
+ end
70
+ show do
71
+ field :chosen_furnitures
72
+ end
73
+
74
+ edit do
75
+ # Differenziare fra quando sono nella configurazione stanze o ponti
76
+ field :room do
77
+ visible do
78
+ bindings[:controller].params["model_name"] == "chosen_deck"
79
+ end
80
+ end
81
+ field :chosen_furnitures do
82
+ visible do
83
+ bindings[:controller].params["model_name"] == "chosen_room"
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ amoeba do
90
+ enable
91
+ include_association :chosen_furnitures
92
+ end
93
+
94
+ def readable_barcode
95
+ "#{chosen_deck.readable_barcode rescue "" }|#{room.code}|#{code}"
96
+ end
97
+
98
+ def barcode
99
+ "#{chosen_deck.barcode rescue "" }#{room.code}#{code}"
100
+ end
101
+
102
+ def name
103
+ # "#{room.name rescue nil} (#{readable_barcode rescue nil})"
104
+ room.name rescue "Undefined"
105
+ end
106
+
107
+ private
108
+
109
+ def increment_code
110
+ max_code = ChosenRoom.order("chosen_rooms.code DESC").pluck(:code).compact.map(&:to_i).max.to_i
111
+ # Rails.logger.debug "MAX CODE IS:#{max_code} Adding 1: #{(max_code + 1)}"
112
+ self.code = (max_code + 1)
113
+ end
114
+ end
@@ -0,0 +1,58 @@
1
+ class Commission < ApplicationRecord
2
+ has_many :bundles, inverse_of: :commission, dependent: :destroy
3
+ has_many :chosen_decks, inverse_of: :commission, dependent: :destroy
4
+ has_many :decks, through: :chosen_decks, inverse_of: :commissions
5
+ #accepts_nested_attributes_for :chosen_decks, allow_destroy: true
6
+
7
+ # validates :name, uniqueness: { case_sensitive: false }, presence: true
8
+ validates :code, uniqueness: { case_sensitive: false }, presence: true #, length: { is: 5 }
9
+ # validates :issued_on, uniqueness: { case_sensitive: false }, presence: true
10
+
11
+ before_save do
12
+ self.name = code
13
+ end
14
+
15
+ def self.is_opened
16
+ where closed: false
17
+ end
18
+
19
+ def self.is_closed
20
+ where closed: true
21
+ end
22
+ # Items: I need a method to obtain all the items in the
23
+ # current selected Commission
24
+ def records_for_print id
25
+ # TODO: move away from this pseudo code as soon as Bancolini tells me
26
+ # what Mobilart wants
27
+ # chosen_item.name
28
+ # chosen_item.barcode
29
+ # chosen_item.timetables.last.status
30
+ # chosen_item.timetables.last.job_type
31
+ ChosenItem.joins(chosen_furniture: {chosen_room: {chosen_deck: :commission}}).where(commissions: {id: id}).distinct
32
+ end
33
+
34
+ def list_associated_items
35
+ true
36
+ end
37
+
38
+ rails_admin do
39
+ navigation_label I18n.t(:operative_section)
40
+ navigation_icon 'fa fa-anchor'
41
+ weight 4
42
+
43
+ field :code
44
+ field :description
45
+ field :closed, :toggle
46
+ field :decks
47
+ list do
48
+ scopes [:is_opened, :is_closed, nil]
49
+ field :updated_at
50
+ end
51
+ end
52
+
53
+ amoeba do
54
+ enable
55
+ include_association :chosen_decks
56
+ prepend :code => "Copia di "
57
+ end
58
+ end
@@ -0,0 +1,25 @@
1
+ class Deck < ApplicationRecord
2
+ has_many :chosen_decks, inverse_of: :deck
3
+ has_many :commissions, through: :chosen_decks, inverse_of: :decks, dependent: :destroy
4
+
5
+ validates :name, uniqueness: { case_sensitive: false }, presence: true
6
+ #validates :code, uniqueness: { case_sensitive: false }, presence: true
7
+
8
+ before_save do
9
+ self.code = name
10
+ end
11
+
12
+ rails_admin do
13
+ navigation_label I18n.t(:main_records)
14
+ navigation_icon 'fa fa-align-center'
15
+ weight 0
16
+
17
+ field :name
18
+ field :description
19
+
20
+ list do
21
+ scopes [:all, :starts_with_a, :starts_with_b, :starts_with_c, :starts_with_d, :starts_with_e, :starts_with_f, :starts_with_g, :starts_with_h, :starts_with_i, :starts_with_j, :starts_with_k, :starts_with_l, :starts_with_m, :starts_with_n, :starts_with_o, :starts_with_p, :starts_with_q, :starts_with_r, :starts_with_s, :starts_with_t, :starts_with_u, :starts_with_v, :starts_with_w, :starts_with_x, :starts_with_y, :starts_with_z ]
22
+ field :updated_at
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,45 @@
1
+ class Furniture < ApplicationRecord
2
+ has_many :chosen_furnitures, inverse_of: :furniture
3
+ has_many :chosen_rooms, through: :chosen_furnitures, inverse_of: :furnitures, dependent: :destroy
4
+
5
+ has_many :furniture_items, inverse_of: :furniture
6
+ has_many :items, through: :furniture_items, inverse_of: :furnitures, dependent: :destroy
7
+ # accepts_nested_attributes_for :furniture_items, allow_destroy: true
8
+
9
+ validates :name, uniqueness: { case_sensitive: false, scope: :description }, presence: true
10
+ validates :code, uniqueness: { case_sensitive: false }, presence: true
11
+
12
+ after_save {
13
+ chosen_furnitures.each do |cr|
14
+ Rails.logger.debug "SAVING: #{cr.inspect}"
15
+ cr.save
16
+ end
17
+ }
18
+
19
+ amoeba do
20
+ enable
21
+ include_association :furniture_items
22
+ prepend :name => "Copia di "
23
+ prepend :code => "Copia di "
24
+ end
25
+
26
+ def display_name
27
+ "#{name} (#{description})"
28
+ end
29
+
30
+ rails_admin do
31
+ navigation_label I18n.t(:main_records)
32
+ navigation_icon 'fa fa-cubes'
33
+ weight 2
34
+
35
+ field :name
36
+ field :code
37
+ field :description
38
+ field :items
39
+
40
+ list do
41
+ scopes [:all, :starts_with_a, :starts_with_b, :starts_with_c, :starts_with_d, :starts_with_e, :starts_with_f, :starts_with_g, :starts_with_h, :starts_with_i, :starts_with_j, :starts_with_k, :starts_with_l, :starts_with_m, :starts_with_n, :starts_with_o, :starts_with_p, :starts_with_q, :starts_with_r, :starts_with_s, :starts_with_t, :starts_with_u, :starts_with_v, :starts_with_w, :starts_with_x, :starts_with_y, :starts_with_z ]
42
+ field :updated_at
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,20 @@
1
+ class FurnitureItem < ApplicationRecord
2
+ belongs_to :furniture, inverse_of: :furniture_items
3
+ belongs_to :item, inverse_of: :furniture_items
4
+
5
+ has_many :chosen_items, inverse_of: :furniture_item, :dependent => :destroy
6
+ has_many :chosen_furnitures, through: :chosen_items, inverse_of: :furniture_items
7
+
8
+ def name
9
+ item.name rescue "Undefined"
10
+ end
11
+
12
+ rails_admin do
13
+ visible false
14
+
15
+ # Utile se lo usavamo nella configurazione della anagrafic amobili, quando sembrava che
16
+ # in mobilart volessero la possibilità di inserire diverse volte lo stesso
17
+ # item in un mobile
18
+ field :item
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ class Item < ApplicationRecord
2
+ has_many :furniture_items, inverse_of: :item
3
+ has_many :furnitures, through: :furniture_items, inverse_of: :items, dependent: :destroy
4
+
5
+ validates :name, uniqueness: { case_sensitive: false }, presence: true
6
+ # validates :code, uniqueness: { case_sensitive: false }, presence: true
7
+
8
+ before_save do
9
+ self.code = name
10
+ end
11
+
12
+ rails_admin do
13
+ navigation_label I18n.t(:main_records)
14
+ navigation_icon 'fa fa-cube'
15
+ weight 3
16
+
17
+ field :name
18
+ field :description
19
+
20
+ list do
21
+ scopes [:all, :starts_with_a, :starts_with_b, :starts_with_c, :starts_with_d, :starts_with_e, :starts_with_f, :starts_with_g, :starts_with_h, :starts_with_i, :starts_with_j, :starts_with_k, :starts_with_l, :starts_with_m, :starts_with_n, :starts_with_o, :starts_with_p, :starts_with_q, :starts_with_r, :starts_with_s, :starts_with_t, :starts_with_u, :starts_with_v, :starts_with_w, :starts_with_x, :starts_with_y, :starts_with_z ]
22
+ field :updated_at
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ class Room < ApplicationRecord
2
+ has_many :chosen_rooms, inverse_of: :room
3
+ has_many :chosen_decks, through: :chosen_rooms, inverse_of: :rooms, dependent: :destroy
4
+
5
+ validates :name, uniqueness: { case_sensitive: false }, presence: true
6
+ validates :code, uniqueness: { case_sensitive: false }, presence: true
7
+
8
+ rails_admin do
9
+ navigation_label I18n.t(:main_records)
10
+ navigation_icon 'fa fa-th-large'
11
+ weight 1
12
+
13
+ field :name
14
+ field :code
15
+ field :description
16
+
17
+ list do
18
+ scopes [:all, :starts_with_a, :starts_with_b, :starts_with_c, :starts_with_d, :starts_with_e, :starts_with_f, :starts_with_g, :starts_with_h, :starts_with_i, :starts_with_j, :starts_with_k, :starts_with_l, :starts_with_m, :starts_with_n, :starts_with_o, :starts_with_p, :starts_with_q, :starts_with_r, :starts_with_s, :starts_with_t, :starts_with_u, :starts_with_v, :starts_with_w, :starts_with_x, :starts_with_y, :starts_with_z ]
19
+ field :updated_at
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,171 @@
1
+ class Timetable < ApplicationRecord
2
+ belongs_to :user, inverse_of: :timetables
3
+ belongs_to :chosen_item, inverse_of: :timetables
4
+
5
+ validates :user_id, presence: true
6
+ validates :chosen_item_id, presence: true
7
+ validates :job_type, presence: true
8
+ validates :status, presence: true
9
+ validates :hours, presence: true, numericality: { only_integer: true }
10
+ validates :minutes, presence: true, numericality: { only_integer: true }
11
+
12
+ def self.last_two_days
13
+ where created_at: (Date.today - 2.days)..Time.now
14
+ end
15
+
16
+ def status_enum
17
+ # Array holding all the roles
18
+ status = %i[
19
+ suspended
20
+ finished
21
+ ]
22
+ # Do not EDIT below this line
23
+ status.map {|s| I18n.t("status.#{s.to_sym}")}
24
+ end
25
+
26
+ def job_type_enum
27
+ # Array holding all the roles
28
+ statuses = %i[
29
+ internal_labour
30
+ external_labour
31
+ internal_paint
32
+ external_paint
33
+ upholstery
34
+ storage
35
+ construction_yard
36
+ ]
37
+ # Do not EDIT below this line
38
+ statuses.map {|s| I18n.t("statuses.#{s.to_sym}")}
39
+ end
40
+
41
+ def commission
42
+ chosen_item.chosen_furniture.chosen_room.chosen_deck.commission.code rescue ""
43
+ end
44
+ def deck
45
+ chosen_item.chosen_furniture.chosen_room.chosen_deck.deck.name rescue ""
46
+ end
47
+ def room
48
+ chosen_item.chosen_furniture.chosen_room.room.name rescue ""
49
+ end
50
+ def furniture
51
+ chosen_item.chosen_furniture.furniture.name rescue ""
52
+ end
53
+ def item
54
+ chosen_item.furniture_item.item.name rescue ""
55
+ end
56
+
57
+ def display_name
58
+ "#{user.username} (#{hours}:#{minutes}): #{[commission, deck, room, furniture, item].compact.join(" - ")}" rescue ""
59
+ end
60
+
61
+ rails_admin do
62
+ navigation_label I18n.t("admin.tools.label")
63
+ navigation_icon 'fa fa-calendar'
64
+ weight 13
65
+
66
+ export do
67
+ field :user, :string do
68
+ export_value do
69
+ value.email if value #value is an instance of Teacher
70
+ end
71
+ end
72
+ field :commission
73
+ field :deck
74
+ field :room
75
+ field :furniture
76
+ field :item
77
+ field :chosen_item, :string do
78
+ label do
79
+ "Codice a Barre"
80
+ end
81
+ export_value do
82
+ value.barcode if value #value is an instance of ChosenItem
83
+ end
84
+ end
85
+ field :job_type
86
+ field :status
87
+ field :hours do
88
+ label do
89
+ "Ore Lavorate"
90
+ end
91
+ end
92
+ field :minutes do
93
+ label do
94
+ "Minuti Lavorati"
95
+ end
96
+ end
97
+ end
98
+
99
+ list do
100
+ scopes [:last_two_days, nil]
101
+ field :user do
102
+ searchable [{User => :username}]
103
+ visible do
104
+ !bindings[:view].current_user.has_role?(:workers)
105
+ end
106
+ end
107
+
108
+ field :chosen_item
109
+ field :job_type
110
+ field :status
111
+ field :hours
112
+ field :minutes
113
+ field :created_at
114
+ end
115
+
116
+ edit do
117
+ field :chosen_item
118
+ field :job_type
119
+ field :status
120
+ field :hours
121
+ field :minutes
122
+ field :notes
123
+ # Preset user to current user
124
+ field :user do
125
+ visible do
126
+ # If it's a worker just show the user_id part, and hide the !user_id
127
+ bindings[:view].current_user.admin?
128
+ end
129
+ end
130
+ field :user_id, :hidden do
131
+ label "&nbsp;".html_safe
132
+ help "&nbsp;".html_safe
133
+ visible do
134
+ # If it's a worker just show the user_id part, and hide the !user_id
135
+ bindings[:view].current_user.has_role?(:workers) && !bindings[:view].current_user.admin?
136
+ end
137
+ # TODO: Migliorare questo dato per evitare che venga sovrascritto l'autore originale in edit successivi da parte di altri
138
+ default_value do
139
+ bindings[:view]._current_user.id
140
+ end
141
+ end
142
+ end
143
+ create do
144
+ field :chosen_item
145
+ field :job_type
146
+ field :status
147
+ field :hours
148
+ field :minutes
149
+ field :notes
150
+ # Preset user to current user
151
+ field :user do
152
+ visible do
153
+ # If it's a worker just show the user_id part, and hide the !user_id
154
+ bindings[:view].current_user.admin?
155
+ end
156
+ end
157
+ field :user_id, :hidden do
158
+ label "&nbsp;".html_safe
159
+ help "&nbsp;".html_safe
160
+ visible do
161
+ # If it's a worker just show the user_id part, and hide the !user_id
162
+ bindings[:view].current_user.has_role?(:workers) && !bindings[:view].current_user.admin?
163
+ end
164
+ # TODO: Migliorare questo dato per evitare che venga sovrascritto l'autore originale in edit successivi da parte di altri
165
+ default_value do
166
+ bindings[:view]._current_user.id
167
+ end
168
+ end
169
+ end
170
+ end
171
+ end