ecom_core 1.2.12 → 1.2.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/ecom/core/lookupable.rb +1 -2
  3. data/app/controllers/concerns/ecom/core/resource_typeable.rb +1 -1
  4. data/app/controllers/ecom/core/access_controller.rb +1 -2
  5. data/app/controllers/ecom/core/application_controller.rb +0 -1
  6. data/app/controllers/ecom/core/application_modules_controller.rb +1 -1
  7. data/app/controllers/ecom/core/menus_controller.rb +1 -1
  8. data/app/controllers/ecom/core/user_roles_controller.rb +1 -2
  9. data/app/controllers/ecom/core/users_controller.rb +1 -2
  10. data/app/models/ecom/core/attendance_sheet.rb +2 -1
  11. data/app/models/ecom/core/booked_item.rb +12 -0
  12. data/app/models/ecom/core/booking.rb +16 -0
  13. data/app/models/ecom/core/component_type.rb +1 -1
  14. data/app/models/ecom/core/crew_time.rb +1 -1
  15. data/app/models/ecom/core/equipment_item.rb +1 -0
  16. data/app/models/ecom/core/equipment_location.rb +2 -1
  17. data/app/models/ecom/core/equipment_request.rb +19 -0
  18. data/app/models/ecom/core/payment.rb +1 -1
  19. data/app/models/ecom/core/product_group.rb +9 -0
  20. data/app/models/ecom/core/project.rb +1 -1
  21. data/app/models/ecom/core/requested_item.rb +13 -0
  22. data/app/models/ecom/core/task.rb +45 -2
  23. data/app/models/ecom/core/task_resource.rb +10 -0
  24. data/app/models/ecom/core/task_template.rb +1 -1
  25. data/app/models/ecom/core/work_package.rb +12 -0
  26. data/app/models/ecom/core/work_product.rb +19 -46
  27. data/app/models/ecom/core/work_product_template.rb +2 -6
  28. data/app/serializers/ecom/core/lookup_serializer.rb +1 -1
  29. data/app/serializers/ecom/core/resource_type_serializer.rb +1 -1
  30. data/app/serializers/ecom/core/user_role_serializer.rb +1 -1
  31. data/app/services/ecom/core/menu_service.rb +2 -4
  32. data/app/services/ecom/core/token_auth_service.rb +2 -1
  33. data/db/migrate/20191119012030_create_ecom_core_task_templates.rb +2 -0
  34. data/db/migrate/20191119013236_create_ecom_core_work_product_templates.rb +14 -4
  35. data/db/migrate/20191201145848_create_ecom_core_projects.rb +2 -2
  36. data/db/migrate/20191201251015_create_ecom_core_product_groups.rb +13 -0
  37. data/db/migrate/20191202222210_create_ecom_core_work_packages.rb +17 -0
  38. data/db/migrate/20191202235434_create_ecom_core_work_products.rb +8 -13
  39. data/db/migrate/20191207103735_create_ecom_core_tasks.rb +45 -0
  40. data/db/migrate/20191210724614_create_ecom_core_task_resources.rb +18 -0
  41. data/db/migrate/20200315152143_create_ecom_core_equipment.rb +0 -1
  42. data/db/migrate/20200601104719_create_ecom_core_equipment_requests.rb +18 -0
  43. data/db/migrate/{20200602130247_create_ecom_core_booking_requests.rb → 20200602130247_create_ecom_core_requested_items.rb} +7 -12
  44. data/db/migrate/20200602830603_create_ecom_core_bookings.rb +18 -0
  45. data/db/migrate/20200603115317_create_ecom_core_booked_items.rb +23 -0
  46. data/lib/ecom/core/engine.rb +0 -1
  47. data/lib/ecom/core/version.rb +1 -1
  48. data/spec/factories/ecom/core/application_modules.rb +3 -1
  49. data/spec/factories/ecom/core/{booked_equipments.rb → booked_items.rb} +3 -3
  50. data/spec/factories/ecom/core/bookings.rb +8 -0
  51. data/spec/factories/ecom/core/companies.rb +3 -1
  52. data/spec/factories/ecom/core/equipment.rb +0 -1
  53. data/spec/factories/ecom/core/equipment_requests.rb +8 -0
  54. data/spec/factories/ecom/core/product_groups.rb +6 -0
  55. data/spec/factories/ecom/core/projects.rb +1 -1
  56. data/spec/factories/ecom/core/requested_items.rb +13 -0
  57. data/spec/factories/ecom/core/resource_types.rb +3 -1
  58. data/spec/factories/ecom/core/task_resources.rb +8 -0
  59. data/spec/factories/ecom/core/task_template_types.rb +6 -2
  60. data/spec/factories/ecom/core/task_templates.rb +5 -8
  61. data/spec/factories/ecom/core/tasks.rb +14 -3
  62. data/spec/factories/ecom/core/users.rb +1 -1
  63. data/spec/factories/ecom/core/work_packages.rb +12 -0
  64. data/spec/factories/ecom/core/work_product_templates.rb +7 -4
  65. data/spec/factories/ecom/core/work_products.rb +5 -7
  66. metadata +24 -15
  67. data/app/models/ecom/core/booked_equipment.rb +0 -19
  68. data/app/models/ecom/core/booking_request.rb +0 -26
  69. data/app/models/ecom/core/work_component.rb +0 -14
  70. data/app/models/ecom/core/work_component_template.rb +0 -11
  71. data/db/migrate/20191201134420_create_ecom_core_work_component_templates.rb +0 -25
  72. data/db/migrate/20191202103735_create_ecom_core_tasks.rb +0 -20
  73. data/db/migrate/20191206104247_create_ecom_core_work_components.rb +0 -40
  74. data/db/migrate/20200603115317_create_ecom_core_booked_equipments.rb +0 -24
  75. data/spec/factories/ecom/core/booking_requests.rb +0 -15
  76. data/spec/factories/ecom/core/work_component_templates.rb +0 -11
  77. data/spec/factories/ecom/core/work_components.rb +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53e6b8c84820dca6b1121f9f33ffdffc3f421c2a7aced743a21bac89c25b7580
