Skip to content

Instantly share code, notes, and snippets.

@pythonandchips
Created February 17, 2021 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pythonandchips/eba1df62ad34633b6b18ebf1e8a288ef to your computer and use it in GitHub Desktop.
Save pythonandchips/eba1df62ad34633b6b18ebf1e8a288ef to your computer and use it in GitHub Desktop.
Fix sent invoices
def fix_sent_invoices(company_id, reference)
company = Company.find(company_id)
invoices = company.invoices.where(company_id: company_id, reference: reference)
return "Only #{invoices.length} found" if invoices.length < 2
puts "update #{invoices.length} invoices (#{invoices.map(&:id).join(",")}) for #{company.subdomain}?"
confirm = gets.chomp
return unless confirm == "y"
invoices[1..].each_with_index do |invoice, index|
new_reference = "#{invoice.reference.strip}-FA#{index+1}"
invoice.update_column(:reference, new_reference)
puts "updated invoice #{invoice.id} reference to #{new_reference}"
end
invoices.map{|i| i.reload; [i.id, i.reference]}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment