jobshop 0.0.167 → 0.0.179
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/Rakefile +2 -1
- data/app/assets/javascripts/application.js +1 -0
- data/app/controllers/jobshop/application_controller.rb +3 -1
- data/app/controllers/jobshop/dashboards_controller.rb +11 -0
- data/app/controllers/jobshop/departments_controller.rb +52 -0
- data/app/controllers/jobshop/employees_controller.rb +77 -0
- data/app/controllers/jobshop/organizations_controller.rb +29 -0
- data/app/controllers/jobshop/rfqs_controller.rb +49 -0
- data/app/controllers/jobshop/roles_controller.rb +52 -0
- data/app/helpers/jobshop/application_helper.rb +10 -0
- data/app/listeners/jobshop/assignment_listener.rb +13 -0
- data/app/mailers/jobshop/rfq_responder_mailer.rb +1 -1
- data/app/models/jobshop/auditing.rb +20 -0
- data/app/models/jobshop/collection.rb +2 -7
- data/app/models/jobshop/customer.rb +6 -17
- data/app/models/jobshop/customer/category.rb +2 -8
- data/app/models/jobshop/customer/contact.rb +3 -8
- data/app/models/jobshop/department.rb +10 -0
- data/app/models/jobshop/department/assignment.rb +15 -0
- data/app/models/jobshop/employee.rb +13 -6
- data/app/models/jobshop/employment.rb +8 -8
- data/app/models/jobshop/inspection.rb +1 -1
- data/app/models/jobshop/inspection/boolean_criterion.rb +13 -17
- data/app/models/jobshop/inspection/criterion.rb +9 -10
- data/app/models/jobshop/inspection/deviation_criterion.rb +10 -12
- data/app/models/jobshop/inspection/limit_criterion.rb +12 -10
- data/app/models/jobshop/inspection/report.rb +22 -34
- data/app/models/jobshop/mailman.rb +2 -4
- data/app/models/jobshop/order.rb +3 -27
- data/app/models/jobshop/order_line.rb +4 -10
- data/app/models/jobshop/organization.rb +8 -15
- data/app/models/jobshop/organization_state.rb +10 -0
- data/app/models/jobshop/place.rb +3 -8
- data/app/models/jobshop/product.rb +4 -7
- data/app/models/jobshop/rfq.rb +32 -14
- data/app/models/jobshop/rfq/line.rb +28 -0
- data/app/models/jobshop/rfq/line/assignment.rb +25 -0
- data/app/models/jobshop/rfq/line/quantity.rb +23 -0
- data/app/models/jobshop/role.rb +3 -9
- data/app/models/jobshop/role_assignment.rb +10 -4
- data/app/models/jobshop/routing_process.rb +4 -10
- data/app/models/jobshop/routing_step.rb +3 -5
- data/app/models/jobshop/thing.rb +3 -8
- data/app/models/jobshop/user.rb +24 -11
- data/app/views/jobshop/dashboards/show.html.haml +35 -0
- data/app/views/jobshop/departments/_form.html.haml +12 -0
- data/app/views/jobshop/departments/edit.html.haml +7 -0
- data/app/views/jobshop/departments/index.html.haml +17 -0
- data/app/views/jobshop/departments/new.html.haml +5 -0
- data/app/views/jobshop/departments/show.html.haml +15 -0
- data/app/views/jobshop/employees/_form.html.haml +46 -0
- data/app/views/jobshop/employees/edit.html.haml +1 -0
- data/app/views/jobshop/employees/index.html.haml +12 -0
- data/app/views/jobshop/employees/new.html.haml +1 -0
- data/app/views/jobshop/employees/show.html.haml +16 -0
- data/app/views/jobshop/organizations/_form.html.haml +10 -0
- data/app/views/jobshop/organizations/edit.html.haml +7 -0
- data/app/views/jobshop/organizations/index.html.haml +19 -0
- data/app/views/jobshop/organizations/new.html.haml +5 -0
- data/app/views/jobshop/organizations/show.html.haml +16 -0
- data/app/views/jobshop/rfqs/_form.html.haml +60 -0
- data/app/views/jobshop/rfqs/edit.html.haml +4 -0
- data/app/views/jobshop/rfqs/index.html.haml +2 -0
- data/app/views/jobshop/roles/_form.html.haml +11 -0
- data/app/views/jobshop/roles/edit.html.haml +7 -0
- data/app/views/jobshop/roles/index.html.haml +21 -0
- data/app/views/jobshop/roles/new.html.haml +5 -0
- data/app/views/jobshop/roles/show.html.haml +3 -0
- data/app/views/layouts/jobshop/application.html.haml +50 -2
- data/config/initializers/devise.rb +2 -2
- data/config/routes.rb +18 -0
- data/db/migrate/20170311194758_initialize_jobshop.rb +4 -39
- data/db/migrate/20171216021339_create_organizations.rb +3 -8
- data/db/migrate/20171216021350_create_users.rb +28 -0
- data/db/migrate/20171216021400_create_employees.rb +27 -9
- data/db/migrate/20171216021853_create_customers.rb +29 -14
- data/db/migrate/20171216022020_create_places.rb +3 -4
- data/db/migrate/20171216022135_create_products.rb +4 -4
- data/db/migrate/20171216022605_create_orders.rb +27 -13
- data/db/migrate/20171216023018_create_roles.rb +30 -27
- data/db/migrate/20171216035357_create_things.rb +26 -23
- data/db/migrate/20171219022118_create_routing_processes.rb +28 -33
- data/db/migrate/20180107203241_create_inspections.rb +48 -115
- data/db/migrate/20181117023949_create_rfqs.rb +74 -15
- data/db/migrate/20181118014603_create_mailmen.rb +5 -6
- data/db/migrate/20190309163306_create_departments.rb +38 -0
- data/db/migrate/support/temporal_tables.sql +210 -0
- data/db/seeds.rb +92 -64
- data/exe/jobshop +1 -0
- data/lib/generators/jobshop/app/app_generator.rb +13 -3
- data/lib/generators/jobshop/app/templates/Procfile.tt +1 -1
- data/lib/generators/jobshop/app/templates/config/databases/postgresql.yml.tt +24 -0
- data/lib/generators/jobshop/app/templates/config/puma.rb.tt +44 -0
- data/lib/generators/jobshop/canary/canary_generator.rb +21 -9
- data/lib/generators/jobshop/dev_cert/dev_cert_generator.rb +124 -0
- data/lib/jobshop.rb +1 -1
- data/lib/jobshop/cli.rb +3 -3
- data/lib/jobshop/cli/app_generator.rb +15 -10
- data/lib/jobshop/cli/application.rb +7 -7
- data/lib/jobshop/cli/base.rb +65 -0
- data/lib/jobshop/cli/canary.rb +120 -22
- data/lib/jobshop/configuration.rb +1 -1
- data/lib/jobshop/engine.rb +8 -4
- data/lib/jobshop/helpers/migration.rb +27 -66
- data/lib/jobshop/mailroom/base_handler.rb +1 -1
- data/lib/jobshop/mailroom/null_handler.rb +1 -1
- data/lib/jobshop/mailroom/postmaster.rb +1 -1
- data/lib/jobshop/mailroom/rfq_handler.rb +1 -1
- data/lib/jobshop/version.rb +2 -2
- data/lib/tasks/jobshop_tasks.rake +15 -1
- metadata +114 -61
- data/app/controllers/jobshop/organizations/lookups_controller.rb +0 -18
- data/app/models/jobshop/employment_version.rb +0 -10
- data/app/models/jobshop/inspection/result.rb +0 -46
- data/app/models/jobshop/inspection/tuple.rb +0 -17
- data/app/models/jobshop/rfq_line.rb +0 -12
- data/db/migrate/20171216021554_create_people.rb +0 -43
- data/lib/generators/jobshop/app/templates/config/database.yml.tt +0 -19
@@ -1,16 +1,10 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Jobshop
|
4
4
|
class Customer::Category < ApplicationRecord
|
5
|
-
self.primary_keys = %i[ organization_id category_id ]
|
6
|
-
|
7
|
-
after_initialize { self.category_id ||= SecureRandom.uuid if new_record? }
|
8
|
-
after_create { reload }
|
9
|
-
|
10
5
|
belongs_to :organization, -> { readonly }, inverse_of: :customer_categories
|
11
6
|
|
12
|
-
has_many :customers, inverse_of: :category
|
13
|
-
foreign_key: %i[ organization_id category_id ]
|
7
|
+
has_many :customers, inverse_of: :category
|
14
8
|
|
15
9
|
validates :name, uniqueness: {
|
16
10
|
case_insensitive: true, scope: :organization_id
|
@@ -1,15 +1,10 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Jobshop # :nodoc:
|
4
4
|
class Customer::Contact < ApplicationRecord
|
5
|
-
self.primary_keys = %i[ organization_id customer_id contact_id ]
|
6
|
-
|
7
|
-
after_initialize { self.contact_id ||= SecureRandom.uuid if new_record? }
|
8
|
-
after_create { reload }
|
9
|
-
|
10
5
|
belongs_to :organization, inverse_of: :customer_contacts
|
11
|
-
|
12
|
-
|
6
|
+
|
7
|
+
belongs_to :customer, inverse_of: :contacts
|
13
8
|
|
14
9
|
validates :email,
|
15
10
|
presence: { if: :email_required? },
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Jobshop
|
2
|
+
class Department < ApplicationRecord
|
3
|
+
belongs_to :organization, -> { readonly }, inverse_of: :departments
|
4
|
+
|
5
|
+
has_many :assignments, inverse_of: :department,
|
6
|
+
dependent: :restrict_with_exception
|
7
|
+
|
8
|
+
has_many :employees, through: :assignments
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jobshop
|
4
|
+
class Department::Assignment < ApplicationRecord
|
5
|
+
belongs_to :organization, -> { readonly }
|
6
|
+
|
7
|
+
belongs_to :department, inverse_of: :assignments
|
8
|
+
|
9
|
+
belongs_to :employee, inverse_of: :department_assignments
|
10
|
+
|
11
|
+
before_validation(on: :create) do
|
12
|
+
self.organization ||= department&.organization || employee&.organization
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,18 +1,22 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Jobshop # :nodoc:
|
4
4
|
class Employee < ApplicationRecord
|
5
|
-
|
5
|
+
belongs_to :organization, -> { readonly }, inverse_of: :employees
|
6
6
|
|
7
|
-
|
8
|
-
after_create { reload }
|
7
|
+
belongs_to :user, inverse_of: :employee, optional: true
|
9
8
|
|
10
|
-
|
9
|
+
has_many :department_assignments, inverse_of: :employee,
|
10
|
+
class_name: "Jobshop::Department::Assignment"
|
11
|
+
|
12
|
+
has_many :departments, through: :department_assignments
|
11
13
|
|
12
14
|
has_many :employments, inverse_of: :employee,
|
13
|
-
foreign_key: %i[ organization_id employee_id ],
|
14
15
|
dependent: :restrict_with_exception
|
15
16
|
|
17
|
+
has_many :rfq_line_assignments, through: :user,
|
18
|
+
foreign_key: :assigned_to_id, class_name: "Jobshop::RFQ::Line::Assignment"
|
19
|
+
|
16
20
|
validates :email,
|
17
21
|
presence: { if: :email_required? },
|
18
22
|
format: { if: :email_required?, with: /\A[^@\s]+@[^@\s]+\z/ },
|
@@ -27,6 +31,9 @@ module Jobshop # :nodoc:
|
|
27
31
|
joins(:employments).merge(Jobshop::Employment.inactive)
|
28
32
|
}
|
29
33
|
|
34
|
+
accepts_nested_attributes_for :employments, allow_destroy: true,
|
35
|
+
reject_if: :all_blank
|
36
|
+
|
30
37
|
def active?
|
31
38
|
!!employments.active.first
|
32
39
|
end
|
@@ -1,16 +1,12 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Jobshop
|
4
4
|
class Employment < ApplicationRecord
|
5
|
-
|
5
|
+
include Auditing
|
6
6
|
|
7
|
-
|
8
|
-
after_create { reload }
|
7
|
+
belongs_to :organization, -> { readonly }, inverse_of: :employments
|
9
8
|
|
10
|
-
belongs_to :
|
11
|
-
|
12
|
-
belongs_to :employee, inverse_of: :employments,
|
13
|
-
foreign_key: %i[ organization_id employee_id ]
|
9
|
+
belongs_to :employee, inverse_of: :employments
|
14
10
|
|
15
11
|
default_scope { order(ended_on: :desc, started_on: :desc) }
|
16
12
|
|
@@ -21,5 +17,9 @@ module Jobshop
|
|
21
17
|
scope :inactive, -> {
|
22
18
|
where.not(ended_on: nil)
|
23
19
|
}
|
20
|
+
|
21
|
+
before_validation(on: :create) do
|
22
|
+
self.organization ||= employee.organization
|
23
|
+
end
|
24
24
|
end
|
25
25
|
end
|
@@ -1,31 +1,25 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Jobshop
|
4
4
|
class Inspection::BooleanCriterion < ApplicationRecord
|
5
|
-
|
5
|
+
belongs_to :organization, -> { readonly }
|
6
6
|
|
7
|
-
|
8
|
-
before_save(on: :create) { criterion.save unless criterion.persisted? }
|
7
|
+
belongs_to :report, -> { readonly }
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
foreign_key: %i[ organization_id report_id ]
|
9
|
+
has_one :criterion, -> (boolean_criterion) {
|
10
|
+
where({
|
11
|
+
organization_id: boolean_criterion.organization_id,
|
12
|
+
report_id: boolean_criterion.report_id
|
13
|
+
})
|
14
|
+
}, as: :criterion, autosave: true, dependent: :destroy,
|
15
|
+
inverse_of: :criterion
|
18
16
|
|
19
17
|
def criterion
|
20
18
|
super || build_criterion
|
21
19
|
end
|
22
20
|
|
23
21
|
delegate :name, :name=, :position, :position=, to: :criterion
|
24
|
-
|
25
|
-
def specification
|
26
|
-
@specification ||= "#{condition}\nPASS/FAIL"
|
27
|
-
end
|
28
|
-
=end
|
22
|
+
|
29
23
|
def tolerance
|
30
24
|
@tolerance ||= condition
|
31
25
|
end
|
@@ -40,8 +34,10 @@ module Jobshop
|
|
40
34
|
|
41
35
|
# Generate a random value that has a 90% chance of being in spec.
|
42
36
|
# TODO: This needs to go in the tests somewhere, not really in the model.
|
37
|
+
# :nocov:
|
43
38
|
def random
|
44
39
|
rand(100) < 10
|
45
40
|
end
|
41
|
+
# :nocov:
|
46
42
|
end
|
47
43
|
end
|
@@ -1,19 +1,18 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Jobshop
|
4
4
|
class Inspection::Criterion < ApplicationRecord
|
5
|
-
|
5
|
+
belongs_to :organization, -> { readonly }
|
6
6
|
|
7
|
-
|
7
|
+
belongs_to :report, -> { readonly }
|
8
8
|
|
9
|
-
belongs_to :
|
9
|
+
belongs_to :criterion, polymorphic: true, optional: true,
|
10
|
+
dependent: :destroy
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
before_validation(on: :create) do
|
13
|
+
self.organization ||= report.organization
|
14
|
+
end
|
13
15
|
|
14
|
-
|
15
|
-
foreign_key: %i[ organization_id report_id ], inverse_of: :criteria
|
16
|
-
|
17
|
-
delegate :ascii, :pass?, :random, :unit, to: :criterion
|
16
|
+
delegate :pass?, :random, :unit, to: :criterion
|
18
17
|
end
|
19
18
|
end
|
@@ -1,20 +1,18 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Jobshop
|
4
4
|
class Inspection::DeviationCriterion < ApplicationRecord
|
5
|
-
|
5
|
+
belongs_to :organization, -> { readonly }
|
6
6
|
|
7
|
-
|
8
|
-
before_save(on: :create) { criterion.save unless criterion.persisted? }
|
7
|
+
belongs_to :report, -> { readonly }
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
inverse_of: :criterion
|
9
|
+
has_one :criterion, -> (deviation_criterion) {
|
10
|
+
where({
|
11
|
+
organization_id: deviation_criterion.organization_id,
|
12
|
+
report_id: deviation_criterion.report_id
|
13
|
+
})
|
14
|
+
}, as: :criterion, autosave: true, dependent: :destroy,
|
15
|
+
inverse_of: :criterion
|
18
16
|
|
19
17
|
def criterion
|
20
18
|
super || build_criterion
|
@@ -1,18 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Jobshop
|
2
4
|
class Inspection::LimitCriterion < ApplicationRecord
|
3
|
-
|
4
|
-
|
5
|
-
after_initialize { self.criterion_id ||= SecureRandom.uuid if new_record? }
|
6
|
-
before_save(on: :create) { criterion.save unless criterion.persisted? }
|
5
|
+
belongs_to :organization, -> { readonly }
|
7
6
|
|
8
|
-
belongs_to :
|
7
|
+
belongs_to :report, -> { readonly }
|
9
8
|
|
10
|
-
has_one :criterion,
|
11
|
-
|
12
|
-
|
9
|
+
has_one :criterion, -> (criterion) {
|
10
|
+
where({
|
11
|
+
organization_id: criterion.organization_id,
|
12
|
+
report_id: criterion.report_id
|
13
|
+
})
|
14
|
+
}, as: :criterion, autosave: true, dependent: :destroy,
|
15
|
+
inverse_of: :criterion
|
13
16
|
|
14
|
-
belongs_to :report
|
15
|
-
foreign_key: %i[ organization_id report_id ]
|
17
|
+
belongs_to :report
|
16
18
|
|
17
19
|
def criterion
|
18
20
|
super || build_criterion
|
@@ -1,39 +1,27 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Jobshop
|
4
4
|
class Inspection::Report < ApplicationRecord
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
has_many :
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
t << [ "Specification" ].concat(criteria.map(&:criterion).map(&:specification))
|
27
|
-
tuples.each do |tuple|
|
28
|
-
results = criteria.map do |criterion|
|
29
|
-
tuple.results.find_by(criterion: criterion)
|
30
|
-
end
|
31
|
-
t << [ tuple.position ].concat(results.map(&:value))
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
puts table
|
36
|
-
end
|
37
|
-
=end
|
5
|
+
belongs_to :organization, -> { readonly }, inverse_of: :inspection_reports
|
6
|
+
|
7
|
+
has_many :criteria, -> (report) {
|
8
|
+
where({ organization_id: report.organization_id }) #.includes(:criterion)
|
9
|
+
.order(:position)
|
10
|
+
}
|
11
|
+
|
12
|
+
has_many :boolean_criteria, -> (report) {
|
13
|
+
rewhere({ organization_id: report.organization_id, report_id: report.id })
|
14
|
+
}, through: :criteria, source: :criterion,
|
15
|
+
source_type: "Jobshop::Inspection::BooleanCriterion"
|
16
|
+
|
17
|
+
has_many :deviation_criteria, -> (report) {
|
18
|
+
rewhere({ organization_id: report.organization_id, report_id: report.id })
|
19
|
+
}, through: :criteria, source: :criterion,
|
20
|
+
source_type: "Jobshop::Inspection::DeviationCriterion"
|
21
|
+
|
22
|
+
has_many :limit_criteria, -> (report) {
|
23
|
+
rewhere({ organization_id: report.organization_id, report_id: report.id })
|
24
|
+
}, through: :criteria, source: :criterion,
|
25
|
+
source_type: "Jobshop::Inspection::LimitCriterion"
|
38
26
|
end
|
39
27
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# +Jobshop::Mailman+
|
4
4
|
#
|
@@ -6,9 +6,7 @@
|
|
6
6
|
# approrpriate handler. If no handler is found, the email is rejected.
|
7
7
|
module Jobshop
|
8
8
|
class Mailman < ApplicationRecord
|
9
|
-
|
10
|
-
|
11
|
-
belongs_to :organization, inverse_of: :mailmen
|
9
|
+
belongs_to :organization, -> { readonly }, inverse_of: :mailmen
|
12
10
|
|
13
11
|
validates :address, presence: true
|
14
12
|
|
data/app/models/jobshop/order.rb
CHANGED
@@ -1,35 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Jobshop
|
4
4
|
class Order < ApplicationRecord
|
5
|
-
self.primary_keys = %i[ organization_id order_id ]
|
6
|
-
|
7
|
-
after_initialize { self.order_id ||= SecureRandom.uuid if new_record? }
|
8
|
-
|
9
5
|
belongs_to :organization, -> { readonly }, inverse_of: :orders
|
10
6
|
|
11
|
-
belongs_to :customer
|
12
|
-
|
13
|
-
has_many :order_lines, inverse_of: :order,
|
14
|
-
foreign_key: %i[ organization_id order_id ]
|
15
|
-
|
16
|
-
around_save :notify_on_save
|
17
|
-
|
18
|
-
def add_listener(listener)
|
19
|
-
(@listeners ||= []) << listener
|
20
|
-
end
|
21
|
-
|
22
|
-
def notify_listeners(event_name, *args)
|
23
|
-
@listeners && @listeners.each do |listener|
|
24
|
-
if listener.respond_to?(event_name)
|
25
|
-
listener.public_send(event_name, self, *args)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
7
|
+
belongs_to :customer
|
29
8
|
|
30
|
-
|
31
|
-
yield
|
32
|
-
notify_listeners(:on_save)
|
33
|
-
end
|
9
|
+
has_many :order_lines, inverse_of: :order
|
34
10
|
end
|
35
11
|
end
|
@@ -1,17 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Jobshop
|
4
4
|
class OrderLine < ApplicationRecord
|
5
|
-
|
5
|
+
belongs_to :organization, -> { readonly }
|
6
6
|
|
7
|
-
|
7
|
+
belongs_to :order, inverse_of: :order_lines
|
8
8
|
|
9
|
-
belongs_to :
|
10
|
-
|
11
|
-
belongs_to :order, inverse_of: :order_lines,
|
12
|
-
foreign_key: %i[ organization_id order_id ]
|
13
|
-
|
14
|
-
belongs_to :product,
|
15
|
-
foreign_key: %i[ organization_id product_id ]
|
9
|
+
belongs_to :product, inverse_of: :orders
|
16
10
|
end
|
17
11
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Jobshop
|
4
4
|
class Organization < ApplicationRecord
|
5
|
-
|
5
|
+
include Auditing
|
6
6
|
|
7
7
|
has_many :collections, inverse_of: :organization,
|
8
8
|
dependent: :restrict_with_exception
|
@@ -18,8 +18,11 @@ module Jobshop
|
|
18
18
|
dependent: :restrict_with_exception,
|
19
19
|
class_name: "Jobshop::Customer::Contact"
|
20
20
|
|
21
|
-
has_many :
|
22
|
-
|
21
|
+
has_many :departments, inverse_of: :organization,
|
22
|
+
dependent: :restrict_with_exception
|
23
|
+
|
24
|
+
has_many :employees, inverse_of: :organization,
|
25
|
+
dependent: :restrict_with_exception
|
23
26
|
|
24
27
|
has_many :employments, inverse_of: :organization,
|
25
28
|
dependent: :restrict_with_exception
|
@@ -55,16 +58,6 @@ module Jobshop
|
|
55
58
|
has_many :users, inverse_of: :organization,
|
56
59
|
dependent: :restrict_with_exception
|
57
60
|
|
58
|
-
|
59
|
-
scope :grouped_by_email, ->(email_addresses) {
|
60
|
-
Jobshop::User
|
61
|
-
.where(email: email_addresses)
|
62
|
-
.joins(:organization)
|
63
|
-
.includes(:organization)
|
64
|
-
.each_with_object({}) { |user, organizations|
|
65
|
-
(organizations[user.email] ||= []) << user.organization
|
66
|
-
}
|
67
|
-
}
|
68
|
-
=end
|
61
|
+
validates :name, presence: true
|
69
62
|
end
|
70
63
|
end
|