code: def remove_invoices(portal):
      
      logger.info("Unlink Invoices")
  
      invoices = portal.get("invoices")
      if invoices is None:
          return
  
      for batch in invoices.objectValues():
          for invoice in batch.objectValues():
              invoice_id = invoice.getId()
              client = invoice.getClient()
              if not client:
                  # invoice w/o a client -> remove
                  batch.manage_delObjects(invoice_id)
                  continue
  
              if invoice_id in client.objectIds():
                  continue
  
              # move invoices inside the client
              cp = batch.manage_cutObjects(invoice_id)
              client.manage_pasteObjects(cp)
  
      # delete the invoices folder
      portal.manage_delObjects(invoices.getId())
docs: Moves all existing invoices inside the client and removes the invoices
      folder with the invoice batches