<commit_before># frozen_string_literal: true

Spree::Sample.load_sample("orders")

order          = Spree::Order.last
inventory_unit = order.inventory_units.first
stock_location = inventory_unit.find_stock_item.stock_location

return_item = Spree::ReturnItem.create(inventory_unit: inventory_unit)

return_item.exchange_variant = return_item.eligible_exchange_variants.last
return_item.build_exchange_inventory_unit
return_item.accept!

customer_return = Spree::CustomerReturn.create(
  stock_location: stock_location,
  return_items: [return_item]
)

order.reimbursements.create(
  customer_return: customer_return,
  return_items: [return_item]
)<commit_msg>Create a valid reimbursement in sample<commit_after># frozen_string_literal: true

Spree::Sample.load_sample("orders")

order = Spree::Order.last
inventory_unit = order.inventory_units.take!
stock_location = inventory_unit.find_stock_item.stock_location
return_reason = Spree::ReturnReason.active.take!
preferred_reimbursement_type = Spree::ReimbursementType.where(name: 'Original').take!

# Mark the order paid and shipped
order.payments.pending.each(&:complete)
order.shipments.each do |shipment|
  shipment.suppress_mailer = false
  shipment.ship!
end

# Create a return authorization
return_item = Spree::ReturnItem.new(
  inventory_unit: inventory_unit,
  preferred_reimbursement_type: preferred_reimbursement_type
)

order.return_authorizations.create!(
  reason: return_reason,
  return_items: [return_item],
  stock_location: stock_location
)

# Create a customer return and mark it as received
customer_return = Spree::CustomerReturn.create!(
  return_items: [return_item],
  stock_location: stock_location
)
return_item.reload
return_item.skip_customer_return_processing = true
return_item.receive!
customer_return.process_return!

# Accept the customer return and reimburse it
return_item.accept!
order.reimbursements.create(
  customer_return: customer_return,
  return_items: [return_item]
)
{'fraction_non_alphanumeric': 0.0845213849287169, 'fraction_numerical': 0.0, 'mean_word_length': 7.5064935064935066, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3728669', 'n_tokens_mistral': 629, 'n_tokens_neox': 610, 'n_words': 112}