Duplicate record with function

Duplicate record with function

Hi, is there a way to duplicate a record through a custom function ? (On my concern, I would like to duplicate an invoice convert from a Quote to split it in 2 different invoices). 

Thus, a way to convert a quote in 2 invoices would be ok two.

Thanks