I'm not sure of the exact source of your first error (though I suspect it's #1 below), but there are three things to get out of the way before digging too deeply:
1. You don't seem to be doing anything that actually requires sub-queries. Just use where_related, or_where_related, not_where_in, etc. for what you're doing.
you correctly used the id field from sme_profile, but in the first block, you're just using the objects themselves, which won't work. You did create an array of IDs for the $accepted_documents part of your code, so you seem to understand this in at least certain circumstances, but just realize that you can't just pass DMZ objects directly to the where functions.
3. Why query IDs and then pass them to another query when there are relationships to use directly? Why not just:
Code:
$documents = new Document();
$documents->group_start() // Groups because of the "OR"
->where_related('product', 'id', $products_purchased) // Fix this and don't pass the object -- also notice not a sub-query
->or_where_related('join_documents_locations_project', 'project_id', $join_projects_purchased) // Fix this and don't pass the object -- also notice not a sub-query
->group_end()
->where_not_related('sme_profile', 'id', $this->sme_profile->id) // This should do the same thing as your $accepted_documents -> array of IDS -> call to where_not_in
That should take care of your $accepted_documents code. Looks like you could also combine the $products_purchased as a deep relationship query. Possibly the $join_projects_purchased part as well, although that looks like it might be better separated.
Regardless, there's a lot of room for simplification in your code.