app/models/ncr/work_order.rb

Summary

Maintainability
B
4 hrs
Test Coverage

Class WorkOrder has 34 methods (exceeds 20 allowed). Consider refactoring.
Open

  class WorkOrder < ActiveRecord::Base
    # must define before include PurchaseCardMixin
    def self.purchase_amount_column_name
      :amount
    end
Severity: Minor
Found in app/models/ncr/work_order.rb - About 4 hrs to fix

    Assignment Branch Condition size for fiscal_year is too high. [16.76/15]
    Open

        def fiscal_year
          year = created_at.nil? ? Time.zone.now.year : created_at.year
          month = created_at.nil? ? Time.zone.now.month : created_at.month
          if month >= 10
            year += 1
    Severity: Minor
    Found in app/models/ncr/work_order.rb by rubocop

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Specify an :inverse_of option.
    Open

        belongs_to :ncr_organization, class_name: Ncr::Organization
    Severity: Minor
    Found in app/models/ncr/work_order.rb by rubocop

    This cop looks for has(one|many) and belongsto associations where ActiveRecord can't automatically determine the inverse association because of a scope or the options used. This can result in unnecessary queries in some circumstances. :inverse_of must be manually specified for associations to work in both ways, or set to false to opt-out.

    Example:

    # good
    class Blog < ApplicationRecord
      has_many :posts
    end
    
    class Post < ApplicationRecord
      belongs_to :blog
    end

    Example:

    # bad
    class Blog < ApplicationRecord
      has_many :posts, -> { order(published_at: :desc) }
    end
    
    class Post < ApplicationRecord
      belongs_to :blog
    end
    
    # good
    class Blog < ApplicationRecord
      has_many(:posts,
        -> { order(published_at: :desc) },
        inverse_of: :blog
      )
    end
    
    class Post < ApplicationRecord
      belongs_to :blog
    end
    
    # good
    class Blog < ApplicationRecord
      with_options inverse_of: :blog do
        has_many :posts, -> { order(published_at: :desc) }
      end
    end
    
    class Post < ApplicationRecord
      belongs_to :blog
    end

    Example:

    # bad
    class Picture < ApplicationRecord
      belongs_to :imageable, polymorphic: true
    end
    
    class Employee < ApplicationRecord
      has_many :pictures, as: :imageable
    end
    
    class Product < ApplicationRecord
      has_many :pictures, as: :imageable
    end
    
    # good
    class Picture < ApplicationRecord
      belongs_to :imageable, polymorphic: true
    end
    
    class Employee < ApplicationRecord
      has_many :pictures, as: :imageable, inverse_of: :imageable
    end
    
    class Product < ApplicationRecord
      has_many :pictures, as: :imageable, inverse_of: :imageable
    end

    Example:

    # bad
    # However, RuboCop can not detect this pattern...
    class Physician < ApplicationRecord
      has_many :appointments
      has_many :patients, through: :appointments
    end
    
    class Appointment < ApplicationRecord
      belongs_to :physician
      belongs_to :patient
    end
    
    class Patient < ApplicationRecord
      has_many :appointments
      has_many :physicians, through: :appointments
    end
    
    # good
    class Physician < ApplicationRecord
      has_many :appointments
      has_many :patients, through: :appointments
    end
    
    class Appointment < ApplicationRecord
      belongs_to :physician, inverse_of: :appointments
      belongs_to :patient, inverse_of: :appointments
    end
    
    class Patient < ApplicationRecord
      has_many :appointments
      has_many :physicians, through: :appointments
    end

    @see http://guides.rubyonrails.org/association_basics.html#bi-directional-associations @see http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses

    Specify an :inverse_of option.
    Open

        belongs_to :approving_official, class_name: User
    Severity: Minor
    Found in app/models/ncr/work_order.rb by rubocop

    This cop looks for has(one|many) and belongsto associations where ActiveRecord can't automatically determine the inverse association because of a scope or the options used. This can result in unnecessary queries in some circumstances. :inverse_of must be manually specified for associations to work in both ways, or set to false to opt-out.

    Example:

    # good
    class Blog < ApplicationRecord
      has_many :posts
    end
    
    class Post < ApplicationRecord
      belongs_to :blog
    end

    Example:

    # bad
    class Blog < ApplicationRecord
      has_many :posts, -> { order(published_at: :desc) }
    end
    
    class Post < ApplicationRecord
      belongs_to :blog
    end
    
    # good
    class Blog < ApplicationRecord
      has_many(:posts,
        -> { order(published_at: :desc) },
        inverse_of: :blog
      )
    end
    
    class Post < ApplicationRecord
      belongs_to :blog
    end
    
    # good
    class Blog < ApplicationRecord
      with_options inverse_of: :blog do
        has_many :posts, -> { order(published_at: :desc) }
      end
    end
    
    class Post < ApplicationRecord
      belongs_to :blog
    end

    Example:

    # bad
    class Picture < ApplicationRecord
      belongs_to :imageable, polymorphic: true
    end
    
    class Employee < ApplicationRecord
      has_many :pictures, as: :imageable
    end
    
    class Product < ApplicationRecord
      has_many :pictures, as: :imageable
    end
    
    # good
    class Picture < ApplicationRecord
      belongs_to :imageable, polymorphic: true
    end
    
    class Employee < ApplicationRecord
      has_many :pictures, as: :imageable, inverse_of: :imageable
    end
    
    class Product < ApplicationRecord
      has_many :pictures, as: :imageable, inverse_of: :imageable
    end

    Example:

    # bad
    # However, RuboCop can not detect this pattern...
    class Physician < ApplicationRecord
      has_many :appointments
      has_many :patients, through: :appointments
    end
    
    class Appointment < ApplicationRecord
      belongs_to :physician
      belongs_to :patient
    end
    
    class Patient < ApplicationRecord
      has_many :appointments
      has_many :physicians, through: :appointments
    end
    
    # good
    class Physician < ApplicationRecord
      has_many :appointments
      has_many :patients, through: :appointments
    end
    
    class Appointment < ApplicationRecord
      belongs_to :physician, inverse_of: :appointments
      belongs_to :patient, inverse_of: :appointments
    end
    
    class Patient < ApplicationRecord
      has_many :appointments
      has_many :physicians, through: :appointments
    end

    @see http://guides.rubyonrails.org/association_basics.html#bi-directional-associations @see http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses

    Please use Rails.root.join('path', 'to') instead.
    Open

      BUILDING_NUMBERS = YAML.load_file("#{Rails.root}/config/data/ncr/building_numbers.yml")
    Severity: Minor
    Found in app/models/ncr/work_order.rb by rubocop

    This cop is used to identify usages of file path joining process to use Rails.root.join clause.

    Example:

    # bad Rails.root.join('app/models/goober') File.join(Rails.root, 'app/models/goober') "#{Rails.root}/app/models/goober"

    # good Rails.root.join('app', 'models', 'goober')

    Models should subclass ApplicationRecord.
    Open

      class WorkOrder < ActiveRecord::Base
    Severity: Minor
    Found in app/models/ncr/work_order.rb by rubocop

    This cop checks that models subclass ApplicationRecord with Rails 5.0.

    Example:

    # good class Rails5Model < ApplicationRecord # ... end

    # bad class Rails4Model < ActiveRecord::Base # ... end

    %w-literals should be delimited by [ and ].
    Open

          %w(is_tock_billable date_requested not_to_exceed)
    Severity: Minor
    Found in app/models/ncr/work_order.rb by rubocop

    This cop enforces the consistent usage of %-literal delimiters.

    Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

    Example:

    # Style/PercentLiteralDelimiters:
    #   PreferredDelimiters:
    #     default: '[]'
    #     '%i':    '()'
    
    # good
    %w[alpha beta] + %i(gamma delta)
    
    # bad
    %W(alpha #{beta})
    
    # bad
    %I(alpha beta)

    Avoid comma after the last item of an array.
    Open

            Ncr::Mailboxes.ool_ba80_budget,
    Severity: Minor
    Found in app/models/ncr/work_order.rb by rubocop

    This cop checks for trailing comma in array and hash literals.

    Example: EnforcedStyleForMultiline: consistent_comma

    # bad
    a = [1, 2,]
    
    # good
    a = [
      1, 2,
      3,
    ]
    
    # good
    a = [
      1,
      2,
    ]

    Example: EnforcedStyleForMultiline: comma

    # bad
    a = [1, 2,]
    
    # good
    a = [
      1,
      2,
    ]

    Example: EnforcedStyleForMultiline: no_comma (default)

    # bad
    a = [1, 2,]
    
    # good
    a = [
      1,
      2
    ]

    %w-literals should be delimited by [ and ].
    Open

      EXPENSE_TYPES = %w(BA60 BA61 BA80)
    Severity: Minor
    Found in app/models/ncr/work_order.rb by rubocop

    This cop enforces the consistent usage of %-literal delimiters.

    Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

    Example:

    # Style/PercentLiteralDelimiters:
    #   PreferredDelimiters:
    #     default: '[]'
    #     '%i':    '()'
    
    # good
    %w[alpha beta] + %i(gamma delta)
    
    # bad
    %W(alpha #{beta})
    
    # bad
    %I(alpha beta)

    Unnecessary spacing detected.
    Open

          year % 100   # convert to two-digit
    Severity: Minor
    Found in app/models/ncr/work_order.rb by rubocop

    This cop checks for extra/unnecessary whitespace.

    Example:

    # good if AllowForAlignment is true
    name      = "RuboCop"
    # Some comment and an empty line
    
    website  += "/bbatsov/rubocop" unless cond
    puts        "rubocop"          if     debug
    
    # bad for any configuration
    set_app("RuboCop")
    website  = "https://github.com/bbatsov/rubocop"

    Freeze mutable objects assigned to constants.
    Open

      EXPENSE_TYPES = %w(BA60 BA61 BA80)
    Severity: Minor
    Found in app/models/ncr/work_order.rb by rubocop

    This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

    Example:

    # bad
    CONST = [1, 2, 3]
    
    # good
    CONST = [1, 2, 3].freeze

    There are no issues that match your filters.

    Category
    Status