<commit_before>module Spree
  class TransferItem < Spree::Base
    acts_as_paranoid
    belongs_to :stock_transfer, inverse_of: :transfer_items
    belongs_to :variant

    validate :stock_availability, if: :check_stock?
    validates :stock_transfer, :variant, presence: true
    validates :variant_id, uniqueness: { scope: :stock_transfer_id }, allow_blank: true
    validates :expected_quantity, numericality: { greater_than: 0 }
    validates :received_quantity, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: :expected_quantity }

    scope :received, -> { where('received_quantity > 0') }
    scope :fully_received, -> { where('expected_quantity = received_quantity') }
    scope :partially_received, -> { received.where('expected_quantity > received_quantity') }

    before_destroy :ensure_stock_transfer_not_finalized
    before_validation :ensure_stock_transfer_not_closed
    before_update :prevent_expected_quantity_update_stock_transfer_finalized

    private

    def ensure_stock_transfer_not_closed<commit_msg>Allow TransferItem to retrieve a soft-deleted variant<commit_after>module Spree
  class TransferItem < Spree::Base
    acts_as_paranoid
    belongs_to :stock_transfer, inverse_of: :transfer_items
    belongs_to :variant, -> { with_deleted }

    validate :stock_availability, if: :check_stock?
    validates :stock_transfer, :variant, presence: true
    validates :variant_id, uniqueness: { scope: :stock_transfer_id }, allow_blank: true
    validates :expected_quantity, numericality: { greater_than: 0 }
    validates :received_quantity, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: :expected_quantity }

    scope :received, -> { where('received_quantity > 0') }
    scope :fully_received, -> { where('expected_quantity = received_quantity') }
    scope :partially_received, -> { received.where('expected_quantity > received_quantity') }

    before_destroy :ensure_stock_transfer_not_finalized
    before_validation :ensure_stock_transfer_not_closed
    before_update :prevent_expected_quantity_update_stock_transfer_finalized

    private

    def ensure_stock_transfer_not_closed
{'fraction_non_alphanumeric': 0.07888631090487239, 'fraction_numerical': 0.0027842227378190253, 'mean_word_length': 5.716510903426792, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, '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': '4996534', 'n_tokens_mistral': 661, 'n_tokens_neox': 618, 'n_words': 128}