<commit_before>class Product < ActiveRecord::Base
  belongs_to :consultant
  belongs_to :request
  belongs_to :sale

  validates :name, :consultant, :request, presence: true

  enum status: [:stock, :sold, :sample, :to_be_defined]

  scope :in_stock,      -> { where(status: 0) }
  scope :sold,          -> { where(status: 1) }
  scope :sample,        -> { where(status: 2) }
  scope :to_be_defined, -> { where(status: 3) }

end<commit_msg>mark product as sold when sold<commit_after>class Product < ActiveRecord::Base
  belongs_to :consultant
  belongs_to :request
  belongs_to :sale

  validates :name, :consultant, :request, presence: true

  after_save :handle_selling, if: 'sale_id_changed?'

  enum status: [:stock, :sold, :sample, :to_be_defined]

  scope :in_stock,      -> { where(status: 0) }
  scope :sold,          -> { where(status: 1) }
  scope :sample,        -> { where(status: 2) }
  scope :to_be_defined, -> { where(status: 3) }

  private

  def handle_selling
    sold! if sale_id_was.nil? && !sold?
  end

end
{'fraction_non_alphanumeric': 0.13300970873786408, 'fraction_numerical': 0.007766990291262136, 'mean_word_length': 3.502183406113537, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '3585271', 'n_tokens_mistral': 379, 'n_tokens_neox': 359, 'n_words': 92}