4
- data.tar.gz: 557e5da2ed61cca47e0e80002469f9798d9eb96f26a8357f897beea42c4a0062
3
+ metadata.gz: d4ad578f6c6d7aece965edd8d3ad059afb16ff3f90445ba63f55c6afdc530b8f
4
+ data.tar.gz: a31af1754f7ccdc5669a1fe5747745bb8d98d0e82371db261bee62cd08d50f38
5
5
  SHA512:
6
- metadata.gz: 23b9c88cb223aa6afec885e5937089695952810e383121f9511a94b58fa5c8fe86787aad5573a61d382511d31bb643a40ba1fe0b50dafe1ea9e4ba7bbf82060f
7
- data.tar.gz: d35a3ede79f6735372668c8812e2b49f3b6653bdd577f6b95b936f2a23177c2f8467c3d307a42b07363d6d36189e0374e351305c8908bcdc20ccc3ce1453d666
6
+ metadata.gz: 7720605e3fa55dd2ff8d12358a5ece0c11f11c47647b4ac1b9be6ca35d308592d3e2ffef33c9beea298c149f5abb301f0612a194934539ab357c78699529d3cb
7
+ data.tar.gz: 4c1a5cf5b05c9a8f247fb0b457b9904b9e98bb884a0b5e8a8da38b8268ae7177f631c51ab905dc947042f7117b1f8bf1525a1b92b76d3b1423c24ee157f0af5f
@@ -29,7 +29,6 @@ module Ecom
29
29
  end
30
30
  end
31
31
 
32
-
33
32
  private
34
33
 
35
34
  def set_clazz
@@ -41,4 +40,4 @@ module Ecom
41
40
  end
42
41
  end
43
42
  end
44
- end
43
+ end
@@ -40,4 +40,4 @@ module Ecom
40
40
  end
41
41
  end
42
42
  end
43
- end
43
+ end
@@ -34,7 +34,6 @@ module Ecom
34
34
  def auth_params
35
35
  params.require(:auth).permit(:email, :password)
36
36
  end
37
-
38
37
  end
39
38
  end
40
- end
39
+ end
@@ -14,7 +14,6 @@ module Ecom
14
14
  @current_user ||= user if user
15
15
  end
16
16
 
17
-
18
17
  private
19
18
 
20
19
  def authenticate
@@ -30,4 +30,4 @@ module Ecom
30
30
  end
31
31
  end
32
32
  end
33
- end
33
+ end
@@ -7,4 +7,4 @@ module Ecom
7
7
  end
8
8
  end
9
9
  end
10
- end
10
+ end
@@ -25,7 +25,6 @@ module Ecom
25
25
  end
26
26
  end
27
27
 
28
-
29
28
  private
30
29
 
31
30
  def set_user_role
@@ -37,4 +36,4 @@ module Ecom
37
36
  end
38
37
  end
39
38
  end
40
- end
39
+ end
@@ -28,7 +28,6 @@ module Ecom
28
28
  end
29
29
  end
30
30
 
31
-
32
31
  private
33
32
 
34
33
  def set_user
