<commit_before>class CapitalPlanModule < ActiveRecord::Base

  #------------------------------------------------------------------------------
  # Behaviors
  #------------------------------------------------------------------------------
  # Include the object key mixin
  include TransamObjectKey

  belongs_to :capital_plan_module_type

  belongs_to :capital_plan

  has_many :capital_plan_actions, :dependent => :destroy

  default_scope { order(:sequence) }

  def completed?
    completed_at.present?
  end

  def is_allowed?
    (prev_module.nil? || prev_module.completed_at.present?) && !(capital_plan_actions.pluck(:completed_at).include? nil) && completed_at.nil?
  end

  def is_undo_allowed?
    (next_module.nil? || next_module.capital_plan_actions.pluck(:completed_at).uniq == [nil]) && (capital_plan_actions.pluck(:completed_at).include? nil) && completed_at.present?
  end

  def prev_module
    capital_plan.capital_plan_modules.where('sequence < ?', self.sequence).order(:sequence).last
  end

  def next_module
    capital_plan.capital_plan_modules.where('sequence > ?', self.sequence).order(:sequence).first
  end

end<commit_msg>[fixes#146523589] tighten check on module completion allowance<commit_after>class CapitalPlanModule < ActiveRecord::Base

  #------------------------------------------------------------------------------
  # Behaviors
  #------------------------------------------------------------------------------
  # Include the object key mixin
  include TransamObjectKey

  belongs_to :capital_plan_module_type

  belongs_to :capital_plan

  has_many :capital_plan_actions, :dependent => :destroy

  default_scope { order(:sequence) }

  def completed?
    completed_at.present?
  end

  def is_allowed?
    capital_plan.capital_plan_modules.where('completed_at IS NULL AND sequence < ?', sequence).count == 0 && !(capital_plan_actions.pluck(:completed_at).include? nil) && completed_at.nil?
  end

  def is_undo_allowed?
    (next_module.nil? || next_module.capital_plan_actions.pluck(:completed_at).uniq == [nil]) && (capital_plan_actions.pluck(:completed_at).include? nil) && completed_at.present?
  end

  def prev_module
    capital_plan.capital_plan_modules.where('sequence < ?', self.sequence).order(:sequence).last
  end

  def next_module
    capital_plan.capital_plan_modules.where('sequence > ?', self.sequence).order(:sequence).first
  end

end
{'fraction_non_alphanumeric': 0.22630480167014613, 'fraction_numerical': 0.0041753653444676405, 'mean_word_length': 2.6636085626911314, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4648032', 'n_tokens_mistral': 709, 'n_tokens_neox': 659, 'n_words': 116}