How to programatically find fields the `party.replace` shall replace?

Following up How to use party.replace? I’m about writing a small tool to search for all references to be replaced by the party.replace wizard. My idea is to iterate over all models, then search all Many2One fields referencing to party.party.

Now there are two issues:

  1. When checking all Models, in the official modules this gave 68 references which are not replaced. E.g. ('party.party-party.category', 'party'). Not sure whether these are not replaced intentionally.

  2. When checking only sub-classes of ModelSQL, in the official modules 40 references which are replaced are not found. E.g. ('bank.account-party.party', 'owner'), which is very curious: bank.account-party.party is a subclass of ModelSQL, but isinstance(model, ModelSQL) is False and model.__class__ is ModelMeta.

    The reason for restriction to ModelSQL is to not report references in e.g. Wizard state.

So the question is: How to check whether a field needs to be replaced?