@@ -40,4 +39,4 @@ module Ecom
40
39
  end
41
40
  end
42
41
  end
43
- end
42
+ end
@@ -52,7 +52,8 @@ module Ecom
52
52
  raise 'There is an open attendance sheet which needs to be submitted before creating a new one.'
53
53
  end
54
54
 
55
- AttendanceSheet.create(date: Date.today, opened_at: Time.now, status: StatusConstants::OPEN, project_id: project_id)
55
+ AttendanceSheet.create(date: Date.today, opened_at: Time.now, status: StatusConstants::OPEN,
56
+ project_id: project_id)
56
57
  end
57
58
 
58
59
  def self.submit_current(project_id)
@@ -0,0 +1,12 @@
1
+ module Ecom
2
+ module Core
3
+ class BookedItem < ApplicationRecord
4
+ belongs_to :booking
5
+ belongs_to :requested_item
6
+ belongs_to :equipment_item
7
+
8
+ validates :start_date, :end_date, presence: true
9
+ validates_with DateRangeValidator
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ module Ecom
2
+ module Core
3
+ class Booking < ApplicationRecord
4
+ APPROVED = 'Approved'.freeze
5
+ UNAPPROVED = 'Unapproved'.freeze
6
+
7
+ STATUSES = [APPROVED, UNAPPROVED].freeze
8
+
9
+ belongs_to :equipment_request
10
+ belongs_to :booked_by, class_name: 'Ecom::Core::User'
11
+ has_many :booked_items
12
+
13
+ validates :status, presence: true, inclusion: STATUSES
14
+ end
15
+ end
16
+ end
@@ -3,4 +3,4 @@ module Ecom
3
3
  class ComponentType < Lookup
4
4
  end
5
5
  end
6
- end
6
+ end
@@ -9,7 +9,7 @@ module Ecom
9
9
  TIME_RANGE = {
10
10
  MORNING => { start: Time.zone.parse('5:00 AM'), end: Time.zone.parse('9:00 AM') },
11
11
  AFTERNOON => { start: Time.zone.parse('10:00 AM'), end: Time.zone.parse('2:00 PM') },
12
- BOTH => {start: Time.zone.parse('5:00 AM'), end: Time.zone.parse('2:00 PM')}
12
+ BOTH => { start: Time.zone.parse('5:00 AM'), end: Time.zone.parse('2:00 PM') }
13
13
  }.freeze
14
14
 
15
15
  belongs_to :attendance_sheet_entry
@@ -15,6 +15,7 @@ module Ecom
15
15
  belongs_to :equipment
16
16
  belongs_to :country
17
17
  belongs_to :current_location, class_name: 'Ecom::Core::EquipmentLocation'
18
+ has_many :equipment_components
18
19
 
19
20
  validates :name, :status, :serial_number, :purchase_date, :purchase_price, presence: true
20
21
  validates :status, inclusion: EQUIPMENT_STATUSES
@@ -18,7 +18,8 @@ module Ecom
18
18
  joins(:location_type).where(
19
19
  'ecom_core_lookups.name = ? AND ecom_core_lookups.type = ?',
20
20
  LocationType::STORE,
21
- Ecom::Core::LocationType)
21
+ Ecom::Core::LocationType
22
+ )
22
23
  }
23
24
  end
24
25
  end
@@ -0,0 +1,19 @@
1
+ module Ecom
2
+ module Core
3
+ class EquipmentRequest < ApplicationRecord
4
+ DRAFT = 'Draft'.freeze
5
+ UNDER_REVIEW = 'Under Review'.freeze
6
+ APPROVED = 'Approved'.freeze
7
+ REJECTED = 'Rejected'.freeze
8
+
9
+ STATUSES = [DRAFT, UNDER_REVIEW, APPROVED, REJECTED].freeze
10
+ belongs_to :project
11
+ belongs_to :requested_by, class_name: 'Ecom::Core::User'
12
+ has_one :booking
13
+
14
+ validates :status, presence: true, inclusion: STATUSES
15
+
16
+ scope :by_status, ->(status) { where(status: status) }
17
+ end
18
+ end
19
+ end
@@ -17,4 +17,4 @@ module Ecom
17
17
  end
18
18
  end
19
19
  end
20
- end
20
+ end
@@ -0,0 +1,9 @@
1
+ module Ecom
2
+ module Core
3
+ class ProductGroup < ApplicationRecord
4
+ belongs_to :project
5
+
6
+ validates :name, presence: true, uniqueness: true
7
+ end
8
+ end
9
+ end
@@ -5,7 +5,7 @@ module Ecom
5
5
  belongs_to :contractor, class_name: 'Ecom::Core::Stakeholder'
