You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: sale_affair_test.rb
    path of file: ./repos/ekylibre/test/models
    
    the code of the file until where you have to start completion: # = Informations
#
# == License
#
# Ekylibre - Simple agricultural ERP
# Copyright (C) 2008-2009 Brice Texier, Thibaud Merigon
# Copyright (C) 2010-2012 Brice Texier
# Copyright (C) 2012-2014 Brice Texier, David Joulin
# Copyright (C) 2015-2023 Ekylibre SAS
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of th
    
  def new_valid_sales_invoice
    client = create(:entity, :client)
    journal = Journal.find_by(nature: :sales)
    nature = SaleNature.find_or_initialize_by(
      journal: journal,
      currency: journal.currency,
      catalog: Catalog.by_default!(:sale)
    )
    nature.name ||= 'Sales baby!'
    nature.save!
    items = (0..4).to_a.map do |index|
      variant = ProductNatureVariant.where(category: ProductNatureCategory.where(saleable: true)).offset(index).first
      SaleItem.new(
        conditioning_quantity: 1 + rand(20),
        unit_pretax_amount: 10 + (100 * rand).round(2),
        variant: variant,
        tax: Tax.all.sample,
        conditioning_unit: variant.guess_conditioning[:unit]
      )
    end
    sale = Sale.create!(client: client, nature: nature, items: items, invoiced_at: DateTime.new(2018, 1, 1))
    sale.invoice!
    sale.reload
    assert sale.amount > 0, "Sale amount should be greater than 0. Got: #{sale.amount.inspect}"
    assert sale.journal_entry, 'A journal entry should exists after sale invoicing'
    assert_equal sale.affair.debit, sale.amount, 'Sale amount should match exactly affair debit'
    assert sale.affair.unbalanced?,
           "Affair should not be balanced:\n" +
           sale.affair.attributes.sort_by(&:first).map { |k, v| " - #{k}: #{v}" }.join("\n")
    assert sale.affair.letterable_journal_entry_items.any?,
           "Affair should have letterable journal entry items:\n" +
           sale.affair.deals.map { |d| " - #{d.class.name}: #{d.journal_entry.inspect}" }.join("\n")
    assert sale.affair.journal_entry_items_unbalanced?,
           "Journal entry items should be unbalanced:\n" +
           sale.affair.letterable_journal_entry_items.map { |i| " - #{i.account_number.ljust(14)} | #{i.debit.to_s.rjust(10)} | #{i.credit.to_s.rjust(10)}" }.join("\n")
    assert !sale.affair.multi_thirds?
    assert !sale.affair.journal_entry_items_already_lettered?

    # REVIEW: This should be confirmed by someone.
    # Test changed by @aquaj because it seems to be the desired behaviour
    # after @lcoq's modifications in code.
    # Can @burisu or @ionosphere confirm ?
    assert sale.affair.letterable?
    sale
  end