Interacting with Line Items in logic hooks

Hi again everyone,

I have been struggling with trying to get an after save logic hook to copy the line items from one invoice to another, we have a requirement to be able to duplicate an invoice with a number of changes if certain fields are set. I can successfully duplicate the invoice record however the line items are not coming across. I am using getBean to retrieve the first invoice and then set a new id before saving, not sure how I should go about setting the parent id for the line items in the duplicated record.

I am having a bit of trouble understanding how AOS_Line_Items_Groups.php save_group function works, should I pass the new invoice id to this function?

          $new_invoice = BeanFactory::getBean('AOS_Invoices', $bean->id);
          $nid = create_guid();
          $new_invoice->id = $nid;
          //Set fields in new invoice.

          //Set id for duplicated line items
          $productQuoteGroup = new AOS_Line_Item_Groups();
          $productQuoteGroup->save_groups($_POST, $nid, 'group_');


Any advice on how I could handle this would be great. Thanks as always.