6
6
  belongs_to :consultant, class_name: 'Ecom::Core::Stakeholder'
7
7
  belongs_to :project_manager, class_name: 'Ecom::Core::Stakeholder'
8
- belongs_to :task_template
8
+ belongs_to :task_template_type
9
9
  belongs_to :currency
10
10
  belongs_to :company
11
11
 
@@ -0,0 +1,13 @@
1
+ module Ecom
2
+ module Core
3
+ class RequestedItem < ApplicationRecord
4
+ belongs_to :equipment_request
5
+ belongs_to :equipment
6
+ belongs_to :country, optional: true
7
+
8
+ validates :start_date, :end_date, :quantity, presence: true
9
+ validates :quantity, numericality: { only_integer: true, greater_than: 0 }
10
+ validates_with DateRangeValidator
11
+ end
12
+ end
13
+ end
@@ -1,10 +1,53 @@
1
1
  module Ecom
2
2
  module Core
3
3
  class Task < ApplicationRecord
4
- belongs_to :project
4
+ include AASM
5
+
6
+ has_ancestry
7
+
8
+ belongs_to :work_product
5
9
  belongs_to :task_template
10
+ belongs_to :work_package, optional: true
11
+ belongs_to :performer, class_name: 'Ecom::Core::User', optional: true
12
+ belongs_to :approver, class_name: 'Ecom::Core::User', optional: true
13
+ belongs_to :supervisor, class_name: 'Ecom::Core::User', optional: true
14
+ belongs_to :quality_controller, class_name: 'Ecom::Core::User', optional: true
15
+
16
+ validates :code, :name, :status, :percent_completed, presence: true
17
+ validates_numericality_of :percent_completed,
18
+ only_integer: true,
19
+ greater_than_or_equal_to: 0,
20
+ less_than_or_equal_to: 100
21
+
22
+ scope :by_status, ->(status) { where(status: status) }
23
+
24
+ aasm column: 'status' do
25
+ state :new, initial: true
26
+ state :in_progress
27
+ state :submitted
28
+ state :under_review
29
+ state :completed
30
+
31
+ event :start do
32
+ transitions from: :new, to: :in_progress
33
+ end
34
+
35
+ event :submit do
36
+ transitions from: :in_progress, to: :submitted
37
+ end
38
+
39
+ event :review do
40
+ transitions from: :submitted, to: :under_review
41
+ end
42
+
43
+ event :complete do
44
+ transitions from: %i[submitted under_review], to: :completed
45
+ end
6
46
 
7
- validates :code, :name, presence: true
47
+ event :rework do
48
+ transitions from: :under_review, to: :in_progress
49
+ end
50
+ end
8
51
  end
9
52
  end
10
53
  end
@@ -0,0 +1,10 @@
1
+ module Ecom
2
+ module Core
3
+ class TaskResource < ApplicationRecord
4
+ belongs_to :task
5
+ belongs_to :resource_type
6
+
7
+ validates :amount, presence: true, numericality: { greater_than: 0 }
8
+ end
9
+ end
10
+ end
@@ -4,7 +4,7 @@ module Ecom
4
4
  has_ancestry
5
5
 
6
6
  belongs_to :task_template_type
7
- has_one :work_product_template
7
+ has_and_belongs_to_many :work_product_templates, join_table: 'ecom_core_task_templates_work_product_templates'
8
8
  has_and_belongs_to_many :resource_types, join_table: 'ecom_core_task_templates_resource_types'
9
9
 
10
10
  validates :name, :code, presence: true
@@ -0,0 +1,12 @@
1
+ module Ecom
2
+ module Core
3
+ class WorkPackage < ApplicationRecord
4
+ belongs_to :project
5
+
6
+ validates :code, :name, presence: true
7
+ validates :code, uniqueness: true
8
+
9
+ has_many :tasks
10
+ end
11
+ end
12
+ end
@@ -12,59 +12,32 @@
12
12
  # way as chart of accounts to identify parent and child relationships. Even then,
13
13
  # there needs to be a well defined coding scheme developed before using the column
14
14
  # field.
15
- #
16
15
  module Ecom
17
16
  module Core
18
17
  class WorkProduct < ApplicationRecord
19
18
  include AASM
20
19
 
