jobshop 0.0.157 → 0.0.163

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -1
  3. data/app/email_handlers/jobshop/rfq_handler.rb +43 -0
  4. data/app/models/jobshop/collection.rb +6 -11
  5. data/app/models/jobshop/company.rb +25 -12
  6. data/app/models/jobshop/company/type.rb +17 -0
  7. data/app/models/jobshop/company_person.rb +15 -0
  8. data/app/models/jobshop/inspection.rb +2 -0
  9. data/app/models/jobshop/inspection/boolean_criterion.rb +13 -10
  10. data/app/models/jobshop/inspection/criterion.rb +8 -11
  11. data/app/models/jobshop/inspection/deviation_criterion.rb +13 -10
  12. data/app/models/jobshop/inspection/limit_criterion.rb +9 -7
  13. data/app/models/jobshop/inspection/report.rb +11 -15
  14. data/app/models/jobshop/inspection/result.rb +9 -5
  15. data/app/models/jobshop/inspection/tuple.rb +7 -3
  16. data/app/models/jobshop/mailman.rb +11 -0
  17. data/app/models/jobshop/order.rb +12 -14
  18. data/app/models/jobshop/order_line.rb +10 -5
  19. data/app/models/jobshop/organization.rb +35 -8
  20. data/app/models/jobshop/person.rb +30 -0
  21. data/app/models/jobshop/place.rb +3 -1
  22. data/app/models/jobshop/product.rb +10 -12
  23. data/app/models/jobshop/rfq.rb +22 -0
  24. data/app/models/jobshop/rfq_line.rb +12 -0
  25. data/app/models/jobshop/role.rb +6 -13
  26. data/app/models/jobshop/role_assignment.rb +4 -2
  27. data/app/models/jobshop/routing_process.rb +8 -11
  28. data/app/models/jobshop/routing_step.rb +4 -2
  29. data/app/models/jobshop/thing.rb +6 -11
  30. data/app/models/jobshop/user.rb +10 -17
  31. data/db/migrate/20170311194758_initialize_jobshop.rb +3 -1
  32. data/db/migrate/20171216021339_create_organizations.rb +4 -2
  33. data/db/migrate/20171216021554_create_people.rb +48 -0
  34. data/db/migrate/20171216021853_create_companies.rb +47 -8
  35. data/db/migrate/20171216022020_create_places.rb +3 -3
  36. data/db/migrate/20171216022135_create_products.rb +5 -3
  37. data/db/migrate/20171216022605_create_orders.rb +9 -7
  38. data/db/migrate/20171216023018_create_roles.rb +18 -16
  39. data/db/migrate/20171216023022_create_sessions.rb +9 -7
  40. data/db/migrate/20171216035357_create_things.rb +7 -5
  41. data/db/migrate/20171219022118_create_routing_processes.rb +10 -8
  42. data/db/migrate/{20180107203241_create_inspection.rb → 20180107203241_create_inspections.rb} +21 -16
  43. data/db/migrate/20181117023949_create_rfqs.rb +40 -0
  44. data/db/migrate/20181118014603_create_mailmen.rb +29 -0
  45. data/exe/jobshop +1 -1
  46. data/lib/generators/jobshop/app/app_generator.rb +12 -23
  47. data/lib/generators/jobshop/app/templates/Procfile.tt +1 -0
  48. data/lib/generators/jobshop/config/templates/config/initializers/jobshop.rb.tt +5 -0
  49. data/lib/generators/jobshop/dummy/dummy_generator.rb +4 -5
  50. data/lib/jobshop.rb +8 -4
  51. data/lib/jobshop/cli.rb +58 -47
  52. data/lib/jobshop/configuration.rb +17 -5
  53. data/lib/jobshop/dummy_app.rb +27 -15
  54. data/lib/jobshop/engine.rb +28 -15
  55. data/lib/jobshop/helpers/migration.rb +6 -2
  56. data/lib/jobshop/postmaster.rb +89 -0
  57. data/lib/jobshop/version.rb +2 -2
  58. data/lib/tasks/jobshop_tasks.rake +11 -0
  59. metadata +83 -16
  60. data/db/migrate/20171216021717_create_users.rb +0 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cfebb1f31d1fcbb60de9a9b6d74d38cf33db9dd8
4
- data.tar.gz: 06d074ee3efe7275a4a2704b0c4ad1a512853259
3
+ metadata.gz: 72d9c251b2bcc65848a33510d25bdee8d14ca55b
4
+ data.tar.gz: b0e53706a8d59d0824affb1a416fb519786a520b
5
5
  SHA512:
6
- metadata.gz: 342ba401730334f6e0b99959c2a90abb10b1f5a46dc5caf88c36df26515797d510944035742c133cd38e244f551df4235ed15bd6774cf0ac022594807be1f138
7
- data.tar.gz: c6186e7da358301f38968e0a700bab329a4a98be4f57934163513b005cad73f31370184489f2ec10367a90cdfb0d0f6c5d74c100a437937b19aa3ab9ccd6f38d
6
+ metadata.gz: 3a442988c2fcc8dc15e7bca171754a7d1ef608cf55a1021354b0be3c189ec1eadac472ffbb33c69371a8a9caceff0513dde3d7624aadf69f07fa5c6cbfe15c53
7
+ data.tar.gz: 1aff3bac63832e1f71be8cb40ae5949b8f45966d9752a78f0c2e7a89e8f1e3b01c70b5c58c02ab2b4d034ee419a49fe72f7f562da98bd863046d728e0886fc2b
data/README.md CHANGED
@@ -6,7 +6,6 @@ Real-time production tracking and process evaluation, under your own roof.
6
6
  [![Code Climate](https://codeclimate.com/github/jobshop/jobshop/badges/gpa.svg)](https://codeclimate.com/github/jobshop/jobshop)
7
7
  [![Build Status](https://semaphoreci.com/api/v1/frankjmattia/jobshop/branches/master/shields_badge.svg)](https://semaphoreci.com/frankjmattia/jobshop)
8
8
  [![Test Coverage](https://codeclimate.com/github/jobshop/jobshop/badges/coverage.svg)](https://codeclimate.com/github/jobshop/jobshop/coverage)
9
- [![Dependency Status](https://gemnasium.com/badges/github.com/jobshop/jobshop.svg)](https://gemnasium.com/github.com/jobshop/jobshop)
10
9
 
11
10
  ## TL;DR
12
11
 
@@ -0,0 +1,43 @@
1
+ # frozen_string_literals: true
2
+
3
+ module Jobshop
4
+ class RFQHandler
5
+ def initialize(message, organization:)
6
+ @from = message.from.first
7
+ @subject = message.subject
8
+ @content = message.text_part.decoded
9
+ @organization = organization
10
+ end
11
+
12
+ def process
13
+ new_rfq = @organization.rfqs.create({
14
+ from: @from,
15
+ subject: @subject,
16
+ content: @content
17
+ })
18
+
19
+ if new_rfq.persisted?
20
+ # TODO: Send response email to customer
21
+ # TODO: Send rfq to quoting queue.
22
+ return new_rfq
23
+ else
24
+ # TODO: There was some kind of failure which should be logged.
25
+ return false
26
+ end
27
+ end
28
+
29
+ # Whether or not to copy the original to a new location after processing.
30
+ def copy_after_processing?
31
+ true
32
+ end
33
+
34
+ # Whether or not to delete the original item after processing.
35
+ def delete_after_processing?
36
+ true
37
+ end
38
+
39
+ def processed_copy_prefix
40
+ "rfqs/processed"
41
+ end
42
+ end
43
+ end
@@ -1,20 +1,15 @@
1
+ # frozen_string_literals
2
+
1
3
  module Jobshop
2
4
  class Collection < ApplicationRecord
3
- self.primary_keys = [ :organization_id, :collection_id ]
5
+ self.primary_keys = %i[ organization_id collection_id ]
4
6
 
5
- after_create do
6
- self.class.connection.clear_query_cache
7
- fresh_collection = self.class.unscoped {
8
- self.class.find_by!(organization: organization, name: name)
9
- }
10
- @attributes = fresh_collection.instance_variable_get(:@attributes)
11
- @new_record = false
12
- self
13
- end
7
+ after_initialize { self.collection_id ||= SecureRandom.uuid if new_record? }
14
8
 
15
9
  belongs_to :organization, inverse_of: :collections
10
+
16
11
  has_many :things, inverse_of: :collection,
17
- foreign_key: [ :organization_id, :collection_id ]
12
+ foreign_key: %i[ organization_id collection_id ]
18
13
 
19
14
  validates :name, presence: true,
20
15
  uniqueness: { scope: :organization_id, case_sensitive: false }
@@ -1,21 +1,34 @@
1
+ # frozen_string_literals: true
2
+
1
3
  module Jobshop
2
4
  class Company < ApplicationRecord
3
- self.primary_keys = [ :organization_id, :company_id ]
5
+ self.primary_keys = %i[ organization_id company_id ]
6
+
7
+ # Because we have a column named +type+, Rails wants to activate STI
8
+ # Disable it manually
9
+ self.inheritance_column = nil
4
10
 
5
- after_create do
6
- self.class.connection.clear_query_cache
7
- @attributes = self.class.unscoped {
8
- self.class.find_by!(organization: organization, name: name)
9
- }.instance_variable_get(:@attributes)
10
- @new_record = false
11
- self
12
- end
11
+ after_initialize { self.company_id ||= SecureRandom.uuid if new_record? }
13
12
 
14
13
  belongs_to :organization, inverse_of: :companies
15
- belongs_to :created_by, class_name: "Jobshop::User",
16
- foreign_key: [ :organization_id, :created_by_id ]
14
+
15
+ has_many :company_people, inverse_of: :company,
16
+ foreign_key: %i[ organization_id company_id ]
17
+
18
+ belongs_to :created_by, class_name: "Jobshop::Person",
19
+ foreign_key: %i[ organization_id created_by_id ]
20
+
17
21
  has_many :orders, inverse_of: :company,
18
- foreign_key: [ :organization_id, :company_id ]
22
+ foreign_key: %i[ organization_id company_id ]
23
+
24
+ has_many :people, through: :company_people,
25
+ foreign_key: %i[ organization_id person_id ]
26
+
27
+ has_many :rfqs, inverse_of: :company,
28
+ foreign_key: %i[ organization_id company_id ]
29
+
30
+ belongs_to :type, class_name: "Jobshop::Company::Type",
31
+ foreign_key: %i[ organization_id type_id ], inverse_of: :companies
19
32
 
20
33
  validates :name, presence: true
21
34
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literals: true
2
+
3
+ module Jobshop
4
+ class Company::Type < ApplicationRecord
5
+ self.primary_keys = %i[ organization_id type_id ]
6
+
7
+ after_initialize { self.type_id ||= SecureRandom.uuid if new_record? }
8
+
9
+ belongs_to :organization, inverse_of: :company_types
10
+
11
+ has_many :companies, inverse_of: :type,
12
+ foreign_key: %i[ organization_id type_id ]
13
+
14
+ validates :name,
15
+ uniqueness: { scope: :organization_id, case_sensitive: false }
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literals: true
2
+
3
+ module Jobshop
4
+ class CompanyPerson < ApplicationRecord
5
+ self.primary_keys = %i[ organization_id company_id person_id ]
6
+
7
+ belongs_to :organization
8
+
9
+ belongs_to :company, inverse_of: :company_people,
10
+ foreign_key: %i[ organization_id company_id ]
11
+
12
+ belongs_to :person, inverse_of: :company_person,
13
+ foreign_key: %i[ organization_id person_id ]
14
+ end
15
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literals: true
2
+
1
3
  module Jobshop
2
4
  module Inspection
3
5
  def self.table_name_prefix
@@ -1,21 +1,24 @@
1
+ # frozen_string_literals: true
2
+
1
3
  module Jobshop
2
4
  class Inspection::BooleanCriterion < ApplicationRecord
3
- self.primary_keys = [ :organization_id, :report_id, :criterion_id, :criterion_type ]
5
+ self.primary_keys = %i[ organization_id report_id criterion_id criterion_type ]
4
6
 
5
- after_initialize do
6
- self[:criterion_id] ||= SecureRandom.uuid if new_record?
7
- end
7
+ after_initialize { self.criterion_id ||= SecureRandom.uuid if new_record? }
8
+ before_save(on: :create) { criterion.save unless criterion.persisted? }
8
9
 
9
10
  belongs_to :organization
11
+
10
12
  has_one :criterion, as: :criterion, autosave: true, dependent: :destroy,
11
- foreign_key: [ :organization_id, :report_id, :criterion_id, :criterion_type ]
13
+ foreign_key: %i[ organization_id report_id criterion_id criterion_type ],
14
+ inverse_of: :criterion
15
+
12
16
  belongs_to :report, class_name: "Jobshop::Inspection::Report",
13
- foreign_key: [ :organization_id, :report_id ], inverse_of: :criteria
17
+ foreign_key: %i[ organization_id report_id ]
14
18
 
15
- alias_method :criterion_without_build, :criterion
16
- def criterion_with_build
17
- criterion_without_build || build_criterion(criterion_id: criterion_id, report: report)
18
- end; alias_method :criterion, :criterion_with_build
19
+ def criterion
20
+ super || build_criterion
21
+ end
19
22
 
20
23
  delegate :name, :name=, :position, :position=, to: :criterion
21
24
 
@@ -1,21 +1,18 @@
1
+ # frozen_string_literals: true
2
+
1
3
  module Jobshop
2
4
  class Inspection::Criterion < ApplicationRecord
3
- self.primary_keys = [ :organization_id, :report_id, :criterion_id, :criterion_type ]
5
+ self.primary_keys = %i[ organization_id report_id criterion_id criterion_type ]
4
6
 
5
- after_create do
6
- self.class.connection.clear_query_cache
7
- @attributes = self.class.unscoped {
8
- self.class.find_by!(organization: organization, criterion_id: criterion_id)
9
- }.instance_variable_get(:@attributes)
10
- @new_record = false
11
- self
12
- end
7
+ after_initialize { self.criterion_id ||= SecureRandom.uuid if new_record? }
13
8
 
14
9
  belongs_to :organization
10
+
15
11
  belongs_to :criterion, polymorphic: true, optional: true, dependent: :destroy,
16
- foreign_key: [ :organization_id, :report_id, :criterion_id, :criterion_type ]
12
+ foreign_key: %i[ organization_id report_id criterion_id criterion_type ]
13
+
17
14
  belongs_to :report, class_name: "Jobshop::Inspection::Report",
18
- foreign_key: [ :organization_id, :report_id ], inverse_of: :criteria
15
+ foreign_key: %i[ organization_id report_id ], inverse_of: :criteria
19
16
 
20
17
  delegate :ascii, :pass?, :random, :unit, to: :criterion
21
18
  end
@@ -1,21 +1,24 @@
1
+ # frozen_string_literals: true
2
+
1
3
  module Jobshop
2
4
  class Inspection::DeviationCriterion < ApplicationRecord
3
- self.primary_keys = [ :organization_id, :report_id, :criterion_id, :criterion_type ]
5
+ self.primary_keys = %i[ organization_id report_id criterion_id criterion_type ]
4
6
 
5
- after_initialize do
6
- self.criterion_id ||= SecureRandom.uuid if new_record?
7
- end
7
+ after_initialize { self.criterion_id ||= SecureRandom.uuid if new_record? }
8
+ before_save(on: :create) { criterion.save unless criterion.persisted? }
8
9
 
9
10
  belongs_to :organization
11
+
10
12
  belongs_to :report, class_name: "Jobshop::Inspection::Report",
11
- foreign_key: [ :organization_id, :report_id ], inverse_of: :criteria
13
+ foreign_key: %i[ organization_id report_id ]
14
+
12
15
  has_one :criterion, as: :criterion, autosave: true, dependent: :destroy,
13
- foreign_key: [ :organization_id, :report_id, :criterion_id, :criterion_type ]
16
+ foreign_key: %i[ organization_id report_id criterion_id criterion_type ],
17
+ inverse_of: :criterion
14
18
 
15
- alias_method :criterion_without_build, :criterion
16
- def criterion_with_build
17
- criterion_without_build || build_criterion
18
- end; alias_method :criterion, :criterion_with_build
19
+ def criterion
20
+ super || build_criterion
21
+ end
19
22
 
20
23
  delegate :name, :name=, :position, :position=, to: :criterion
21
24
 
@@ -1,16 +1,18 @@
1
1
  module Jobshop
2
2
  class Inspection::LimitCriterion < ApplicationRecord
3
- self.primary_keys = [ :organization_id, :report_id, :criterion_id, :criterion_type ]
3
+ self.primary_keys = %i[ organization_id report_id criterion_id criterion_type ]
4
4
 
5
- after_initialize do
6
- self.criterion_id = SecureRandom.uuid if new_record?
7
- end
5
+ after_initialize { self.criterion_id ||= SecureRandom.uuid if new_record? }
6
+ before_save(on: :create) { criterion.save unless criterion.persisted? }
8
7
 
9
8
  belongs_to :organization
10
- has_one :criterion, as: :criterion, autosave: true, dependent: :destroy, inverse_of: :criterion,
11
- foreign_key: [ :organization_id, :report_id, :criterion_id, :criterion_type ]
9
+
10
+ has_one :criterion, as: :criterion, autosave: true, dependent: :destroy,
11
+ foreign_key: %i[ organization_id report_id criterion_id criterion_type ],
12
+ inverse_of: :criterion
13
+
12
14
  belongs_to :report, class_name: "Jobshop::Inspection::Report",
13
- foreign_key: [ :organization_id, :report_id ], inverse_of: :criteria
15
+ foreign_key: %i[ organization_id report_id ]
14
16
 
15
17
  def criterion
16
18
  super || build_criterion
@@ -1,25 +1,21 @@
1
+ # frozen_string_literals: true
2
+
1
3
  module Jobshop
2
4
  class Inspection::Report < ApplicationRecord
3
- self.primary_keys = [ :organization_id, :report_id ]
5
+ self.primary_keys = %i[ organization_id report_id ]
4
6
 
5
- after_initialize do
6
- self.report_id ||= SecureRandom.uuid if new_record?
7
- end
7
+ after_initialize { self.report_id ||= SecureRandom.uuid if new_record? }
8
8
 
9
- after_create do
10
- self.class.connection.clear_query_cache
11
- @attributes = self.class.unscoped {
12
- self.class.find_by!(organization: organization, report_id: report_id)
13
- }.instance_variable_get(:@attributes)
14
- @new_record = false
15
- self
16
- end
9
+ belongs_to :organization, inverse_of: :inspection_reports
17
10
 
18
- belongs_to :organization
19
11
  has_many :criteria, -> { includes(:criterion).order(:position) },
20
- foreign_key: [ :organization_id, :report_id ], inverse_of: :report
12
+ foreign_key: %i[ organization_id report_id ], inverse_of: :report
13
+
14
+ has_many :limit_criteria, inverse_of: :report,
15
+ foreign_key: %i[ organization_id report_id ]
16
+
21
17
  has_many :tuples, -> { order(:position) }, inverse_of: :report,
22
- foreign_key: [ :organization_id, :report_id ]
18
+ foreign_key: %i[ organization_id report_id ]
23
19
 
24
20
  def ascii
25
21
  require "terminal-table"
@@ -1,22 +1,26 @@
1
+ # frozen_string_literals: true
2
+
1
3
  module Jobshop
2
4
  class Inspection::Result < ApplicationRecord
3
5
  FALSE_VALUES = [false, 0, "0", "f", "F", "false", "FALSE", "off", "OFF"]
4
6
 
5
- self.primary_keys = [ :organization_id, :report_id, :criterion_id, :criterion_type, :position ]
7
+ self.primary_keys = %i[ organization_id report_id criterion_id criterion_type position ]
6
8
 
7
9
  belongs_to :organization
10
+
8
11
  belongs_to :report, class_name: "Jobshop::Inspection::Report",
9
- foreign_key: [ :organization_id, :report_id ]
12
+ foreign_key: %i[ organization_id report_id ]
13
+
10
14
  belongs_to :criterion, polymorphic: true, optional: true, dependent: :destroy,
11
- foreign_key: [ :organization_id, :report_id, :criterion_id, :criterion_type ]
15
+ foreign_key: %i[ organization_id report_id criterion_id criterion_type ]
16
+
12
17
  belongs_to :tuple, class_name: "Jobshop::Inspection::Tuple",
13
- foreign_key: [ :organization_id, :report_id, :position ]
18
+ foreign_key: %i[ organization_id report_id position ]
14
19
 
15
20
  def value
16
21
  if self[:unit] == "boolean"
17
22
  !!self[:value]
18
23
  else
19
- # binding.pry
20
24
  self[:value] && Unitwise(self[:value].truncate(4), self[:unit])
21
25
  end
22
26
  end
@@ -1,12 +1,16 @@
1
+ # frozen_string_literals: true
2
+
1
3
  module Jobshop
2
4
  class Inspection::Tuple < ApplicationRecord
3
- self.primary_keys = [ :organization_id, :report_id, :position ]
5
+ self.primary_keys = %i[ organization_id report_id position ]
4
6
 
5
7
  belongs_to :organization
8
+
6
9
  belongs_to :report, class_name: "Jobshop::Inspection::Report", inverse_of: :tuples,
7
- foreign_key: [ :organization_id, :report_id ]
10
+ foreign_key: %i[ organization_id report_id ]
11
+
8
12
  has_many :results, class_name: "Jobshop::Inspection::Result", inverse_of: :tuple,
9
- foreign_key: [ :organization_id, :report_id, :position ]
13
+ foreign_key: %i[ organization_id report_id position ]
10
14
 
11
15
  has_many :criteria, through: :results
12
16
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literals: true
2
+
3
+ module Jobshop
4
+ class Mailman < ApplicationRecord
5
+ self.primary_keys = %i[ organization_id address ]
6
+
7
+ belongs_to :organization, inverse_of: :mailmen
8
+
9
+ validates :address, presence: true
10
+ end
11
+ end
@@ -1,23 +1,21 @@
1
+ # frozen_string_literals: true
2
+
1
3
  module Jobshop
2
4
  class Order < ApplicationRecord
3
- self.primary_keys = [ :organization_id, :order_id ]
4
-
5
- after_create do
6
- self.class.connection.clear_query_cache
7
- @attributes = self.class.unscoped {
8
- self.class.find_by!(organization: organization, number: number)
9
- }.instance_variable_get(:@attributes)
10
- @new_record = false
11
- self
12
- end
5
+ self.primary_keys = %i[ organization_id order_id ]
6
+
7
+ after_initialize { self.order_id ||= SecureRandom.uuid if new_record? }
13
8
 
14
9
  belongs_to :organization, inverse_of: :orders
15
- belongs_to :created_by, class_name: "Jobshop::User",
16
- foreign_key: [ :organization_id, :created_by_id ]
10
+
11
+ belongs_to :created_by, class_name: "Jobshop::Person",
12
+ foreign_key: %i[ organization_id created_by_id ]
13
+
17
14
  belongs_to :company, inverse_of: :orders,
18
- foreign_key: [ :organization_id, :company_id ]
15
+ foreign_key: %i[ organization_id company_id ]
16
+
19
17
  has_many :order_lines, inverse_of: :order,
20
- foreign_key: [ :organization_id, :order_id ]
18
+ foreign_key: %i[ organization_id order_id ]
21
19
 
22
20
  around_save :notify_on_save
23
21