21
- belongs_to :work_product_template
22
- belongs_to :task
23
- belongs_to :project
24
- belongs_to :performer, class_name: 'Ecom::Core::User'
25
- belongs_to :approver, class_name: 'Ecom::Core::User'
26
- belongs_to :supervisor, class_name: 'Ecom::Core::User'
27
- belongs_to :quality_controller, class_name: 'Ecom::Core::User'
28
-
29
- validates :name, presence: true
30
- validates :design_reference_no, uniqueness: true
31
-
32
- aasm column: 'task_status' do
33
- state :new, initial: true
34
- state :in_progress
35
- state :submitted
36
- state :under_review
37
- state :completed
38
-
39
- event :start do
40
- transitions from: :new, to: :in_progress
41
- end
42
-
43
- event :submit do
44
- transitions from: :in_progress, to: :submitted
45
- end
20
+ NEW = 'New'.freeze
21
+ UNDER_CONSTRUCTION = 'Under Construction'.freeze
22
+ COMPLETED = 'Completed'.freeze
46
23
 
47
- event :review do
48
- transitions from: :submitted, to: :under_review
49
- end
24
+ STATUSES = [NEW, UNDER_CONSTRUCTION, COMPLETED].freeze
50
25
 
51
- event :complete do
52
- transitions from: %i[submitted under_review], to: :completed
53
- end
54
-
55
- event :rework do
56
- transitions from: :under_review, to: :in_progress
57
- end
58
- end
59
-
60
- aasm column: 'assignment_status' do
61
- state :unassigned, initial: true
62
- state :assigned
63
-
64
- event :assign do
65
- transitions from: :unassigned, to: :assigned
66
- end
67
- end
26
+ belongs_to :work_product_template
27
+ belongs_to :project
28
+ belongs_to :product_group, optional: true
29
+ belongs_to :approver, class_name: 'Ecom::Core::User', optional: true
30
+ belongs_to :supervisor, class_name: 'Ecom::Core::User', optional: true
31
+ belongs_to :quality_controller, class_name: 'Ecom::Core::User', optional: true
32
+ has_many :tasks
33
+
34
+ validates :name, :design_reference_no, :status, :percent_completed, presence: true
35
+ validates :design_reference_no, uniqueness: { scope: :project_id }
36
+ validates :status, inclusion: STATUSES
37
+ validates_numericality_of :percent_completed,
38
+ only_integer: true,
39
+ greater_than_or_equal_to: 0,
40
+ less_than_or_equal_to: 100
68
41
  end
69
42
  end
70
43
  end
@@ -2,13 +2,9 @@ module Ecom
2
2
  module Core
3
3
  class WorkProductTemplate < ApplicationRecord
4
4
  validates :code, :name, presence: true, uniqueness: true
5
- belongs_to :task_template
5
+ belongs_to :task_template_type
6
+ has_and_belongs_to_many :task_templates
6
7
  has_many :product_types
7
-
8
- scope :filtered_by_template_type, lambda { |id|
9
- joins(:task_template).where('ecom_core_task_templates.task_template_type_id = ?', id)
10
- .order(:code)
11
- }
12
8
  end
13
9
  end
14
10
  end
@@ -4,4 +4,4 @@ module Ecom
4
4
  attributes :id, :name, :type
5
5
  end
6
6
  end
7
- end
7
+ end
@@ -4,4 +4,4 @@ module Ecom
4
4
  attributes :id, :code, :name, :base_unit, :type
5
5
  end
6
6
  end
7
- end
7
+ end
@@ -4,4 +4,4 @@ module Ecom
4
4
  attributes :id, :name
5
5
  end
6
6
  end
7
- end
7
+ end
@@ -7,16 +7,14 @@ module Ecom
7
7
  INNER JOIN ecom_core_menus_user_roles MUR ON MUR.menu_id = ecom_core_menus.id
8
8
  INNER JOIN ecom_core_user_roles UR ON MUR.user_role_id = UR.id
9
9
  SQL
10
- menu = Menu.joins(join_sql).where('UR.id IN (?)', role_ids).distinct
10
+ menu = Menu.joins(join_sql).where('UR.id IN (?)', role_ids).order(:id).distinct
11
11
  menu_list = menu.select { |m| m.parent.nil? }.each_with_object([]) do |item, list|
12
12
  list << { id: item.id, text: item.label, iconCss: item.icon, items: [] }
13
13
  end
14
14
 
15
15
  menu_list.each do |ml|
16
16
  ml[:items] = menu.reject { |m| m.parent.nil? }.each_with_object([]) do |item, list|
17
- if item.parent_id == ml[:id]
18
- list << { id: item.id, text: item.label, iconCss: item.icon, url: item.route }
19
- end
17
+ list << { id: item.id, text: item.label, iconCss: item.icon, url: item.route } if item.parent_id == ml[:id]
20
18
  end
21
19
  end
22
20
  { success: true, data: menu_list }